@@ -35,21 +35,25 @@ pub enum RenderSpan {
35
35
/// the source code covered by the span.
36
36
FullSpan ( Span ) ,
37
37
38
+ /// Similar to a FullSpan, but the cited position is the end of
39
+ /// the span, instead of the start. Used, at least, for telling
40
+ /// compiletest/runtest to look at the last line of the span
41
+ /// (since `end_highlight_lines` displays an arrow to the end
42
+ /// of the span).
43
+ EndSpan ( Span ) ,
44
+
38
45
/// A FileLine renders with just a line for the message prefixed
39
46
/// by file:linenum.
40
47
FileLine ( Span ) ,
41
48
}
42
49
43
50
impl RenderSpan {
44
- fn span ( self ) -> Span {
45
- match self {
46
- FullSpan ( s) | FileLine ( s) => s
47
- }
48
- }
49
- fn is_full_span ( & self ) -> bool {
50
- match self {
51
- & FullSpan ( ..) => true ,
52
- & FileLine ( ..) => false ,
51
+ fn span ( & self ) -> Span {
52
+ match * self {
53
+ FullSpan ( s) |
54
+ EndSpan ( s) |
55
+ FileLine ( s) =>
56
+ s
53
57
}
54
58
}
55
59
}
@@ -115,7 +119,7 @@ impl SpanHandler {
115
119
self . handler . emit ( Some ( ( & self . cm , sp) ) , msg, Note ) ;
116
120
}
117
121
pub fn span_end_note ( & self , sp : Span , msg : & str ) {
118
- self . handler . custom_emit ( & self . cm , FullSpan ( sp) , msg, Note ) ;
122
+ self . handler . custom_emit ( & self . cm , EndSpan ( sp) , msg, Note ) ;
119
123
}
120
124
pub fn span_help ( & self , sp : Span , msg : & str ) {
121
125
self . handler . emit ( Some ( ( & self . cm , sp) ) , msg, Help ) ;
@@ -407,8 +411,8 @@ impl Emitter for EmitterWriter {
407
411
let error = match cmsp {
408
412
Some ( ( cm, COMMAND_LINE_SP ) ) => emit ( self , cm,
409
413
FileLine ( COMMAND_LINE_SP ) ,
410
- msg, code, lvl, false ) ,
411
- Some ( ( cm, sp) ) => emit ( self , cm, FullSpan ( sp) , msg, code, lvl, false ) ,
414
+ msg, code, lvl) ,
415
+ Some ( ( cm, sp) ) => emit ( self , cm, FullSpan ( sp) , msg, code, lvl) ,
412
416
None => print_diagnostic ( self , "" , lvl, msg, code) ,
413
417
} ;
414
418
@@ -420,43 +424,46 @@ impl Emitter for EmitterWriter {
420
424
421
425
fn custom_emit ( & mut self , cm : & codemap:: CodeMap ,
422
426
sp : RenderSpan , msg : & str , lvl : Level ) {
423
- match emit ( self , cm, sp, msg, None , lvl, true ) {
427
+ match emit ( self , cm, sp, msg, None , lvl) {
424
428
Ok ( ( ) ) => { }
425
429
Err ( e) => panic ! ( "failed to print diagnostics: {:?}" , e) ,
426
430
}
427
431
}
428
432
}
429
433
430
434
fn emit ( dst : & mut EmitterWriter , cm : & codemap:: CodeMap , rsp : RenderSpan ,
431
- msg : & str , code : Option < & str > , lvl : Level , custom : bool ) -> io:: Result < ( ) > {
435
+ msg : & str , code : Option < & str > , lvl : Level ) -> io:: Result < ( ) > {
432
436
let sp = rsp. span ( ) ;
433
437
434
438
// We cannot check equality directly with COMMAND_LINE_SP
435
439
// since PartialEq is manually implemented to ignore the ExpnId
436
440
let ss = if sp. expn_id == COMMAND_LINE_EXPN {
437
441
"<command line option>" . to_string ( )
442
+ } else if let EndSpan ( _) = rsp {
443
+ let span_end = Span { lo : sp. hi , hi : sp. hi , expn_id : sp. expn_id } ;
444
+ cm. span_to_string ( span_end)
438
445
} else {
439
446
cm. span_to_string ( sp)
440
447
} ;
441
- if custom {
442
- // we want to tell compiletest/runtest to look at the last line of the
443
- // span (since `custom_highlight_lines` displays an arrow to the end of
444
- // the span)
445
- let span_end = Span { lo : sp. hi , hi : sp. hi , expn_id : sp. expn_id } ;
446
- let ses = cm. span_to_string ( span_end) ;
447
- try!( print_diagnostic ( dst, & ses[ ..] , lvl, msg, code) ) ;
448
- if rsp. is_full_span ( ) {
449
- try!( custom_highlight_lines ( dst, cm, sp, lvl, cm. span_to_lines ( sp) ) ) ;
450
- }
451
- } else {
452
- try!( print_diagnostic ( dst, & ss[ ..] , lvl, msg, code) ) ;
453
- if rsp. is_full_span ( ) {
448
+
449
+ try!( print_diagnostic ( dst, & ss[ ..] , lvl, msg, code) ) ;
450
+
451
+ match rsp {
452
+ FullSpan ( _) => {
454
453
try!( highlight_lines ( dst, cm, sp, lvl, cm. span_to_lines ( sp) ) ) ;
455
454
}
455
+ EndSpan ( _) => {
456
+ try!( end_highlight_lines ( dst, cm, sp, lvl, cm. span_to_lines ( sp) ) ) ;
457
+ }
458
+ FileLine ( ..) => {
459
+ // no source text in this case!
460
+ }
456
461
}
462
+
457
463
if sp != COMMAND_LINE_SP {
458
464
try!( print_macro_backtrace ( dst, cm, sp) ) ;
459
465
}
466
+
460
467
match code {
461
468
Some ( code) =>
462
469
match dst. registry . as_ref ( ) . and_then ( |registry| registry. find_description ( code) ) {
@@ -575,12 +582,12 @@ fn highlight_lines(err: &mut EmitterWriter,
575
582
}
576
583
577
584
/// Here are the differences between this and the normal `highlight_lines`:
578
- /// `custom_highlight_lines ` will always put arrow on the last byte of the
585
+ /// `end_highlight_lines ` will always put arrow on the last byte of the
579
586
/// span (instead of the first byte). Also, when the span is too long (more
580
- /// than 6 lines), `custom_highlight_lines ` will print the first line, then
587
+ /// than 6 lines), `end_highlight_lines ` will print the first line, then
581
588
/// dot dot dot, then last line, whereas `highlight_lines` prints the first
582
589
/// six lines.
583
- fn custom_highlight_lines ( w : & mut EmitterWriter ,
590
+ fn end_highlight_lines ( w : & mut EmitterWriter ,
584
591
cm : & codemap:: CodeMap ,
585
592
sp : Span ,
586
593
lvl : Level ,
0 commit comments