@@ -229,14 +229,14 @@ impl Renderer {
229
229
. find_map ( |s| match & s {
230
230
Element :: Cause ( cause) => {
231
231
if cause. markers . iter ( ) . any ( |m| m. kind . is_primary ( ) ) {
232
- Some ( cause. path )
232
+ Some ( cause. path . as_ref ( ) )
233
233
} else {
234
234
None
235
235
}
236
236
}
237
237
Element :: Origin ( origin) => {
238
238
if origin. primary {
239
- Some ( Some ( origin. path ) )
239
+ Some ( Some ( & origin. path ) )
240
240
} else {
241
241
None
242
242
}
@@ -248,8 +248,8 @@ impl Renderer {
248
248
. elements
249
249
. iter ( )
250
250
. find_map ( |s| match & s {
251
- Element :: Cause ( cause) => Some ( cause. path ) ,
252
- Element :: Origin ( origin) => Some ( Some ( origin. path ) ) ,
251
+ Element :: Cause ( cause) => Some ( cause. path . as_ref ( ) ) ,
252
+ Element :: Origin ( origin) => Some ( Some ( & origin. path ) ) ,
253
253
_ => None ,
254
254
} )
255
255
<
10000
code class="diff-text syntax-highlighted-line"> . unwrap_or_default ( ) ,
@@ -269,7 +269,7 @@ impl Renderer {
269
269
let mut max_depth = 0 ;
270
270
for e in & group. elements {
271
271
if let Element :: Cause ( cause) = e {
272
- let source_map = SourceMap :: new ( cause. source , cause. line_start ) ;
272
+ let source_map = SourceMap :: new ( & cause. source , cause. line_start ) ;
273
273
let ( depth, annotated_lines) =
274
274
source_map. annotated_lines ( cause. markers . clone ( ) , cause. fold ) ;
275
275
max_depth = max ( max_depth, depth) ;
@@ -340,7 +340,7 @@ impl Renderer {
340
340
}
341
341
Element :: Suggestion ( suggestion) => {
342
342
let source_map =
343
- SourceMap :: new ( suggestion. source , suggestion. line_start ) ;
343
+ SourceMap :: new ( & suggestion. source , suggestion. line_start ) ;
344
344
self . emit_suggestion_default (
345
345
& mut buffer,
346
346
suggestion,
@@ -426,10 +426,10 @@ impl Renderer {
426
426
let labels_inner = cause
427
427
. markers
428
428
. iter ( )
429
- . filter_map ( |ann| match ann. label {
429
+ . filter_map ( |ann| match & ann. label {
430
430
Some ( msg) if ann. kind . is_primary ( ) => {
431
431
if !msg. trim ( ) . is_empty ( ) {
432
- Some ( msg. to_owned ( ) )
432
+ Some ( msg. to_string ( ) )
433
433
} else {
434
434
None
435
435
}
@@ -442,11 +442,11 @@ impl Renderer {
442
442
labels = Some ( labels_inner) ;
443
443
}
444
444
445
- if let Some ( path) = cause. path {
446
- let mut origin = Origin :: new ( path) ;
445
+ if let Some ( path) = & cause. path {
446
+ let mut origin = Origin :: new ( path. as_ref ( ) ) ;
447
447
origin. primary = true ;
448
448
449
- let sou
F987
rce_map = SourceMap :: new ( cause. source , cause. line_start ) ;
449
+ let source_map = SourceMap :: new ( & cause. source , cause. line_start ) ;
450
450
let ( _depth, annotated_lines) =
451
451
source_map. annotated_lines ( cause. markers . clone ( ) , cause. fold ) ;
452
452
@@ -531,7 +531,7 @@ impl Renderer {
531
531
if title. level . name != Some ( None ) {
532
532
buffer. append ( buffer_msg_line_offset, title. level . as_str ( ) , label_style) ;
533
533
label_width += title. level . as_str ( ) . len ( ) ;
534
- if let Some ( Id { id : Some ( id) , url } ) = title. id {
534
+ if let Some ( Id { id : Some ( id) , url } ) = & title. id {
535
535
buffer. append ( buffer_msg_line_offset, "[" , label_style) ;
536
536
if let Some ( url) = url. as_ref ( ) {
537
537
buffer. append (
@@ -575,9 +575,9 @@ impl Renderer {
575
575
} ) ;
576
576
577
577
let ( title_str, style) = if title. is_pre_styled {
578
- ( title. title . to_owned ( ) , ElementStyle :: NoStyle )
578
+ ( title. title . to_string ( ) , ElementStyle :: NoStyle )
579
579
} else {
580
- ( normalize_whitespace ( title. title ) , title_element_style)
580
+ ( normalize_whitespace ( & title. title ) , title_element_style)
581
581
} ;
582
582
for ( i, text) in title_str. lines ( ) . enumerate ( ) {
583
583
if i != 0 {
@@ -654,7 +654,7 @@ impl Renderer {
654
654
format ! ( "{}:{}:{}" , origin. path, line, col)
655
655
}
656
656
( Some ( line) , None ) => format ! ( "{}:{}" , origin. path, line) ,
657
- _ => origin. path . to_owned ( ) ,
657
+ _ => origin. path . to_string ( ) ,
658
658
} ;
659
659
660
660
buffer. append ( buffer_msg_line_offset, & str, ElementStyle :: LineAndColumn ) ;
@@ -671,17 +671,17 @@ impl Renderer {
671
671
buffer : & mut StyledBuffer ,
672
672
max_line_num_len : usize ,
673
673
snippet : & Snippet < ' _ , Annotation < ' _ > > ,
674
- primary_path : Option< & str > ,
674
+ primary_path : Option < & Cow < ' _ , str > > ,
675
675
sm : & SourceMap < ' _ > ,
676
676
annotated_lines : & [ AnnotatedLineInfo < ' _ > ] ,
677
677
multiline_depth : usize ,
678
678
is_cont : bool ,
679
679
) {
680
- if let Some ( path) = snippet. path {
681
- let mut origin = Origin :: new ( path) ;
680
+ if let Some ( path) = & snippet. path {
681
+ let mut origin = Origin :: new ( path. as_ref ( ) ) ;
682
682
// print out the span location and spacer before we print the annotated source
683
683
// to do this, we need to know if this span will be primary
684
- let is_primary = primary_path == Some ( origin. path ) ;
684
+ let is_primary = primary_path == Some ( & origin. path ) ;
685
685
686
686
if is_primary {
687
687
origin. primary = true ;
@@ -1394,7 +1394,7 @@ impl Renderer {
1394
1394
} else {
1395
1395
( pos + 2 , annotation. start . display . saturating_sub ( left) )
1396
1396
} ;
1397
- if let Some ( label) = annotation. label {
1397
+ if let Some ( label) = & annotation. label {
1398
1398
buffer. puts ( line_offset + pos, code_offset + col, label, style) ;
1399
1399
}
1400
1400
}
@@ -1535,7 +1535,7 @@ impl Renderer {
1535
1535
suggestion : & Snippet < ' _ , Patch < ' _ > > ,
1536
1536
max_line_num_len : usize ,
1537
1537
sm : & SourceMap < ' _ > ,
1538
- primary_path : Option < & str > ,
1538
+ primary_path : Option < & Cow < ' _ , str > > ,
1539
1539
is_cont : bool ,
1540
1540
) {
1541
1541
let suggestions = sm. splice_lines ( suggestion. markers . clone ( ) ) ;
@@ -1558,8 +1558,8 @@ impl Renderer {
1558
1558
ElementStyle :: LineNumber ,
1559
1559
) ;
1560
1560
}
1561
- if suggestion. path != primary_path {
1562
- if let Some ( path) = suggestion. path {
1561
+ if suggestion. path . as_ref ( ) != primary_path {
1562
+ if let Some ( path) = suggestion. path . as_ref ( ) {
1563
1563
let ( loc, _) = sm. span_to_locations ( parts[ 0 ] . span . clone ( ) ) ;
1564
1564
// --> file.rs:line:col
1565
1565
// |
@@ -1781,7 +1781,7 @@ impl Renderer {
1781
1781
// ...or trailing spaces. Account for substitutions containing unicode
1782
1782
// characters.
1783
1783
let sub_len: usize = str_width ( if is_whitespace_addition {
1784
- part. replacement
1784
+ & part. replacement
1785
1785
} else {
1786
1786
part. replacement . trim ( )
1787
1787
} ) ;
@@ -1802,7 +1802,7 @@ impl Renderer {
1802
1802
let padding: usize = max_line_num_len + 3 ;
1803
1803
for p in underline_start..underline_end {
1804
1804
if matches ! ( show_code_change, DisplaySuggestion :: Underline )
1805
- && is_different ( sm, part. replacement , part. span . clone ( ) )
1805
+ && is_different ( sm, & part. replacement , part. span . clone ( ) )
1806
1806
{
1807
1807
// If this is a replacement, underline with `~`, if this is an addition
1808
1808
// underline with `+`.
@@ -1903,7 +1903,7 @@ impl Renderer {
1903
1903
}
1904
1904
1905
1905
// length of the code after substitution
1906
- let full_sub_len = str_width ( part. replacement ) as isize ;
1906
+ let full_sub_len = str_width ( & part. replacement ) as isize ;
1907
1907
1908
1908
// length of the code to be substituted
1909
1909
let snippet_len = span_end_pos as isize - span_start_pos as isize ;
@@ -2631,7 +2631,7 @@ pub(crate) struct LineAnnotation<'a> {
2631
2631
pub kind : AnnotationKind ,
2632
2632
2633
2633
/// Optional label to display adjacent to the annotation.
2634
- pub label : Option < & ' a str > ,
2634
+ pub label : Option < Cow < ' a , str > > ,
2635
2635
2636
2636
/// Is this a single line, multiline or multiline span minimized down to a
2637
2637
/// smaller span.
@@ -2658,7 +2658,7 @@ impl LineAnnotation<'_> {
2658
2658
}
2659
2659
2660
2660
pub ( crate ) fn has_label ( & self ) -> bool {
2661
- if let Some ( label) = self . label {
2661
+ if let Some ( label) = & self . label {
2662
2662
// Consider labels with no text as effectively not being there
2663
2663
// to avoid weird output with unnecessary vertical lines, like:
2664
2664
//
0 commit comments