@@ -13,7 +13,6 @@ use self::Destination::*;
1313use syntax_pos:: { DUMMY_SP , FileMap , Span , MultiSpan } ;
1414
1515use { Level , CodeSuggestion , DiagnosticBuilder , SubDiagnostic , CodeMapper , DiagnosticId } ;
16- use RenderSpan :: * ;
1716use snippet:: { Annotation , AnnotationType , Line , MultilineAnnotation , StyledString , Style } ;
1817use styled_buffer:: StyledBuffer ;
1918
@@ -35,6 +34,7 @@ impl Emitter for EmitterWriter {
3534 fn emit ( & mut self , db : & DiagnosticBuilder ) {
3635 let mut primary_span = db. span . clone ( ) ;
3736 let mut children = db. children . clone ( ) ;
37+ let mut suggestions: & [ _ ] = & [ ] ;
3838
3939 if let Some ( ( sugg, rest) ) = db. suggestions . split_first ( ) {
4040 if rest. is_empty ( ) &&
@@ -60,14 +60,7 @@ impl Emitter for EmitterWriter {
6060 // to be consistent. We could try to figure out if we can
6161 // make one (or the first one) inline, but that would give
6262 // undue importance to a semi-random suggestion
63- for sugg in & db. suggestions {
64- children. push ( SubDiagnostic {
65- level : Level :: Help ,
66- message : Vec :: new ( ) ,
67- span : MultiSpan :: new ( ) ,
68- render_span : Some ( Suggestion ( sugg. clone ( ) ) ) ,
69- } ) ;
70- }
63+ suggestions = & db. suggestions ;
7164 }
7265 }
7366
@@ -76,7 +69,8 @@ impl Emitter for EmitterWriter {
7669 & db. styled_message ( ) ,
7770 & db. code ,
7871 & primary_span,
79- & children) ;
72+ & children,
73+ & suggestions) ;
8074 }
8175}
8276
@@ -1179,7 +1173,8 @@ impl EmitterWriter {
11791173 message : & Vec < ( String , Style ) > ,
11801174 code : & Option < DiagnosticId > ,
11811175 span : & MultiSpan ,
1182- children : & Vec < SubDiagnostic > ) {
1176+ children : & Vec < SubDiagnostic > ,
1177+ suggestions : & [ CodeSuggestion ] ) {
11831178 let max_line_num = self . get_max_line_num ( span, children) ;
11841179 let max_line_num_len = max_line_num. to_string ( ) . len ( ) ;
11851180
@@ -1198,37 +1193,23 @@ impl EmitterWriter {
11981193 }
11991194 if !self . short_message {
12001195 for child in children {
1201- match child. render_span {
1202- Some ( FullSpan ( ref msp) ) => {
1203- match self . emit_message_default ( msp,
1204- & child. styled_message ( ) ,
1205- & None ,
1206- & child. level ,
1207- max_line_num_len,
1208- true ) {
1209- Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
1210- _ => ( )
1211- }
1212- }
1213- Some ( Suggestion ( ref cs) ) => {
1214- match self . emit_suggestion_default ( cs,
1215- & child. level ,
1216- max_line_num_len) {
1217- Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
1218- _ => ( )
1219- }
1220- }
1221- None => {
1222- match self . emit_message_default ( & child. span ,
1223- & child. styled_message ( ) ,
1224- & None ,
1225- & child. level ,
1226- max_line_num_len,
1227- true ) {
1228- Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
1229- _ => ( ) ,
1230- }
1231- }
1196+ let span = child. render_span . as_ref ( ) . unwrap_or ( & child. span ) ;
1197+ match self . emit_message_default ( & span,
1198+ & child. styled_message ( ) ,
1199+ & None ,
1200+ & child. level ,
1201+ max_line_num_len,
1202+ true ) {
1203+ Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
1204+ _ => ( )
1205+ }
1206+ }
1207+ for sugg in suggestions {
1208+ match self . emit_suggestion_default ( sugg,
1209+ & Level :: Help ,
1210+ max_line_num_len) {
1211+ Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
1212+ _ => ( )
12321213 }
12331214 }
12341215 }
0 commit comments