@@ -51,8 +51,8 @@ impl ColorConfig {
51
51
fn use_color ( & self ) -> bool {
52
52
match * self {
53
53
ColorConfig :: Always => true ,
54
- ColorConfig :: Never => false ,
55
- ColorConfig :: Auto => stderr_isatty ( ) ,
54
+ ColorConfig :: Never => false ,
55
+ ColorConfig :: Auto => stderr_isatty ( ) ,
56
56
}
57
57
}
58
58
}
@@ -83,22 +83,22 @@ macro_rules! println_maybe_styled {
83
83
}
84
84
85
85
impl EmitterWriter {
86
- pub fn stderr ( color_config : ColorConfig ,
87
- code_map : Option < Rc < CodeMapper > > )
88
- -> EmitterWriter {
86
+ pub fn stderr ( color_config : ColorConfig , code_map : Option < Rc < CodeMapper > > ) -> EmitterWriter {
89
87
if color_config. use_color ( ) {
90
88
let dst = Destination :: from_stderr ( ) ;
91
- EmitterWriter { dst : dst,
92
- cm : code_map}
89
+ EmitterWriter {
90
+ dst : dst,
91
+ cm : code_map,
92
+ }
93
93
} else {
94
- EmitterWriter { dst : Raw ( Box :: new ( io:: stderr ( ) ) ) ,
95
- cm : code_map}
94
+ EmitterWriter {
95
+ dst : Raw ( Box :: new ( io:: stderr ( ) ) ) ,
96
+ cm : code_map,
97
+ }
96
98
}
97
99
}
98
100
99
- pub fn new ( dst : Box < Write + Send > ,
100
- code_map : Option < Rc < CodeMapper > > )
101
- -> EmitterWriter {
101
+ pub fn new ( dst : Box < Write + Send > , code_map : Option < Rc < CodeMapper > > ) -> EmitterWriter {
102
102
EmitterWriter {
103
103
dst : Raw ( dst) ,
104
104
cm : code_map,
@@ -107,9 +107,9 @@ impl EmitterWriter {
107
107
108
108
fn preprocess_annotations ( & self , msp : & MultiSpan ) -> Vec < FileWithAnnotatedLines > {
109
109
fn add_annotation_to_file ( file_vec : & mut Vec < FileWithAnnotatedLines > ,
110
- file : Rc < FileMap > ,
111
- line_index : usize ,
112
- ann : Annotation ) {
110
+ file : Rc < FileMap > ,
111
+ line_index : usize ,
112
+ ann : Annotation ) {
113
113
114
114
for slot in file_vec. iter_mut ( ) {
115
115
// Look through each of our files for the one we're adding to
@@ -168,15 +168,15 @@ impl EmitterWriter {
168
168
}
169
169
170
170
add_annotation_to_file ( & mut output,
171
- lo. file ,
172
- lo. line ,
173
- Annotation {
174
- start_col : lo. col . 0 ,
175
- end_col : hi. col . 0 ,
176
- is_primary : span_label. is_primary ,
177
- is_minimized : is_minimized,
178
- label : span_label. label . clone ( ) ,
179
- } ) ;
171
+ lo. file ,
172
+ lo. line ,
173
+ Annotation {
174
+ start_col : lo. col . 0 ,
175
+ end_col : hi. col . 0 ,
176
+ is_primary : span_label. is_primary ,
177
+ is_minimized : is_minimized,
178
+ label : span_label. label . clone ( ) ,
179
+ } ) ;
180
180
}
181
181
}
182
182
output
@@ -237,19 +237,15 @@ impl EmitterWriter {
237
237
'^' ,
238
238
Style :: UnderlinePrimary ) ;
239
239
if !annotation. is_minimized {
240
- buffer. set_style ( line_offset,
241
- width_offset + p,
242
- Style :: UnderlinePrimary ) ;
240
+ buffer. set_style ( line_offset, width_offset + p, Style :: UnderlinePrimary ) ;
243
241
}
244
242
} else {
245
243
buffer. putc ( line_offset + 1 ,
246
244
width_offset + p,
247
245
'-' ,
248
246
Style :: UnderlineSecondary ) ;
249
247
if !annotation. is_minimized {
250
- buffer. set_style ( line_offset,
251
- width_offset + p,
252
- Style :: UnderlineSecondary ) ;
248
+ buffer. set_style ( line_offset, width_offset + p, Style :: UnderlineSecondary ) ;
253
249
}
254
250
}
255
251
}
@@ -429,8 +425,7 @@ impl EmitterWriter {
429
425
}
430
426
// Check to make sure we're not in any <*macros>
431
427
if !cm. span_to_filename ( def_site) . contains ( "macros>" ) &&
432
- !trace. macro_decl_name . starts_with ( "#[" )
433
- {
428
+ !trace. macro_decl_name . starts_with ( "#[" ) {
434
429
new_labels. push ( ( trace. call_site ,
435
430
"in this macro invocation" . to_string ( ) ) ) ;
436
431
break ;
@@ -475,10 +470,10 @@ impl EmitterWriter {
475
470
if spans_updated {
476
471
children. push ( SubDiagnostic {
477
472
level : Level :: Note ,
478
- message : "this error originates in a macro outside of the current \
479
- crate" . to_string ( ) ,
473
+ message : "this error originates in a macro outside of the current crate"
474
+ . to_string ( ) ,
480
475
span : MultiSpan :: new ( ) ,
481
- render_span : None
476
+ render_span : None ,
482
477
} ) ;
483
478
}
484
479
}
@@ -502,8 +497,7 @@ impl EmitterWriter {
502
497
buffer. append ( 0 , & level. to_string ( ) , Style :: HeaderMsg ) ;
503
498
buffer. append ( 0 , ": " , Style :: NoStyle ) ;
504
499
buffer. append ( 0 , msg, Style :: NoStyle ) ;
505
- }
506
- else {
500
+ } else {
507
501
buffer. append ( 0 , & level. to_string ( ) , Style :: Level ( level. clone ( ) ) ) ;
508
502
match code {
509
503
& Some ( ref code) => {
@@ -522,23 +516,21 @@ impl EmitterWriter {
522
516
let mut annotated_files = self . preprocess_annotations ( msp) ;
523
517
524
518
// Make sure our primary file comes first
525
- let primary_lo =
526
- if let ( Some ( ref cm) , Some ( ref primary_span) ) = ( self . cm . as_ref ( ) ,
527
- msp. primary_span ( ) . as_ref ( ) ) {
528
- if primary_span != & & DUMMY_SP && primary_span != & & COMMAND_LINE_SP {
529
- cm. lookup_char_pos ( primary_span. lo )
530
- }
531
- else {
532
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ?;
533
- return Ok ( ( ) ) ;
534
- }
519
+ let primary_lo = if let ( Some ( ref cm) , Some ( ref primary_span) ) =
520
+ ( self . cm . as_ref ( ) , msp. primary_span ( ) . as_ref ( ) ) {
521
+ if primary_span != & & DUMMY_SP && primary_span != & & COMMAND_LINE_SP {
522
+ cm. lookup_char_pos ( primary_span. lo )
535
523
} else {
536
- // If we don't have span information, emit and exit
537
524
emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ?;
538
525
return Ok ( ( ) ) ;
539
- } ;
526
+ }
527
+ } else {
528
+ // If we don't have span information, emit and exit
529
+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ?;
530
+ return Ok ( ( ) ) ;
531
+ } ;
540
532
if let Ok ( pos) =
541
- annotated_files. binary_search_by ( |x| x. file . name . cmp ( & primary_lo. file . name ) ) {
533
+ annotated_files. binary_search_by ( |x| x. file . name . cmp ( & primary_lo. file . name ) ) {
542
534
annotated_files. swap ( 0 , pos) ;
543
535
}
544
536
@@ -554,8 +546,8 @@ impl EmitterWriter {
554
546
buffer. prepend ( buffer_msg_line_offset, "--> " , Style :: LineNumber ) ;
555
547
let loc = primary_lo. clone ( ) ;
556
548
buffer. append ( buffer_msg_line_offset,
557
- & format ! ( "{}:{}:{}" , loc. file. name, loc. line, loc. col. 0 + 1 ) ,
558
- Style :: LineAndColumn ) ;
549
+ & format ! ( "{}:{}:{}" , loc. file. name, loc. line, loc. col. 0 + 1 ) ,
550
+ Style :: LineAndColumn ) ;
559
551
for _ in 0 ..max_line_num_len {
560
552
buffer. prepend ( buffer_msg_line_offset, " " , Style :: NoStyle ) ;
561
553
}
@@ -569,8 +561,8 @@ impl EmitterWriter {
569
561
// Then, the secondary file indicator
570
562
buffer. prepend ( buffer_msg_line_offset + 1 , "::: " , Style :: LineNumber ) ;
571
563
buffer. append ( buffer_msg_line_offset + 1 ,
572
- & annotated_file. file . name ,
573
- Style :: LineAndColumn ) ;
564
+ & annotated_file. file . name ,
565
+ Style :: LineAndColumn ) ;
574
566
for _ in 0 ..max_line_num_len {
575
567
buffer. prepend ( buffer_msg_line_offset + 1 , " " , Style :: NoStyle ) ;
576
568
}
@@ -591,7 +583,7 @@ impl EmitterWriter {
591
583
// this annotated line and the next one
592
584
if line_idx < ( annotated_file. lines . len ( ) - 1 ) {
593
585
let line_idx_delta = annotated_file. lines [ line_idx + 1 ] . line_index -
594
- annotated_file. lines [ line_idx] . line_index ;
586
+ annotated_file. lines [ line_idx] . line_index ;
595
587
if line_idx_delta > 2 {
596
588
let last_buffer_line_num = buffer. num_lines ( ) ;
597
589
buffer. puts ( last_buffer_line_num, 0 , "..." , Style :: LineNumber ) ;
@@ -672,12 +664,7 @@ impl EmitterWriter {
672
664
let max_line_num = self . get_max_line_num ( span, children) ;
673
665
let max_line_num_len = max_line_num. to_string ( ) . len ( ) ;
674
666
675
- match self . emit_message_default ( span,
676
- message,
677
- code,
678
- level,
679
- max_line_num_len,
680
- false ) {
667
+ match self . emit_message_default ( span, message, code, level, max_line_num_len, false ) {
681
668
Ok ( ( ) ) => {
682
669
if !children. is_empty ( ) {
683
670
let mut buffer = StyledBuffer :: new ( ) ;
@@ -723,13 +710,15 @@ impl EmitterWriter {
723
710
}
724
711
}
725
712
}
726
- Err ( e) => panic ! ( "failed to emit error: {}" , e)
713
+ Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
727
714
}
728
715
match write ! ( & mut self . dst, "\n " ) {
729
716
Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
730
- _ => match self . dst . flush ( ) {
731
- Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
732
- _ => ( )
717
+ _ => {
718
+ match self . dst . flush ( ) {
719
+ Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
720
+ _ => ( ) ,
721
+ }
733
722
}
734
723
}
735
724
}
@@ -753,8 +742,9 @@ fn overlaps(a1: &Annotation, a2: &Annotation) -> bool {
753
742
}
754
743
755
744
fn emit_to_destination ( rendered_buffer : & Vec < Vec < StyledString > > ,
756
- lvl : & Level ,
757
- dst : & mut Destination ) -> io:: Result < ( ) > {
745
+ lvl : & Level ,
746
+ dst : & mut Destination )
747
+ -> io:: Result < ( ) > {
758
748
use lock;
759
749
760
750
// In order to prevent error message interleaving, where multiple error lines get intermixed
@@ -795,8 +785,7 @@ fn stderr_isatty() -> bool {
795
785
const STD_ERROR_HANDLE : DWORD = -12i32 as DWORD ;
796
786
extern "system" {
797
787
fn GetStdHandle ( which : DWORD ) -> HANDLE ;
798
- fn GetConsoleMode ( hConsoleHandle : HANDLE ,
799
- lpMode : * mut DWORD ) -> BOOL ;
788
+ fn GetConsoleMode ( hConsoleHandle : HANDLE , lpMode : * mut DWORD ) -> BOOL ;
800
789
}
801
790
unsafe {
802
791
let handle = GetStdHandle ( STD_ERROR_HANDLE ) ;
@@ -824,9 +813,7 @@ impl BufferedWriter {
824
813
// note: we use _new because the conditional compilation at its use site may make this
825
814
// this function unused on some platforms
826
815
fn _new ( ) -> BufferedWriter {
827
- BufferedWriter {
828
- buffer : vec ! [ ]
829
- }
816
+ BufferedWriter { buffer : vec ! [ ] }
830
817
}
831
818
}
832
819
@@ -853,35 +840,34 @@ impl Destination {
853
840
/// When not on Windows, prefer the buffered terminal so that we can buffer an entire error
854
841
/// to be emitted at one time.
855
842
fn from_stderr ( ) -> Destination {
856
- let stderr: Option < Box < BufferedStderr > > =
843
+ let stderr: Option < Box < BufferedStderr > > =
857
844
term:: TerminfoTerminal :: new ( BufferedWriter :: _new ( ) )
858
845
. map ( |t| Box :: new ( t) as Box < BufferedStderr > ) ;
859
846
860
847
match stderr {
861
848
Some ( t) => BufferedTerminal ( t) ,
862
- None => Raw ( Box :: new ( io:: stderr ( ) ) ) ,
849
+ None => Raw ( Box :: new ( io:: stderr ( ) ) ) ,
863
850
}
864
851
}
865
852
866
853
#[ cfg( windows) ]
867
854
/// Return a normal, unbuffered terminal when on Windows.
868
855
fn from_stderr ( ) -> Destination {
869
- let stderr: Option < Box < term:: StderrTerminal > > =
870
- term:: TerminfoTerminal :: new ( io:: stderr ( ) )
871
- . map ( |t| Box :: new ( t) as Box < term:: StderrTerminal > )
872
- . or_else ( || term:: WinConsole :: new ( io:: stderr ( ) ) . ok ( )
873
- . map ( |t| Box :: new ( t) as Box < term:: StderrTerminal > ) ) ;
856
+ let stderr: Option < Box < term:: StderrTerminal > > = term:: TerminfoTerminal :: new ( io:: stderr ( ) )
857
+ . map ( |t| Box :: new ( t) as Box < term:: StderrTerminal > )
858
+ . or_else ( || {
859
+ term:: WinConsole :: new ( io:: stderr ( ) )
860
+ . ok ( )
861
+ . map ( |t| Box :: new ( t) as Box < term:: StderrTerminal > )
862
+ } ) ;
874
863
875
864
match stderr {
876
865
Some ( t) => Terminal ( t) ,
877
- None => Raw ( Box :: new ( io:: stderr ( ) ) ) ,
866
+ None => Raw ( Box :: new ( io:: stderr ( ) ) ) ,
878
867
}
879
868
}
880
869
881
- fn apply_style ( & mut self ,
882
- lvl : Level ,
883
- style : Style )
884
- -> io:: Result < ( ) > {
870
+ fn apply_style ( & mut self , lvl : Level , style : Style ) -> io:: Result < ( ) > {
885
871
match style {
886
872
Style :: FileNameStyle | Style :: LineAndColumn => { }
887
873
Style :: LineNumber => {
@@ -931,18 +917,26 @@ impl Destination {
931
917
932
918
fn start_attr ( & mut self , attr : term:: Attr ) -> io:: Result < ( ) > {
933
919
match * self {
934
- Terminal ( ref mut t) => { t. attr ( attr) ?; }
935
- BufferedTerminal ( ref mut t) => { t. attr ( attr) ?; }
936
- Raw ( _) => { }
920
+ Terminal ( ref mut t) => {
921
+ t. attr ( attr) ?;
922
+ }
923
+ BufferedTerminal ( ref mut t) => {
924
+ t. attr ( attr) ?;
925
+ }
926
+ Raw ( _) => { }
937
927
}
938
928
Ok ( ( ) )
939
929
}
940
930
941
931
fn reset_attrs ( & mut self ) -> io:: Result < ( ) > {
942
932
match * self {
943
- Terminal ( ref mut t) => { t. reset ( ) ?; }
944
- BufferedTerminal ( ref mut t) => { t. reset ( ) ?; }
945
- Raw ( _) => { }
933
+ Terminal ( ref mut t) => {
934
+ t. reset ( ) ?;
935
+ }
936
+ BufferedTerminal ( ref mut t) => {
937
+ t. reset ( ) ?;
938
+ }
939
+ Raw ( _) => { }
946
940
}
947
941
Ok ( ( ) )
948
942
}
0 commit comments