@@ -14,13 +14,12 @@ use syntax_pos::{COMMAND_LINE_SP, DUMMY_SP, FileMap, Span, MultiSpan, LineInfo,
14
14
use registry;
15
15
16
16
use check_old_skool;
17
- use { Level , RenderSpan , CodeSuggestion , DiagnosticBuilder , CodeMapper } ;
17
+ use { Level , CodeSuggestion , DiagnosticBuilder , CodeMapper } ;
18
18
use RenderSpan :: * ;
19
- use Level :: * ;
20
- use snippet:: { SnippetData , StyledString , Style , FormatMode , Annotation , Line } ;
19
+ use snippet:: { StyledString , Style , FormatMode , Annotation , Line } ;
21
20
use styled_buffer:: StyledBuffer ;
22
21
23
- use std:: { cmp, fmt } ;
22
+ use std:: cmp;
24
23
use std:: io:: prelude:: * ;
25
24
use std:: io;
26
25
use std:: rc:: Rc ;
@@ -73,10 +72,6 @@ pub struct EmitterWriter {
73
72
registry : Option < registry:: Registry > ,
74
73
cm : Option < Rc < CodeMapper > > ,
75
74
76
- /// Is this the first error emitted thus far? If not, we emit a
77
- /// `\n` before the top-level errors.
78
- first : bool ,
79
-
80
75
// For now, allow an old-school mode while we transition
81
76
format_mode : FormatMode
82
77
}
@@ -112,13 +107,11 @@ impl EmitterWriter {
112
107
EmitterWriter { dst : dst,
113
108
registry : registry,
114
109
cm : code_map,
115
- first : true ,
116
110
format_mode : format_mode. clone ( ) }
117
111
} else {
118
112
EmitterWriter { dst : Raw ( Box :: new ( io:: stderr ( ) ) ) ,
119
113
registry : registry,
120
114
cm : code_map,
121
- first : true ,
122
115
format_mode : format_mode. clone ( ) }
123
116
}
124
117
}
@@ -131,23 +124,9 @@ impl EmitterWriter {
131
124
EmitterWriter { dst : Raw ( dst) ,
132
125
registry : registry,
133
126
cm : code_map,
134
- first : true ,
135
127
format_mode : format_mode. clone ( ) }
136
128
}
137
129
138
- fn emit_message ( & mut self ,
139
- rsp : & RenderSpan ,
140
- msg : & str ,
141
- code : Option < & str > ,
142
- lvl : Level ,
143
- is_header : bool ,
144
- show_snippet : bool ) {
145
- match self . emit_message_ ( rsp, msg, code, lvl, is_header, show_snippet) {
146
- Ok ( ( ) ) => { }
147
- Err ( e) => panic ! ( "failed to emit error: {}" , e)
148
- }
149
- }
150
-
151
130
fn preprocess_annotations ( & self , msp : & MultiSpan ) -> Vec < FileWithAnnotatedLines > {
152
131
fn add_annotation_to_file ( file_vec : & mut Vec < FileWithAnnotatedLines > ,
153
132
file : Rc < FileMap > ,
@@ -187,7 +166,7 @@ impl EmitterWriter {
187
166
188
167
if let Some ( ref cm) = self . cm {
189
168
for span_label in msp. span_labels ( ) {
190
- let mut lo = cm. lookup_char_pos ( span_label. span . lo ) ;
169
+ let lo = cm. lookup_char_pos ( span_label. span . lo ) ;
191
170
let mut hi = cm. lookup_char_pos ( span_label. span . hi ) ;
192
171
let mut is_minimized = false ;
193
172
@@ -478,7 +457,7 @@ impl EmitterWriter {
478
457
479
458
if msp. primary_spans ( ) . is_empty ( ) && msp. span_labels ( ) . is_empty ( ) && is_secondary {
480
459
// This is a secondary message with no span info
481
- for i in 0 ..max_line_num_len {
460
+ for _ in 0 ..max_line_num_len {
482
461
buffer. prepend ( 0 , " " , Style :: NoStyle ) ;
483
462
}
484
463
draw_note_separator ( & mut buffer, 0 , max_line_num_len + 1 ) ;
@@ -511,7 +490,7 @@ impl EmitterWriter {
511
490
cm. lookup_char_pos ( primary_span. lo )
512
491
} else {
513
492
// If we don't have span information, emit and exit
514
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ;
493
+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ? ;
515
494
return Ok ( ( ) ) ;
516
495
} ;
517
496
if let Ok ( pos) =
@@ -526,19 +505,19 @@ impl EmitterWriter {
526
505
let is_primary = primary_lo. file . name == annotated_file. file . name ;
527
506
if is_primary {
528
507
// remember where we are in the output buffer for easy reference
529
- let mut buffer_msg_line_offset = buffer. num_lines ( ) ;
508
+ let buffer_msg_line_offset = buffer. num_lines ( ) ;
530
509
531
510
buffer. prepend ( buffer_msg_line_offset, "--> " , Style :: LineNumber ) ;
532
511
let loc = primary_lo. clone ( ) ;
533
512
buffer. append ( buffer_msg_line_offset,
534
513
& format ! ( "{}:{}:{}" , loc. file. name, loc. line, loc. col. 0 + 1 ) ,
535
514
Style :: LineAndColumn ) ;
536
- for i in 0 ..max_line_num_len {
515
+ for _ in 0 ..max_line_num_len {
537
516
buffer. prepend ( buffer_msg_line_offset, " " , Style :: NoStyle ) ;
538
517
}
539
518
} else {
540
519
// remember where we are in the output buffer for easy reference
541
- let mut buffer_msg_line_offset = buffer. num_lines ( ) ;
520
+ let buffer_msg_line_offset = buffer. num_lines ( ) ;
542
521
543
522
// Add spacing line
544
523
draw_col_separator ( & mut buffer, buffer_msg_line_offset, max_line_num_len + 1 ) ;
@@ -548,13 +527,13 @@ impl EmitterWriter {
548
527
buffer. append ( buffer_msg_line_offset + 1 ,
549
528
& annotated_file. file . name ,
550
529
Style :: LineAndColumn ) ;
551
- for i in 0 ..max_line_num_len {
530
+ for _ in 0 ..max_line_num_len {
552
531
buffer. prepend ( buffer_msg_line_offset + 1 , " " , Style :: NoStyle ) ;
553
532
}
554
533
}
555
534
556
535
// Put in the spacer between the location and annotated source
557
- let mut buffer_msg_line_offset = buffer. num_lines ( ) ;
536
+ let buffer_msg_line_offset = buffer. num_lines ( ) ;
558
537
draw_col_separator ( & mut buffer, buffer_msg_line_offset, max_line_num_len + 1 ) ;
559
538
560
539
// Next, output the annotate source for this file
@@ -599,7 +578,7 @@ impl EmitterWriter {
599
578
}
600
579
601
580
// final step: take our styled buffer, render it, then output it
602
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ;
581
+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ? ;
603
582
604
583
Ok ( ( ) )
605
584
}
@@ -624,12 +603,6 @@ impl EmitterWriter {
624
603
assert ! ( !lines. lines. is_empty( ) ) ;
625
604
626
605
let complete = suggestion. splice_lines ( cm. borrow ( ) ) ;
627
- let line_count = cmp:: min ( lines. lines . len ( ) , MAX_HIGHLIGHT_LINES ) ;
628
- let display_lines = & lines. lines [ ..line_count] ;
629
-
630
- let fm = & * lines. file ;
631
- // Calculate the widest number to format evenly
632
- let max_digits = line_num_max_digits ( display_lines. last ( ) . unwrap ( ) ) ;
633
606
634
607
// print the suggestion without any line numbers, but leave
635
608
// space for them. This helps with lining up with previous
@@ -646,7 +619,7 @@ impl EmitterWriter {
646
619
if let Some ( _) = lines. next ( ) {
647
620
buffer. append ( row_num, "..." , Style :: NoStyle ) ;
648
621
}
649
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ;
622
+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ? ;
650
623
}
651
624
Ok ( ( ) )
652
625
}
@@ -664,7 +637,10 @@ impl EmitterWriter {
664
637
if !db. children . is_empty ( ) {
665
638
let mut buffer = StyledBuffer :: new ( ) ;
666
639
draw_col_separator ( & mut buffer, 0 , max_line_num_len + 1 ) ;
667
- emit_to_destination ( & buffer. render ( ) , & db. level , & mut self . dst ) ;
640
+ match emit_to_destination ( & buffer. render ( ) , & db. level , & mut self . dst ) {
641
+ Ok ( ( ) ) => ( ) ,
642
+ Err ( e) => panic ! ( "failed to emit error: {}" , e)
643
+ }
668
644
}
669
645
for child in & db. children {
670
646
match child. render_span {
@@ -704,7 +680,10 @@ impl EmitterWriter {
704
680
}
705
681
Err ( e) => panic ! ( "failed to emit error: {}" , e)
706
682
}
707
- write ! ( & mut self . dst, "\n " ) ;
683
+ match write ! ( & mut self . dst, "\n " ) {
684
+ Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
685
+ _ => ( )
686
+ }
708
687
}
709
688
fn emit_message_old_school ( & mut self ,
710
689
msp : & MultiSpan ,
@@ -744,21 +723,21 @@ impl EmitterWriter {
744
723
}
745
724
746
725
if !show_snippet {
747
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ;
726
+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ? ;
748
727
return Ok ( ( ) ) ;
749
728
}
750
729
751
730
// Watch out for various nasty special spans; don't try to
752
731
// print any filename or anything for those.
753
732
match msp. primary_span ( ) {
754
733
Some ( COMMAND_LINE_SP ) | Some ( DUMMY_SP ) => {
755
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ;
734
+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ? ;
756
735
return Ok ( ( ) ) ;
757
736
}
758
737
_ => { }
759
738
}
760
739
761
- let mut annotated_files = self . preprocess_annotations ( msp) ;
740
+ let annotated_files = self . preprocess_annotations ( msp) ;
762
741
763
742
if let ( Some ( ref cm) , Some ( ann_file) , Some ( ref primary_span) ) =
764
743
( self . cm . as_ref ( ) , annotated_files. first ( ) , msp. primary_span ( ) . as_ref ( ) ) {
@@ -781,7 +760,7 @@ impl EmitterWriter {
781
760
buffer. puts ( line_offset, 0 , & file_pos, Style :: FileNameStyle ) ;
782
761
buffer. puts ( line_offset, file_pos_len, & source_string, Style :: Quotation ) ;
783
762
// Sort the annotations by (start, end col)
784
- let mut annotations = ann_file. lines [ 0 ] . annotations . clone ( ) ;
763
+ let annotations = ann_file. lines [ 0 ] . annotations . clone ( ) ;
785
764
786
765
// Next, create the highlight line.
787
766
for annotation in & annotations {
@@ -830,7 +809,7 @@ impl EmitterWriter {
830
809
}
831
810
832
811
// final step: take our styled buffer, render it, then output it
833
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ;
812
+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ? ;
834
813
Ok ( ( ) )
835
814
}
836
815
fn emit_suggestion_old_school ( & mut self ,
@@ -874,7 +853,7 @@ impl EmitterWriter {
874
853
let mut row_num = 1 ;
875
854
for line in lines. by_ref ( ) . take ( MAX_HIGHLIGHT_LINES ) {
876
855
buffer. append ( row_num, & fm. name , Style :: FileNameStyle ) ;
877
- for i in 0 ..max_digits+2 {
856
+ for _ in 0 ..max_digits+2 {
878
857
buffer. append ( row_num, & " " , Style :: NoStyle ) ;
879
858
}
880
859
buffer. append ( row_num, line, Style :: NoStyle ) ;
@@ -885,7 +864,7 @@ impl EmitterWriter {
885
864
if let Some ( _) = lines. next ( ) {
886
865
buffer. append ( row_num, "..." , Style :: NoStyle ) ;
887
866
}
888
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ;
867
+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ? ;
889
868
}
890
869
Ok ( ( ) )
891
870
}
@@ -905,7 +884,7 @@ impl EmitterWriter {
905
884
} ;
906
885
907
886
match child. render_span {
908
- Some ( FullSpan ( ref msp ) ) => {
887
+ Some ( FullSpan ( _ ) ) => {
909
888
match self . emit_message_old_school ( & span,
910
889
& child. message ,
911
890
& None ,
@@ -940,235 +919,6 @@ impl EmitterWriter {
940
919
}
941
920
}
942
921
943
- fn emit_message_ ( & mut self ,
944
- rsp : & RenderSpan ,
945
- msg : & str ,
946
- code : Option < & str > ,
947
- lvl : Level ,
948
- is_header : bool ,
949
- show_snippet : bool )
950
- -> io:: Result < ( ) > {
951
- let old_school = match self . format_mode {
952
- FormatMode :: NewErrorFormat => false ,
953
- FormatMode :: OriginalErrorFormat => true ,
954
- FormatMode :: EnvironmentSelected => check_old_skool ( )
955
- } ;
956
-
957
- if is_header {
958
- if self . first {
959
- self . first = false ;
960
- } else {
961
- if !old_school {
962
- write ! ( self . dst, "\n " ) ?;
963
- }
964
- }
965
- }
966
-
967
- match code {
968
- Some ( code) if self . registry . as_ref ( )
969
- . and_then ( |registry| registry. find_description ( code) )
970
- . is_some ( ) => {
971
- let code_with_explain = String :: from ( "--explain " ) + code;
972
- if old_school {
973
- let loc = match rsp. span ( ) . primary_span ( ) {
974
- Some ( COMMAND_LINE_SP ) | Some ( DUMMY_SP ) => "" . to_string ( ) ,
975
- Some ( ps) => if let Some ( ref cm) = self . cm {
976
- cm. span_to_string ( ps)
977
- } else {
978
- "" . to_string ( )
979
- } ,
980
- None => "" . to_string ( )
981
- } ;
982
- print_diagnostic ( & mut self . dst , & loc, lvl, msg, Some ( code) ) ?
983
- }
984
- else {
985
- print_diagnostic ( & mut self . dst , "" , lvl, msg, Some ( & code_with_explain) ) ?
986
- }
987
- }
988
- _ => {
989
- if old_school {
990
- let loc = match rsp. span ( ) . primary_span ( ) {
991
- Some ( COMMAND_LINE_SP ) | Some ( DUMMY_SP ) => "" . to_string ( ) ,
992
- Some ( ps) => if let Some ( ref cm) = self . cm {
993
- cm. span_to_string ( ps)
994
- } else {
995
- "" . to_string ( )
996
- } ,
997
- None => "" . to_string ( )
998
- } ;
999
- print_diagnostic ( & mut self . dst , & loc, lvl, msg, code) ?
1000
- }
1001
- else {
1002
- print_diagnostic ( & mut self . dst , "" , lvl, msg, code) ?
1003
- }
1004
- }
1005
- }
1006
-
1007
- if !show_snippet {
1008
- return Ok ( ( ) ) ;
1009
- }
1010
-
1011
- // Watch out for various nasty special spans; don't try to
1012
- // print any filename or anything for those.
1013
- match rsp. span ( ) . primary_span ( ) {
1014
- Some ( COMMAND_LINE_SP ) | Some ( DUMMY_SP ) => {
1015
- return Ok ( ( ) ) ;
1016
- }
1017
- _ => { }
1018
- }
1019
-
1020
- // Otherwise, print out the snippet etc as needed.
1021
- match * rsp {
1022
- FullSpan ( ref msp) => {
1023
- self . highlight_lines ( msp, lvl) ?;
1024
- if let Some ( primary_span) = msp. primary_span ( ) {
1025
- self . print_macro_backtrace ( primary_span) ?;
1026
- }
1027
- }
1028
- Suggestion ( ref suggestion) => {
1029
- self . highlight_suggestion ( suggestion) ?;
1030
- if let Some ( primary_span) = rsp. span ( ) . primary_span ( ) {
1031
- self . print_macro_backtrace ( primary_span) ?;
1032
- }
1033
- }
1034
- }
1035
- if old_school {
1036
- match code {
1037
- Some ( code) if self . registry . as_ref ( )
1038
- . and_then ( |registry| registry. find_description ( code) )
1039
- . is_some ( ) => {
1040
- let loc = match rsp. span ( ) . primary_span ( ) {
1041
- Some ( COMMAND_LINE_SP ) | Some ( DUMMY_SP ) => "" . to_string ( ) ,
1042
- Some ( ps) => if let Some ( ref cm) = self . cm {
1043
- cm. span_to_string ( ps)
1044
- } else {
1045
- "" . to_string ( )
1046
- } ,
1047
- None => "" . to_string ( )
1048
- } ;
1049
- let msg = "run `rustc --explain " . to_string ( ) + & code. to_string ( ) +
1050
- "` to see a detailed explanation" ;
1051
- print_diagnostic ( & mut self . dst , & loc, Level :: Help , & msg,
1052
- None ) ?
1053
- }
1054
- _ => ( )
1055
- }
1056
- }
1057
- Ok ( ( ) )
1058
- }
1059
-
1060
- fn highlight_suggestion ( & mut self , suggestion : & CodeSuggestion ) -> io:: Result < ( ) >
1061
- {
1062
- use std:: borrow:: Borrow ;
1063
-
1064
- let primary_span = suggestion. msp . primary_span ( ) . unwrap ( ) ;
1065
- if let Some ( ref cm) = self . cm {
1066
- let lines = cm. span_to_lines ( primary_span) . unwrap ( ) ;
1067
-
1068
- assert ! ( !lines. lines. is_empty( ) ) ;
1069
-
1070
- let complete = suggestion. splice_lines ( cm. borrow ( ) ) ;
1071
- let line_count = cmp:: min ( lines. lines . len ( ) , MAX_HIGHLIGHT_LINES ) ;
1072
- let display_lines = & lines. lines [ ..line_count] ;
1073
-
1074
- let fm = & * lines. file ;
1075
- // Calculate the widest number to format evenly
1076
- let max_digits = line_num_max_digits ( display_lines. last ( ) . unwrap ( ) ) ;
1077
-
1078
- // print the suggestion without any line numbers, but leave
1079
- // space for them. This helps with lining up with previous
1080
- // snippets from the actual error being reported.
1081
- let mut lines = complete. lines ( ) ;
1082
- for line in lines. by_ref ( ) . take ( MAX_HIGHLIGHT_LINES ) {
1083
- write ! ( & mut self . dst, "{0}:{1:2$} {3}\n " ,
1084
- fm. name, "" , max_digits, line) ?;
1085
- }
1086
-
1087
- // if we elided some lines, add an ellipsis
1088
- if let Some ( _) = lines. next ( ) {
1089
- write ! ( & mut self . dst, "{0:1$} {0:2$} ...\n " ,
1090
- "" , fm. name. len( ) , max_digits) ?;
1091
- }
1092
- }
1093
- Ok ( ( ) )
1094
- }
1095
-
1096
- pub fn highlight_lines ( & mut self ,
1097
- msp : & MultiSpan ,
1098
- lvl : Level )
1099
- -> io:: Result < ( ) >
1100
- {
1101
- // Check to see if we have any lines to highlight, exit early if not
1102
- match self . cm {
1103
- None => return Ok ( ( ) ) ,
1104
- _ => ( )
1105
- }
1106
-
1107
- let old_school = match self . format_mode {
1108
- FormatMode :: NewErrorFormat => false ,
1109
- FormatMode :: OriginalErrorFormat => true ,
1110
- FormatMode :: EnvironmentSelected => check_old_skool ( )
1111
- } ;
1112
-
1113
- let mut snippet_data = SnippetData :: new ( self . cm . as_ref ( ) . unwrap ( ) . clone ( ) ,
1114
- msp. primary_span ( ) ,
1115
- self . format_mode . clone ( ) ) ;
1116
- if old_school {
1117
- let mut output_vec = vec ! [ ] ;
1118
-
1119
- for span_label in msp. span_labels ( ) {
1120
- let mut snippet_data = SnippetData :: new ( self . cm . as_ref ( ) . unwrap ( ) . clone ( ) ,
1121
- Some ( span_label. span ) ,
1122
- self . format_mode . clone ( ) ) ;
1123
-
1124
- snippet_data. push ( span_label. span ,
1125
- span_label. is_primary ,
1126
- span_label. label ) ;
1127
- if span_label. is_primary {
1128
- output_vec. insert ( 0 , snippet_data) ;
1129
- }
1130
- else {
1131
- output_vec. push ( snippet_data) ;
1132
- }
1133
- }
1134
-
1135
- for snippet_data in output_vec. iter ( ) {
1136
- /*
1137
- let rendered_lines = snippet_data.render_lines();
1138
- for rendered_line in &rendered_lines {
1139
- for styled_string in &rendered_line.text {
1140
- self.dst.apply_style(lvl, &rendered_line.kind, styled_string.style)?;
1141
- write!(&mut self.dst, "{}", styled_string.text)?;
1142
- self.dst.reset_attrs()?;
1143
- }
1144
- write!(&mut self.dst, "\n")?;
1145
- }
1146
- */
1147
- emit_to_destination ( & snippet_data. render_lines ( ) , & lvl, & mut self . dst ) ;
1148
- }
1149
- }
1150
- else {
1151
- for span_label in msp. span_labels ( ) {
1152
- snippet_data. push ( span_label. span ,
1153
- span_label. is_primary ,
1154
- span_label. label ) ;
1155
- }
1156
- emit_to_destination ( & snippet_data. render_lines ( ) , & lvl, & mut self . dst ) ;
1157
- /*
1158
- let rendered_lines = snippet_data.render_lines();
1159
- for rendered_line in &rendered_lines {
1160
- for styled_string in &rendered_line.text {
1161
- self.dst.apply_style(lvl, &rendered_line.kind, styled_string.style)?;
1162
- write!(&mut self.dst, "{}", styled_string.text)?;
1163
- self.dst.reset_attrs()?;
1164
- }
1165
- write!(&mut self.dst, "\n")?;
1166
- }
1167
- */
1168
- }
1169
- Ok ( ( ) )
1170
- }
1171
-
1172
922
fn render_macro_backtrace_old_school ( & mut self ,
1173
923
sp : & Span ,
1174
924
buffer : & mut StyledBuffer ) -> io:: Result < ( ) > {
@@ -1192,24 +942,6 @@ impl EmitterWriter {
1192
942
}
1193
943
Ok ( ( ) )
1194
944
}
1195
- fn print_macro_backtrace ( & mut self ,
1196
- sp : Span )
1197
- -> io:: Result < ( ) > {
1198
- if let Some ( ref cm) = self . cm {
1199
- for trace in cm. macro_backtrace ( sp) {
1200
- let mut diag_string =
1201
- format ! ( "in this expansion of {}" , trace. macro_decl_name) ;
1202
- if let Some ( def_site_span) = trace. def_site_span {
1203
- diag_string. push_str (
1204
- & format ! ( " (defined in {})" ,
1205
- cm. span_to_filename( def_site_span) ) ) ;
1206
- }
1207
- let snippet = cm. span_to_string ( trace. call_site ) ;
1208
- print_diagnostic ( & mut self . dst , & snippet, Note , & diag_string, None ) ?;
1209
- }
1210
- }
1211
- Ok ( ( ) )
1212
- }
1213
945
}
1214
946
1215
947
fn draw_col_separator ( buffer : & mut StyledBuffer , line : usize , col : usize ) {
@@ -1230,11 +962,11 @@ fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
1230
962
dst : & mut Destination ) -> io:: Result < ( ) > {
1231
963
for line in rendered_buffer {
1232
964
for part in line {
1233
- dst. apply_style ( lvl. clone ( ) , part. style ) ;
1234
- write ! ( dst, "{}" , part. text) ;
965
+ dst. apply_style ( lvl. clone ( ) , part. style ) ? ;
966
+ write ! ( dst, "{}" , part. text) ? ;
1235
967
dst. reset_attrs ( ) ?;
1236
968
}
1237
- write ! ( dst, "\n " ) ;
969
+ write ! ( dst, "\n " ) ? ;
1238
970
}
1239
971
Ok ( ( ) )
1240
972
}
@@ -1249,40 +981,6 @@ fn line_num_max_digits(line: &LineInfo) -> usize {
1249
981
digits
1250
982
}
1251
983
1252
- fn print_diagnostic ( dst : & mut Destination ,
1253
- topic : & str ,
1254
- lvl : Level ,
1255
- msg : & str ,
1256
- code : Option < & str > )
1257
- -> io:: Result < ( ) > {
1258
- if !topic. is_empty ( ) {
1259
- let old_school = check_old_skool ( ) ;
1260
- if !old_school {
1261
- write ! ( dst, "{}: " , topic) ?;
1262
- }
1263
- else {
1264
- write ! ( dst, "{} " , topic) ?;
1265
- }
1266
- dst. reset_attrs ( ) ?;
1267
- }
1268
- dst. start_attr ( term:: Attr :: Bold ) ?;
1269
- dst. start_attr ( term:: Attr :: ForegroundColor ( lvl. color ( ) ) ) ?;
1270
- write ! ( dst, "{}" , lvl. to_string( ) ) ?;
1271
- dst. reset_attrs ( ) ?;
1272
- write ! ( dst, ": " ) ?;
1273
- dst. start_attr ( term:: Attr :: Bold ) ?;
1274
- write ! ( dst, "{}" , msg) ?;
1275
-
1276
- if let Some ( code) = code {
1277
- let style = term:: Attr :: ForegroundColor ( term:: color:: BRIGHT_MAGENTA ) ;
1278
- print_maybe_styled ! ( dst, style, " [{}]" , code. clone( ) ) ?;
1279
- }
1280
-
1281
- dst. reset_attrs ( ) ?;
1282
- write ! ( dst, "\n " ) ?;
1283
- Ok ( ( ) )
1284
- }
1285
-
1286
984
#[ cfg( unix) ]
1287
985
fn stderr_isatty ( ) -> bool {
1288
986
use libc;
@@ -1374,46 +1072,6 @@ impl Destination {
1374
1072
}
1375
1073
Ok ( ( ) )
1376
1074
}
1377
-
1378
- fn print_maybe_styled ( & mut self ,
1379
- args : fmt:: Arguments ,
1380
- color : term:: Attr ,
1381
- print_newline_at_end : bool )
1382
- -> io:: Result < ( ) > {
1383
- match * self {
1384
- Terminal ( ref mut t) => {
1385
- t. attr ( color) ?;
1386
- // If `msg` ends in a newline, we need to reset the color before
1387
- // the newline. We're making the assumption that we end up writing
1388
- // to a `LineBufferedWriter`, which means that emitting the reset
1389
- // after the newline ends up buffering the reset until we print
1390
- // another line or exit. Buffering the reset is a problem if we're
1391
- // sharing the terminal with any other programs (e.g. other rustc
1392
- // instances via `make -jN`).
1393
- //
1394
- // Note that if `msg` contains any internal newlines, this will
1395
- // result in the `LineBufferedWriter` flushing twice instead of
1396
- // once, which still leaves the opportunity for interleaved output
1397
- // to be miscolored. We assume this is rare enough that we don't
1398
- // have to worry about it.
1399
- t. write_fmt ( args) ?;
1400
- t. reset ( ) ?;
1401
- if print_newline_at_end {
1402
- t. write_all ( b"\n " )
1403
- } else {
1404
- Ok ( ( ) )
1405
- }
1406
- }
1407
- Raw ( ref mut w) => {
1408
- w. write_fmt ( args) ?;
1409
- if print_newline_at_end {
1410
- w. write_all ( b"\n " )
1411
- } else {
1412
- Ok ( ( ) )
1413
- }
1414
- }
1415
- }
1416
- }
1417
1075
}
1418
1076
1419
1077
impl Write for Destination {
0 commit comments