Skip to content

Commit 76456e7

Browse files
committed
review comments
1 parent 02f57f8 commit 76456e7

File tree

2 files changed

+51
-47
lines changed

2 files changed

+51
-47
lines changed

Diff for: src/librustc_errors/diagnostic.rs

+43-41
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,24 @@ impl Diagnostic {
304304
msg: &str,
305305
suggestion: String,
306306
applicability: Applicability,
307+
) -> &mut Self {
308+
self.span_suggestion_with_style(
309+
sp,
310+
msg,
311+
suggestion,
312+
applicability,
313+
SuggestionStyle::ShowCode,
314+
);
315+
self
316+
}
317+
318+
pub fn span_suggestion_with_style(
319+
&mut self,
320+
sp: Span,
321+
msg: &str,
322+
suggestion: String,
323+
applicability: Applicability,
324+
style: SuggestionStyle,
307325
) -> &mut Self {
308326
self.suggestions.push(CodeSuggestion {
309327
substitutions: vec![Substitution {
@@ -313,7 +331,7 @@ impl Diagnostic {
313331
}],
314332
}],
315333
msg: msg.to_owned(),
316-
style: SuggestionStyle::ShowCode,
334+
style,
317335
applicability,
318336
});
319337
self
@@ -326,17 +344,13 @@ impl Diagnostic {
326344
suggestion: String,
327345
applicability: Applicability,
328346
) -> &mut Self {
329-
self.suggestions.push(CodeSuggestion {
330-
substitutions: vec![Substitution {
331-
parts: vec![SubstitutionPart {
332-
snippet: suggestion,
333-
span: sp,
334-
}],
335-
}],
336-
msg: msg.to_owned(),
337-
style: SuggestionStyle::ShowAlways,
347+
self.span_suggestion_with_style(
348+
sp,
349+
msg,
350+
suggestion,
338351
applicability,
339-
});
352+
SuggestionStyle::ShowAlways,
353+
);
340354
self
341355
}
342356

@@ -369,17 +383,13 @@ impl Diagnostic {
369383
pub fn span_suggestion_short(
370384
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
371385
) -> &mut Self {
372-
self.suggestions.push(CodeSuggestion {
373-
substitutions: vec![Substitution {
374-
parts: vec![SubstitutionPart {
375-
snippet: suggestion,
376-
span: sp,
377-
}],
378-
}],
379-
msg: msg.to_owned(),
380-
style: SuggestionStyle::HideCodeInline,
386+
self.span_suggestion_with_style(
387+
sp,
388+
msg,
389+
suggestion,
381390
applicability,
382-
});
391+
SuggestionStyle::HideCodeInline,
392+
);
383393
self
384394
}
385395

@@ -392,17 +402,13 @@ impl Diagnostic {
392402
pub fn span_suggestion_hidden(
393403
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
394404
) -> &mut Self {
395-
self.suggestions.push(CodeSuggestion {
396-
substitutions: vec![Substitution {
397-
parts: vec![SubstitutionPart {
398-
snippet: suggestion,
399-
span: sp,
400-
}],
401-
}],
402-
msg: msg.to_owned(),
403-
style: SuggestionStyle::HideCodeAlways,
405+
self.span_suggestion_with_style(
406+
sp,
407+
msg,
408+
suggestion,
404409
applicability,
405-
});
410+
SuggestionStyle::HideCodeAlways,
411+
);
406412
self
407413
}
408414

@@ -413,17 +419,13 @@ impl Diagnostic {
413419
pub fn tool_only_span_suggestion(
414420
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
415421
) -> &mut Self {
416-
self.suggestions.push(CodeSuggestion {
417-
substitutions: vec![Substitution {
418-
parts: vec![SubstitutionPart {
419-
snippet: suggestion,
420-
span: sp,
421-
}],
422-
}],
423-
msg: msg.to_owned(),
424-
style: SuggestionStyle::CompletelyHidden,
422+
self.span_suggestion_with_style(
423+
sp,
424+
msg,
425+
suggestion,
425426
applicability,
426-
});
427+
SuggestionStyle::CompletelyHidden,
428+
);
427429
self
428430
}
429431

Diff for: src/librustc_errors/emitter.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,14 @@ pub trait Emitter {
218218
sugg.msg.split_whitespace().count() < 10 &&
219219
// don't display multiline suggestions as labels
220220
!sugg.substitutions[0].parts[0].snippet.contains('\n') &&
221-
// when this style is set we want the suggestion to be a message, not inline
222-
sugg.style != SuggestionStyle::HideCodeAlways &&
223-
// trivial suggestion for tooling's sake, never shown
224-
sugg.style != SuggestionStyle::CompletelyHidden &&
225-
// subtle suggestion, never shown inline
226-
sugg.style != SuggestionStyle::ShowAlways
221+
![
222+
// when this style is set we want the suggestion to be a message, not inline
223+
SuggestionStyle::HideCodeAlways,
224+
// trivial suggestion for tooling's sake, never shown
225+
SuggestionStyle::CompletelyHidden,
226+
// subtle suggestion, never shown inline
227+
SuggestionStyle::ShowAlways,
228+
].contains(&sugg.style)
227229
{
228230
let substitution = &sugg.substitutions[0].parts[0].snippet.trim();
229231
let msg = if substitution.len() == 0 || sugg.style.hide_inline() {

0 commit comments

Comments
 (0)