@@ -64,11 +64,11 @@ impl Emitter for EmitterWriter {
64
64
}
65
65
}
66
66
67
- if !db. handler . flags . external_macro_backtrace {
68
- self . fix_multispans_in_std_macros ( & mut primary_span, & mut children) ;
69
- }
67
+ self . fix_multispans_in_std_macros ( & mut primary_span,
68
+ & mut children,
69
+ db. handler . flags . external_macro_backtrace ) ;
70
+
70
71
self . emit_messages_default ( & db. level ,
71
- db. handler . flags . external_macro_backtrace ,
72
72
& db. styled_message ( ) ,
73
73
& db. code ,
74
74
& primary_span,
@@ -726,7 +726,9 @@ impl EmitterWriter {
726
726
// This "fixes" MultiSpans that contain Spans that are pointing to locations inside of
727
727
// <*macros>. Since these locations are often difficult to read, we move these Spans from
728
728
// <*macros> to their corresponding use site.
729
- fn fix_multispan_in_std_macros ( & mut self , span : & mut MultiSpan ) -> bool {
729
+ fn fix_multispan_in_std_macros ( & mut self ,
730
+ span : & mut MultiSpan ,
731
+ always_backtrace : bool ) -> bool {
730
732
let mut spans_updated = false ;
731
733
732
734
if let Some ( ref cm) = self . cm {
@@ -739,22 +741,45 @@ impl EmitterWriter {
739
741
continue ;
740
742
}
741
743
let call_sp = cm. call_span_if_macro ( * sp) ;
742
- if call_sp != * sp {
743
- before_after. push ( ( sp . clone ( ) , call_sp) ) ;
744
+ if call_sp != * sp && !always_backtrace {
745
+ before_after. push ( ( * sp , call_sp) ) ;
744
746
}
745
- for trace in sp. macro_backtrace ( ) . iter ( ) . rev ( ) {
747
+ let backtrace_len = sp. macro_backtrace ( ) . len ( ) ;
748
+ for ( i, trace) in sp. macro_backtrace ( ) . iter ( ) . rev ( ) . enumerate ( ) {
746
749
// Only show macro locations that are local
747
750
// and display them like a span_note
748
751
if let Some ( def_site) = trace. def_site_span {
749
752
if def_site == DUMMY_SP {
750
753
continue ;
751
754
}
755
+ if always_backtrace {
756
+ new_labels. push ( ( def_site,
757
+ format ! ( "in this expansion of `{}`{}" ,
758
+ trace. macro_decl_name,
759
+ if backtrace_len > 2 {
760
+ // if backtrace_len == 1 it'll be pointed
761
+ // at by "in this macro invocation"
762
+ format!( " (#{})" , i + 1 )
763
+ } else {
764
+ "" . to_string( )
765
+ } ) ) ) ;
766
+ }
752
767
// Check to make sure we're not in any <*macros>
753
768
if !cm. span_to_filename ( def_site) . contains ( "macros>" ) &&
754
- !trace. macro_decl_name . starts_with ( "#[" ) {
769
+ !trace. macro_decl_name . starts_with ( "#[" ) ||
770
+ always_backtrace {
755
771
new_labels. push ( ( trace. call_site ,
756
- "in this macro invocation" . to_string ( ) ) ) ;
757
- break ;
772
+ format ! ( "in this macro invocation{}" ,
773
+ if backtrace_len > 2 && always_backtrace {
774
+ // only specify order when the macro
775
+ // backtrace is multiple levels deep
776
+ format!( " (#{})" , i + 1 )
777
+ } else {
778
+ "" . to_string( )
779
+ } ) ) ) ;
780
+ if !always_backtrace {
781
+ break ;
782
+ }
758
783
}
759
784
}
760
785
}
@@ -766,7 +791,9 @@ impl EmitterWriter {
766
791
if sp_label. span == DUMMY_SP {
767
792
continue ;
768
793
}
769
- if cm. span_to_filename ( sp_label. span . clone ( ) ) . contains ( "macros>" ) {
794
+ if cm. span_to_filename ( sp_label. span . clone ( ) ) . contains ( "macros>" ) &&
795
+ !always_backtrace
796
+ {
770
797
let v = sp_label. span . macro_backtrace ( ) ;
771
798
if let Some ( use_site) = v. last ( ) {
772
799
before_after. push ( ( sp_label. span . clone ( ) , use_site. call_site . clone ( ) ) ) ;
@@ -788,18 +815,19 @@ impl EmitterWriter {
788
815
// will change the span to point at the use site.
789
816
fn fix_multispans_in_std_macros ( & mut self ,
790
817
span : & mut MultiSpan ,
791
- children : & mut Vec < SubDiagnostic > ) {
792
- let mut spans_updated = self . fix_multispan_in_std_macros ( span) ;
818
+ children : & mut Vec < SubDiagnostic > ,
819
+ backtrace : bool ) {
820
+ let mut spans_updated = self . fix_multispan_in_std_macros ( span, backtrace) ;
793
821
for child in children. iter_mut ( ) {
794
- spans_updated |= self . fix_multispan_in_std_macros ( & mut child. span ) ;
822
+ spans_updated |= self . fix_multispan_in_std_macros ( & mut child. span , backtrace ) ;
795
823
}
796
824
if spans_updated {
797
825
children. push ( SubDiagnostic {
798
826
level : Level :: Note ,
799
827
message : vec ! [
800
- ( [ "this error originates in a macro outside of the current crate" ,
801
- " (in Nightly builds, run with -Z external-macro-backtrace for more info)" ]
802
- . join ( " " ) ,
828
+ ( "this error originates in a macro outside of the current crate \
829
+ (in Nightly builds, run with -Z external-macro-backtrace \
830
+ for more info)" . to_string ( ) ,
803
831
Style :: NoStyle ) ,
804
832
] ,
805
833
span : MultiSpan :: new ( ) ,
@@ -861,7 +889,7 @@ impl EmitterWriter {
861
889
// ("see?", Style::Highlight),
862
890
// ];
863
891
//
864
- // the expected output on a note is (* surround the highlighted text)
892
+ // the expected output on a note is (* surround the highlighted text)
865
893
//
866
894
// = note: highlighted multiline
867
895
// string to
@@ -889,7 +917,6 @@ impl EmitterWriter {
889
917
msg : & Vec < ( String , Style ) > ,
890
918
code : & Option < DiagnosticId > ,
891
919
level : & Level ,
892
- external_macro_backtrace : bool ,
893
920
max_line_num_len : usize ,
894
921
is_secondary : bool )
895
922
-> io:: Result < ( ) > {
@@ -1087,18 +1114,13 @@ impl EmitterWriter {
1087
1114
}
1088
1115
}
1089
1116
1090
- if external_macro_backtrace {
1091
- if let Some ( ref primary_span) = msp. primary_span ( ) . as_ref ( ) {
1092
- self . render_macro_backtrace_old_school ( primary_span, & mut buffer) ?;
1093
- }
1094
- }
1095
-
1096
1117
// final step: take our styled buffer, render it, then output it
1097
1118
emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ) ?;
1098
1119
1099
1120
Ok ( ( ) )
1100
1121
1101
1122
}
1123
+
1102
1124
fn emit_suggestion_default ( & mut self ,
1103
1125
suggestion : & CodeSuggestion ,
1104
1126
level : & Level ,
@@ -1182,9 +1204,9 @@ impl EmitterWriter {
1182
1204
}
1183
1205
Ok ( ( ) )
1184
1206
}
1207
+
1185
1208
fn emit_messages_default ( & mut self ,
1186
1209
level : & Level ,
1187
- external_macro_backtrace : bool ,
1188
1210
message : & Vec < ( String , Style ) > ,
1189
1211
code : & Option < DiagnosticId > ,
1190
1212
span : & MultiSpan ,
@@ -1197,7 +1219,6 @@ impl EmitterWriter {
1197
1219
message,
1198
1220
code,
1199
1221
level,
1200
- external_macro_backtrace,
1201
1222
max_line_num_len,
1202
1223
false ) {
1203
1224
Ok ( ( ) ) => {
@@ -1219,7 +1240,6 @@ impl EmitterWriter {
1219
1240
& child. styled_message ( ) ,
1220
1241
& None ,
1221
1242
& child. level ,
1222
- external_macro_backtrace,
1223
1243
max_line_num_len,
1224
1244
true ) {
1225
1245
Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
@@ -1248,30 +1268,6 @@ impl EmitterWriter {
1248
1268
}
1249
1269
}
1250
1270
}
1251
-
1252
- fn render_macro_backtrace_old_school ( & self ,
1253
- sp : & Span ,
1254
- buffer : & mut StyledBuffer ) -> io:: Result < ( ) > {
1255
- if let Some ( ref cm) = self . cm {
1256
- for trace in sp. macro_backtrace ( ) . iter ( ) . rev ( ) {
1257
- let line_offset = buffer. num_lines ( ) ;
1258
-
1259
- let mut diag_string =
1260
- format ! ( "in this expansion of {}" , trace. macro_decl_name) ;
1261
- if let Some ( def_site_span) = trace. def_site_span {
1262
- diag_string. push_str (
1263
- & format ! ( " (defined in {})" ,
1264
- cm. span_to_filename( def_site_span) ) ) ;
1265
- }
1266
- let snippet = cm. span_to_string ( trace. call_site ) ;
1267
- buffer. append ( line_offset, & format ! ( "{} " , snippet) , Style :: NoStyle ) ;
1268
- buffer. append ( line_offset, "note" , Style :: Level ( Level :: Note ) ) ;
1269
- buffer. append ( line_offset, ": " , Style :: NoStyle ) ;
1270
- buffer. append ( line_offset, & diag_string, Style :: OldSchoolNoteText ) ;
1271
- }
1272
- }
1273
- Ok ( ( ) )
1274
- }
1275
1271
}
1276
1272
1277
1273
fn draw_col_separator ( buffer : & mut StyledBuffer , line : usize , col : usize ) {
0 commit comments