@@ -24,7 +24,7 @@ use rustc_lint_defs::pluralize;
24
24
25
25
use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
26
26
use rustc_data_structures:: sync:: Lrc ;
27
- use rustc_error_messages:: FluentArgs ;
27
+ use rustc_error_messages:: { FluentArgs , SpanLabel } ;
28
28
use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
29
29
use std:: borrow:: Cow ;
30
30
use std:: cmp:: { max, min, Reverse } ;
@@ -2202,46 +2202,28 @@ impl FileWithAnnotatedLines {
2202
2202
let mut multiline_annotations = vec ! [ ] ;
2203
2203
2204
2204
if let Some ( ref sm) = emitter. source_map ( ) {
2205
- for span_label in msp. span_labels ( ) {
2206
- let fixup_lo_hi = |span : Span | {
2207
- let lo = sm. lookup_char_pos ( span. lo ( ) ) ;
2208
- let mut hi = sm. lookup_char_pos ( span. hi ( ) ) ;
2209
-
2210
- // Watch out for "empty spans". If we get a span like 6..6, we
2211
- // want to just display a `^` at 6, so convert that to
2212
- // 6..7. This is degenerate input, but it's best to degrade
2213
- // gracefully -- and the parser likes to supply a span like
2214
- // that for EOF, in particular.
2215
-
2216
- if lo. col_display == hi. col_display && lo. line == hi. line {
2217
- hi. col_display += 1 ;
2218
- }
2219
- ( lo, hi)
2205
+ for SpanLabel { span, is_primary, label } in msp. span_labels ( ) {
2206
+ // If we don't have a useful span, pick the primary span if that exists.
2207
+ // Worst case we'll just print an error at the top of the main file.
2208
+ let span = match ( span. is_dummy ( ) , msp. primary_span ( ) ) {
2209
+ ( _, None ) | ( false , _) => span,
2210
+ ( true , Some ( span) ) => span,
2220
2211
} ;
2221
2212
2222
- if span_label. span . is_dummy ( ) {
2223
- if let Some ( span) = msp. primary_span ( ) {
2224
- // if we don't know where to render the annotation, emit it as a note
2225
- // on the primary span.
2226
-
2227
- let ( lo, hi) = fixup_lo_hi ( span) ;
2228
-
2229
- let ann = Annotation {
2230
- start_col : lo. col_display ,
2231
- end_col : hi. col_display ,
2232
- is_primary : span_label. is_primary ,
2233
- label : span_label
2234
- . label
2235
- . as_ref ( )
2236
- . map ( |m| emitter. translate_message ( m, args) . to_string ( ) ) ,
2237
- annotation_type : AnnotationType :: Singleline ,
2238
- } ;
2239
- add_annotation_to_file ( & mut output, lo. file , lo. line , ann) ;
2240
- }
2241
- continue ;
2213
+ let lo = sm. lookup_char_pos ( span. lo ( ) ) ;
2214
+ let mut hi = sm. lookup_char_pos ( span. hi ( ) ) ;
2215
+
2216
+ // Watch out for "empty spans". If we get a span like 6..6, we
2217
+ // want to just display a `^` at 6, so convert that to
2218
+ // 6..7. This is degenerate input, but it's best to degrade
2219
+ // gracefully -- and the parser likes to supply a span like
2220
+ // that for EOF, in particular.
2221
+
2222
+ if lo. col_display == hi. col_display && lo. line == hi. line {
2223
+ hi. col_display += 1 ;
2242
2224
}
2243
2225
2244
- let ( lo , hi ) = fixup_lo_hi ( span_label . span ) ;
2226
+ let label = label . as_ref ( ) . map ( |m| emitter . translate_message ( m , args ) . to_string ( ) ) ;
2245
2227
2246
2228
if lo. line != hi. line {
2247
2229
let ml = MultilineAnnotation {
@@ -2250,23 +2232,17 @@ impl FileWithAnnotatedLines {
2250
2232
line_end : hi. line ,
2251
2233
start_col : lo. col_display ,
2252
2234
end_col : hi. col_display ,
2253
- is_primary : span_label. is_primary ,
2254
- label : span_label
2255
- . label
2256
- . as_ref ( )
2257
- . map ( |m| emitter. translate_message ( m, args) . to_string ( ) ) ,
2235
+ is_primary,
2236
+ label,
2258
2237
overlaps_exactly : false ,
2259
2238
} ;
2260
2239
multiline_annotations. push ( ( lo. file , ml) ) ;
2261
2240
} else {
2262
2241
let ann = Annotation {
2263
2242
start_col : lo. col_display ,
2264
2243
end_col : hi. col_display ,
2265
- is_primary : span_label. is_primary ,
2266
- label : span_label
2267
- . label
2268
- . as_ref ( )
2269
- . map ( |m| emitter. translate_message ( m, args) . to_string ( ) ) ,
2244
+ is_primary,
2245
+ label,
2270
2246
annotation_type : AnnotationType :: Singleline ,
2271
2247
} ;
2272
2248
add_annotation_to_file ( & mut output, lo. file , lo. line , ann) ;
0 commit comments