@@ -2,7 +2,10 @@ use Destination::*;
2
2
3
3
use syntax_pos:: { SourceFile , Span , MultiSpan } ;
4
4
5
- use crate :: { Level , CodeSuggestion , DiagnosticBuilder , SubDiagnostic , SourceMapperDyn , DiagnosticId } ;
5
+ use crate :: {
6
+ Level , CodeSuggestion , DiagnosticBuilder , SubDiagnostic ,
7
+ SuggestionStyle , SourceMapperDyn , DiagnosticId ,
8
+ } ;
6
9
use crate :: snippet:: { Annotation , AnnotationType , Line , MultilineAnnotation , StyledString , Style } ;
7
10
use crate :: styled_buffer:: StyledBuffer ;
8
11
@@ -45,7 +48,7 @@ impl Emitter for EmitterWriter {
45
48
// don't display multiline suggestions as labels
46
49
!sugg. substitutions [ 0 ] . parts [ 0 ] . snippet . contains ( '\n' ) {
47
50
let substitution = & sugg. substitutions [ 0 ] . parts [ 0 ] . snippet . trim ( ) ;
48
- let msg = if substitution. len ( ) == 0 || ! sugg. show_code_when_inline {
51
+ let msg = if substitution. len ( ) == 0 || sugg. style . hide_inline ( ) {
49
52
// This substitution is only removal or we explicitly don't want to show the
50
53
// code inline, don't show it
51
54
format ! ( "help: {}" , sugg. msg)
@@ -942,14 +945,15 @@ impl EmitterWriter {
942
945
}
943
946
}
944
947
945
- fn emit_message_default ( & mut self ,
946
- msp : & MultiSpan ,
947
- msg : & [ ( String , Style ) ] ,
948
- code : & Option < DiagnosticId > ,
949
- level : & Level ,
950
- max_line_num_len : usize ,
951
- is_secondary : bool )
952
- -> io:: Result < ( ) > {
948
+ fn emit_message_default (
949
+ & mut self ,
950
+ msp : & MultiSpan ,
951
+ msg : & [ ( String , Style ) ] ,
952
+ code : & Option < DiagnosticId > ,
953
+ level : & Level ,
954
+ max_line_num_len : usize ,
955
+ is_secondary : bool ,
956
+ ) -> io:: Result < ( ) > {
953
957
let mut buffer = StyledBuffer :: new ( ) ;
954
958
let header_style = if is_secondary {
955
959
Style :: HeaderMsg
@@ -1184,11 +1188,12 @@ impl EmitterWriter {
1184
1188
1185
1189
}
1186
1190
1187
- fn emit_suggestion_default ( & mut self ,
1188
- suggestion : & CodeSuggestion ,
1189
- level : & Level ,
1190
- max_line_num_len : usize )
1191
- -> io:: Result < ( ) > {
1191
+ fn emit_suggestion_default (
1192
+ & mut self ,
1193
+ suggestion : & CodeSuggestion ,
1194
+ level : & Level ,
1195
+ max_line_num_len : usize ,
1196
+ ) -> io:: Result < ( ) > {
1192
1197
if let Some ( ref sm) = self . sm {
1193
1198
let mut buffer = StyledBuffer :: new ( ) ;
1194
1199
@@ -1198,11 +1203,13 @@ impl EmitterWriter {
1198
1203
buffer. append ( 0 , & level_str, Style :: Level ( level. clone ( ) ) ) ;
1199
1204
buffer. append ( 0 , ": " , Style :: HeaderMsg ) ;
1200
1205
}
1201
- self . msg_to_buffer ( & mut buffer,
1202
- & [ ( suggestion. msg . to_owned ( ) , Style :: NoStyle ) ] ,
1203
- max_line_num_len,
1204
- "suggestion" ,
1205
- Some ( Style :: HeaderMsg ) ) ;
1206
+ self . msg_to_buffer (
1207
+ & mut buffer,
1208
+ & [ ( suggestion. msg . to_owned ( ) , Style :: NoStyle ) ] ,
1209
+ max_line_num_len,
1210
+ "suggestion" ,
1211
+ Some ( Style :: HeaderMsg ) ,
1212
+ ) ;
1206
1213
1207
1214
// Render the replacements for each suggestion
1208
1215
let suggestions = suggestion. splice_lines ( & * * sm) ;
@@ -1340,22 +1347,40 @@ impl EmitterWriter {
1340
1347
if !self . short_message {
1341
1348
for child in children {
1342
1349
let span = child. render_span . as_ref ( ) . unwrap_or ( & child. span ) ;
1343
- match self . emit_message_default ( & span,
1344
- & child. styled_message ( ) ,
1345
- & None ,
1346
- & child. level ,
1347
- max_line_num_len,
1348
- true ) {
1350
+ match self . emit_message_default (
1351
+ & span,
1352
+ & child. styled_message ( ) ,
1353
+ & None ,
1354
+ & child. level ,
1355
+ max_line_num_len,
1356
+ true ,
1357
+ ) {
1349
1358
Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
1350
1359
_ => ( )
1351
1360
}
1352
1361
}
1353
1362
for sugg in suggestions {
1354
- match self . emit_suggestion_default ( sugg,
1355
- & Level :: Help ,
1356
- max_line_num_len) {
1357
- Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
1358
- _ => ( )
1363
+ if sugg. style == SuggestionStyle :: HideCodeAlways {
1364
+ match self . emit_message_default (
1365
+ & MultiSpan :: new ( ) ,
1366
+ & [ ( sugg. msg . to_owned ( ) , Style :: HeaderMsg ) ] ,
1367
+ & None ,
1368
+ & Level :: Help ,
1369
+ max_line_num_len,
1370
+ true ,
1371
+ ) {
1372
+ Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
1373
+ _ => ( )
1374
+ }
1375
+ } else {
1376
+ match self . emit_suggestion_default (
1377
+ sugg,
1378
+ & Level :: Help ,
1379
+ max_line_num_len,
1380
+ ) {
1381
+ Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
1382
+ _ => ( )
1383
+ }
1359
1384
}
1360
1385
}
1361
1386
}
0 commit comments