@@ -239,14 +239,14 @@ impl Renderer {
239
239
group. elements . iter ( ) . find_map ( |s| match & s {
240
240
Element :: Cause ( cause) => {
241
241
if cause. markers . iter ( ) . any ( |m| m. kind . is_primary ( ) ) {
242
- Some ( cause. origin )
242
+ Some ( cause. origin . as_ref ( ) )
243
243
} else {
244
244
None
245
245
}
246
246
}
247
247
Element :: Origin ( origin) => {
248
248
if origin. primary {
249
- Some ( Some ( origin. origin ) )
249
+ Some ( Some ( origin) )
250
250
} else {
251
251
None
252
252
}
@@ -260,30 +260,30 @@ impl Renderer {
260
260
. iter ( )
261
261
. find_map ( |group| {
262
262
group. elements . iter ( ) . find_map ( |s| match & s {
263
- Element :: Cause ( cause) => Some ( cause. origin ) ,
264
- Element :: Origin ( origin) => Some ( Some ( origin. origin ) ) ,
263
+ Element :: Cause ( cause) => Some ( cause. origin . as_ref ( ) ) ,
264
+ Element :: Origin ( origin) => Some ( Some ( origin) ) ,
265
265
_ => None ,
266
266
} )
267
267
} )
268
268
. unwrap_or_default ( ) ,
269
269
) ;
270
270
let group_len = message. groups . len ( ) ;
271
- for ( g, group) in message. groups . into_iter ( ) . enumerate ( ) {
271
+ for ( g, group) in message. groups . iter ( ) . enumerate ( ) {
272
272
let mut buffer = StyledBuffer :: new ( ) ;
273
273
let primary_origin = group
274
274
. elements
275
275
. iter ( )
276
276
. find_map ( |s| match & s {
277
277
Element :: Cause ( cause) => {
278
278
if cause. markers . iter ( ) . any ( |m| m. kind . is_primary ( ) ) {
279
- Some ( cause. origin )
279
+ Some ( cause. origin . as_ref ( ) )
280
280
} else {
281
281
None
282
282
}
283
283
}
284
284
Element :: Origin ( origin) => {
285
285
if origin. primary {
286
- Some ( Some ( origin. origin ) )
286
+ Some ( Some ( origin) )
287
287
} else {
288
288
None
289
289
}
@@ -295,8 +295,8 @@ impl Renderer {
295
295
. elements
296
296
. iter ( )
297
297
. find_map ( |s| match & s {
298
- Element :: Cause ( cause) => Some ( cause. origin ) ,
299
- Element :: Origin ( origin) => Some ( Some ( origin. origin ) ) ,
298
+ Element :: Cause ( cause) => Some ( cause. origin . as_ref ( ) ) ,
299
+ Element :: Origin ( origin) => Some ( Some ( origin) ) ,
300
300
_ => None ,
301
301
} )
302
302
. unwrap_or_default ( ) ,
@@ -490,26 +490,27 @@ impl Renderer {
490
490
labels = Some ( labels_inner) ;
491
491
}
492
492
493
- if let Some ( origin) = cause. origin {
494
- let mut origin = Origin :: new ( origin) ;
493
+ if let Some ( mut origin) = cause. origin . clone ( ) {
495
494
origin. primary = true ;
496
495
497
- let source_map = SourceMap :: new ( cause. source , cause. line_start ) ;
498
- let ( _depth, annotated_lines) =
499
- source_map. annotated_lines ( cause. markers . clone ( ) , cause. fold ) ;
496
+ if origin. line . is_none ( ) || origin. char_column . is_none ( ) {
497
+ let source_map = SourceMap :: new ( cause. source , cause. line_start ) ;
498
+ let ( _depth, annotated_lines) =
499
+ source_map. annotated_lines ( cause. markers . clone ( ) , cause. fold ) ;
500
500
501
- if let Some ( primary_line) = annotated_lines
502
- . iter ( )
503
- . find ( |l| l. annotations . iter ( ) . any ( LineAnnotation :: is_primary) )
504
- . or ( annotated_lines. iter ( ) . find ( |l| !l. annotations . is_empty ( ) ) )
505
- {
506
- origin. line = Some ( primary_line. line_index ) ;
507
- if let Some ( first_annotation) = primary_line
508
- . annotations
501
+ if let Some ( primary_line) = annotated_lines
509
502
. iter ( )
510
- . min_by_key ( |a| ( Reverse ( a. is_primary ( ) ) , a. start . char ) )
503
+ . find ( |l| l. annotations . iter ( ) . any ( LineAnnotation :: is_primary) )
504
+ . or ( annotated_lines. iter ( ) . find ( |l| !l. annotations . is_empty ( ) ) )
511
505
{
512
- origin. char_column = Some ( first_annotation. start . char + 1 ) ;
506
+ origin. line = Some ( primary_line. line_index ) ;
507
+ if let Some ( first_annotation) = primary_line
508
+ . annotations
509
+ . iter ( )
510
+ . min_by_key ( |a| ( Reverse ( a. is_primary ( ) ) , a. start . char ) )
511
+ {
512
+ origin. char_column = Some ( first_annotation. start . char + 1 ) ;
513
+ }
513
514
}
514
515
}
515
516
@@ -784,32 +785,40 @@ impl Renderer {
784
785
buffer : & mut StyledBuffer ,
785
786
max_line_num_len : usize ,
786
787
snippet : & Snippet < ' _ , Annotation < ' _ > > ,
787
- primary_origin : Option < & str > ,
788
+ primary_origin : Option < & Origin < ' _ > > ,
788
789
sm : & SourceMap < ' _ > ,
789
790
annotated_lines : & [ AnnotatedLineInfo < ' _ > ] ,
790
791
multiline_depth : usize ,
791
792
is_cont : bool ,
792
793
) {
793
- if let Some ( origin) = snippet. origin {
794
- let mut origin = Origin :: new ( origin) ;
794
+ if let Some ( mut origin) = snippet. origin . clone ( ) {
795
795
// print out the span location and spacer before we print the annotated source
796
796
// to do this, we need to know if this span will be primary
797
- let is_primary = primary_origin == Some ( origin . origin ) ;
797
+ let is_primary = origin . primary || primary_origin == Some ( & origin) ;
798
798
799
799
if is_primary {
800
800
origin. primary = true ;
801
- if let Some ( primary_line) = annotated_lines
802
- . iter ( )
803
- . find ( |l| l. annotations . iter ( ) . any ( LineAnnotation :: is_primary) )
804
- . or ( annotated_lines. iter ( ) . find ( |l| !l. annotations . is_empty ( ) ) )
805
- {
806
- origin. line = Some ( primary_line. line_index ) ;
807
- if let Some ( first_annotation) = primary_line
808
- . annotations
801
+
802
+ if origin. line . is_none ( ) || origin. char_column . is_none ( ) {
803
+ if let Some ( primary_line) = annotated_lines
809
804
. iter ( )
810
- . min_by_key ( |a| ( Reverse ( a. is_primary ( ) ) , a. start . char ) )
805
+ . find ( |l| l. annotations . iter ( ) . any ( LineAnnotation :: is_primary) )
806
+ . or ( annotated_lines. iter ( ) . find ( |l| !l. annotations . is_empty ( ) ) )
811
807
{
812
- origin. char_column = Some ( first_annotation. start . char + 1 ) ;
808
+ if origin. line . is_none ( ) {
809
+ origin. line = Some ( primary_line. line_index ) ;
810
+ }
811
+
812
+ // Always set the char column, as it is either `None`
813
+ // or we set the line and now need to set the column on
814
+ // that line.
815
+ if let Some ( first_annotation) = primary_line
816
+ . annotations
817
+ . iter ( )
818
+ . min_by_key ( |a| ( Reverse ( a. is_primary ( ) ) , a. start . char ) )
819
+ {
820
+ origin. char_column = Some ( first_annotation. start . char + 1 ) ;
821
+ }
813
822
}
814
823
}
815
824
} else {
@@ -829,10 +838,12 @@ impl Renderer {
829
838
buffer_msg_line_offset,
830
839
max_line_num_len + 1 ,
831
840
) ;
832
- if let Some ( first_line) = annotated_lines. first ( ) {
833
- origin. line = Some ( first_line. line_index ) ;
834
- if let Some ( first_annotation) = first_line. annotations . first ( ) {
835
- origin. char_column = Some ( first_annotation. start . char + 1 ) ;
841
+ if origin. line . is_none ( ) {
842
+ if let Some ( first_line) = annotated_lines. first ( ) {
843
+ origin. line = Some ( first_line. line_index ) ;
844
+ if let Some ( first_annotation) = first_line. annotations . first ( ) {
845
+ origin. char_column = Some ( first_annotation. start . char + 1 ) ;
846
+ }
836
847
}
837
848
}
838
849
}
@@ -1648,7 +1659,7 @@ impl Renderer {
1648
1659
suggestion : & Snippet < ' _ , Patch < ' _ > > ,
1649
1660
max_line_num_len : usize ,
1650
1661
sm : & SourceMap < ' _ > ,
1651
- primary_origin : Option < & str > ,
1662
+ primary_origin : Option < & Origin < ' _ > > ,
1652
1663
is_cont : bool ,
1653
1664
) {
1654
1665
let suggestions = sm. splice_lines ( suggestion. markers . clone ( ) ) ;
@@ -1671,14 +1682,22 @@ impl Renderer {
1671
1682
ElementStyle :: LineNumber ,
1672
1683
) ;
1673
1684
}
1674
- if suggestion. origin != primary_origin {
1675
- if let Some ( origin) = suggestion. origin {
1676
- let ( loc, _) = sm. span_to_locations ( parts[ 0 ] . span . clone ( ) ) ;
1685
+
1686
+ if suggestion. origin . as_ref ( ) != primary_origin && primary_origin. is_some ( ) {
1687
+ if let Some ( origin) = suggestion. origin . clone ( ) {
1688
+ let ( line, char_col) =
1689
+ if let ( Some ( line) , Some ( char_col) ) = ( origin. line , origin. char_column ) {
1690
+ ( line, char_col)
1691
+ } else {
1692
+ let ( loc, _) = sm. span_to_locations ( parts[ 0 ] . span . clone ( ) ) ;
1693
+ ( loc. line , loc. char + 1 )
1694
+ } ;
1695
+
1677
1696
// --> file.rs:line:col
1678
1697
// |
1679
1698
let arrow = self . file_start ( ) ;
1680
1699
buffer. puts ( row_num - 1 , 0 , arrow, ElementStyle :: LineNumber ) ;
1681
- let message = format ! ( "{}:{}:{}" , origin, loc . line, loc . char + 1 ) ;
1700
+ let message = format ! ( "{}:{}:{}" , origin. origin , line, char_col ) ;
1682
1701
if is_cont {
1683
1702
buffer. append ( row_num - 1 , & message, ElementStyle :: LineAndColumn ) ;
1684
1703
} else {
0 commit comments