@@ -21,7 +21,7 @@ use atty;
2121use std:: borrow:: Cow ;
2222use std:: io:: prelude:: * ;
2323use std:: io;
24- use std:: collections:: { HashMap , HashSet } ;
24+ use std:: collections:: HashMap ;
2525use std:: cmp:: min;
2626use termcolor:: { StandardStream , ColorChoice , ColorSpec , BufferWriter } ;
2727use termcolor:: { WriteColor , Color , Buffer } ;
@@ -33,6 +33,11 @@ const ANONYMIZED_LINE_NUM: &str = "LL";
3333pub trait Emitter {
3434 /// Emit a structured diagnostic.
3535 fn emit ( & mut self , db : & DiagnosticBuilder ) ;
36+
37+ /// Check if should show explanations about "rustc --explain"
38+ fn should_show_explain ( & self ) -> bool {
39+ true
40+ }
3641}
3742
3843impl Emitter for EmitterWriter {
@@ -80,6 +85,10 @@ impl Emitter for EmitterWriter {
8085 & children,
8186 & suggestions) ;
8287 }
88+
89+ fn should_show_explain ( & self ) -> bool {
90+ !self . short_message
91+ }
8392}
8493
8594/// maximum number of lines we will print for each error; arbitrary.
@@ -114,7 +123,6 @@ pub struct EmitterWriter {
114123 cm : Option < Lrc < CodeMapper > > ,
115124 short_message : bool ,
116125 teach : bool ,
117- error_codes : HashSet < String > ,
118126 ui_testing : bool ,
119127}
120128
@@ -124,34 +132,6 @@ struct FileWithAnnotatedLines {
124132 multiline_depth : usize ,
125133}
126134
127- impl Drop for EmitterWriter {
128- fn drop ( & mut self ) {
129- if !self . short_message && !self . error_codes . is_empty ( ) {
130- let mut error_codes = self . error_codes . clone ( ) . into_iter ( ) . collect :: < Vec < _ > > ( ) ;
131- let mut dst = self . dst . writable ( ) ;
132- error_codes. sort ( ) ;
133- if error_codes. len ( ) > 1 {
134- let limit = if error_codes. len ( ) > 9 { 9 } else { error_codes. len ( ) } ;
135- writeln ! ( dst,
136- "You've got a few errors: {}{}" ,
137- error_codes[ ..limit] . join( ", " ) ,
138- if error_codes. len( ) > 9 { "..." } else { "" }
139- ) . expect ( "failed to give tips..." ) ;
140- writeln ! ( dst,
141- "If you want more information on an error, try using \
142- \" rustc --explain {}\" ",
143- & error_codes[ 0 ] ) . expect ( "failed to give tips..." ) ;
144- } else {
145- writeln ! ( dst,
146- "If you want more information on this error, try using \
147- \" rustc --explain {}\" ",
148- & error_codes[ 0 ] ) . expect ( "failed to give tips..." ) ;
149- }
150- dst. flush ( ) . expect ( "failed to emit errors" ) ;
151- }
152- }
153- }
154-
155135impl EmitterWriter {
156136 pub fn stderr ( color_config : ColorConfig ,
157137 code_map : Option < Lrc < CodeMapper > > ,
@@ -164,7 +144,6 @@ impl EmitterWriter {
164144 cm : code_map,
165145 short_message,
166146 teach,
167- error_codes : HashSet :: new ( ) ,
168147 ui_testing : false ,
169148 }
170149 }
@@ -179,7 +158,6 @@ impl EmitterWriter {
179158 cm : code_map,
180159 short_message,
181160 teach,
182- error_codes : HashSet :: new ( ) ,
183161 ui_testing : false ,
184162 }
185163 }
@@ -993,18 +971,26 @@ impl EmitterWriter {
993971 buffer. prepend ( 0 , " " , Style :: NoStyle ) ;
994972 }
995973 draw_note_separator ( & mut buffer, 0 , max_line_num_len + 1 ) ;
996- buffer. append ( 0 , & level. to_string ( ) , Style :: HeaderMsg ) ;
997- buffer. append ( 0 , ": " , Style :: NoStyle ) ;
974+ let level_str = level. to_string ( ) ;
975+ if !level_str. is_empty ( ) {
976+ buffer. append ( 0 , & level_str, Style :: HeaderMsg ) ;
977+ buffer. append ( 0 , ": " , Style :: NoStyle ) ;
978+ }
998979 self . msg_to_buffer ( & mut buffer, msg, max_line_num_len, "note" , None ) ;
999980 } else {
1000- buffer. append ( 0 , & level. to_string ( ) , Style :: Level ( level. clone ( ) ) ) ;
981+ let level_str = level. to_string ( ) ;
982+ if !level_str. is_empty ( ) {
983+ buffer. append ( 0 , & level_str, Style :: Level ( level. clone ( ) ) ) ;
984+ }
1001985 // only render error codes, not lint codes
1002986 if let Some ( DiagnosticId :: Error ( ref code) ) = * code {
1003987 buffer. append ( 0 , "[" , Style :: Level ( level. clone ( ) ) ) ;
1004988 buffer. append ( 0 , & code, Style :: Level ( level. clone ( ) ) ) ;
1005989 buffer. append ( 0 , "]" , Style :: Level ( level. clone ( ) ) ) ;
1006990 }
1007- buffer. append ( 0 , ": " , Style :: HeaderMsg ) ;
991+ if !level_str. is_empty ( ) {
992+ buffer. append ( 0 , ": " , Style :: HeaderMsg ) ;
993+ }
1008994 for & ( ref text, _) in msg. iter ( ) {
1009995 buffer. append ( 0 , text, Style :: HeaderMsg ) ;
1010996 }
@@ -1020,14 +1006,12 @@ impl EmitterWriter {
10201006 if primary_span != & & DUMMY_SP {
10211007 ( cm. lookup_char_pos ( primary_span. lo ( ) ) , cm)
10221008 } else {
1023- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ,
1024- & mut self . error_codes ) ?;
1009+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ) ?;
10251010 return Ok ( ( ) ) ;
10261011 }
10271012 } else {
10281013 // If we don't have span information, emit and exit
1029- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ,
1030- & mut self . error_codes ) ?;
1014+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ) ?;
10311015 return Ok ( ( ) ) ;
10321016 } ;
10331017 if let Ok ( pos) =
@@ -1200,8 +1184,7 @@ impl EmitterWriter {
12001184 }
12011185
12021186 // final step: take our styled buffer, render it, then output it
1203- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ,
1204- & mut self . error_codes ) ?;
1187+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ) ?;
12051188
12061189 Ok ( ( ) )
12071190
@@ -1218,8 +1201,11 @@ impl EmitterWriter {
12181201 let mut buffer = StyledBuffer :: new ( ) ;
12191202
12201203 // Render the suggestion message
1221- buffer. append ( 0 , & level. to_string ( ) , Style :: Level ( level. clone ( ) ) ) ;
1222- buffer. append ( 0 , ": " , Style :: HeaderMsg ) ;
1204+ let level_str = level. to_string ( ) ;
1205+ if !level_str. is_empty ( ) {
1206+ buffer. append ( 0 , & level_str, Style :: Level ( level. clone ( ) ) ) ;
1207+ buffer. append ( 0 , ": " , Style :: HeaderMsg ) ;
1208+ }
12231209 self . msg_to_buffer ( & mut buffer,
12241210 & [ ( suggestion. msg . to_owned ( ) , Style :: NoStyle ) ] ,
12251211 max_line_num_len,
@@ -1289,8 +1275,7 @@ impl EmitterWriter {
12891275 let msg = format ! ( "and {} other candidates" , suggestions. len( ) - MAX_SUGGESTIONS ) ;
12901276 buffer. puts ( row_num, 0 , & msg, Style :: NoStyle ) ;
12911277 }
1292- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ,
1293- & mut self . error_codes ) ?;
1278+ emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ) ?;
12941279 }
12951280 Ok ( ( ) )
12961281 }
@@ -1321,7 +1306,7 @@ impl EmitterWriter {
13211306 draw_col_separator_no_space ( & mut buffer, 0 , max_line_num_len + 1 ) ;
13221307 }
13231308 match emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ,
1324- self . short_message , & mut self . error_codes ) {
1309+ self . short_message ) {
13251310 Ok ( ( ) ) => ( ) ,
13261311 Err ( e) => panic ! ( "failed to emit error: {}" , e)
13271312 }
@@ -1416,8 +1401,7 @@ fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool {
14161401fn emit_to_destination ( rendered_buffer : & Vec < Vec < StyledString > > ,
14171402 lvl : & Level ,
14181403 dst : & mut Destination ,
1419- short_message : bool ,
1420- error_codes : & mut HashSet < String > )
1404+ short_message : bool )
14211405 -> io:: Result < ( ) > {
14221406 use lock;
14231407
@@ -1436,16 +1420,13 @@ fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
14361420 // same buffering approach. Instead, we use a global Windows mutex, which we acquire long
14371421 // enough to output the full error message, then we release.
14381422 let _buffer_lock = lock:: acquire_global_lock ( "rustc_errors" ) ;
1439- for line in rendered_buffer {
1423+ for ( pos , line) in rendered_buffer. iter ( ) . enumerate ( ) {
14401424 for part in line {
14411425 dst. apply_style ( lvl. clone ( ) , part. style ) ?;
14421426 write ! ( dst, "{}" , part. text) ?;
1443- if !short_message && part. text . len ( ) == 12 && part. text . starts_with ( "error[E" ) {
1444- error_codes. insert ( part. text [ 6 ..11 ] . to_owned ( ) ) ;
1445- }
14461427 dst. reset ( ) ?;
14471428 }
1448- if !short_message {
1429+ if !short_message && ( !lvl . is_failure_note ( ) || pos != rendered_buffer . len ( ) - 1 ) {
14491430 write ! ( dst, "\n " ) ?;
14501431 }
14511432 }
0 commit comments