Skip to content
Permalink
Browse files

review comments

  • Loading branch information...
estebank committed Oct 4, 2019
1 parent 02f57f8 commit 76456e74066d7594f23757ebade169c33276ea4d
Showing with 51 additions and 47 deletions.
  1. +43 −41 src/librustc_errors/diagnostic.rs
  2. +8 −6 src/librustc_errors/emitter.rs
@@ -304,6 +304,24 @@ impl Diagnostic {
msg: &str,
suggestion: String,
applicability: Applicability,
) -> &mut Self {
self.span_suggestion_with_style(
sp,
msg,
suggestion,
applicability,
SuggestionStyle::ShowCode,
);
self
}

pub fn span_suggestion_with_style(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability,
style: SuggestionStyle,
) -> &mut Self {
self.suggestions.push(CodeSuggestion {
substitutions: vec![Substitution {
@@ -313,7 +331,7 @@ impl Diagnostic {
}],
}],
msg: msg.to_owned(),
style: SuggestionStyle::ShowCode,
style,
applicability,
});
self
@@ -326,17 +344,13 @@ impl Diagnostic {
suggestion: String,
applicability: Applicability,
) -> &mut Self {
self.suggestions.push(CodeSuggestion {
substitutions: vec![Substitution {
parts: vec![SubstitutionPart {
snippet: suggestion,
span: sp,
}],
}],
msg: msg.to_owned(),
style: SuggestionStyle::ShowAlways,
self.span_suggestion_with_style(
sp,
msg,
suggestion,
applicability,
});
SuggestionStyle::ShowAlways,
);
self
}

@@ -369,17 +383,13 @@ impl Diagnostic {
pub fn span_suggestion_short(
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
) -> &mut Self {
self.suggestions.push(CodeSuggestion {
substitutions: vec![Substitution {
parts: vec![SubstitutionPart {
snippet: suggestion,
span: sp,
}],
}],
msg: msg.to_owned(),
style: SuggestionStyle::HideCodeInline,
self.span_suggestion_with_style(
sp,
msg,
suggestion,
applicability,
});
SuggestionStyle::HideCodeInline,
);
self
}

@@ -392,17 +402,13 @@ impl Diagnostic {
pub fn span_suggestion_hidden(
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
) -> &mut Self {
self.suggestions.push(CodeSuggestion {
substitutions: vec![Substitution {
parts: vec![SubstitutionPart {
snippet: suggestion,
span: sp,
}],
}],
msg: msg.to_owned(),
style: SuggestionStyle::HideCodeAlways,
self.span_suggestion_with_style(
sp,
msg,
suggestion,
applicability,
});
SuggestionStyle::HideCodeAlways,
);
self
}

@@ -413,17 +419,13 @@ impl Diagnostic {
pub fn tool_only_span_suggestion(
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
) -> &mut Self {
self.suggestions.push(CodeSuggestion {
substitutions: vec![Substitution {
parts: vec![SubstitutionPart {
snippet: suggestion,
span: sp,
}],
}],
msg: msg.to_owned(),
style: SuggestionStyle::CompletelyHidden,
self.span_suggestion_with_style(
sp,
msg,
suggestion,
applicability,
});
SuggestionStyle::CompletelyHidden,
);
self
}

@@ -218,12 +218,14 @@ pub trait Emitter {
sugg.msg.split_whitespace().count() < 10 &&
// don't display multiline suggestions as labels
!sugg.substitutions[0].parts[0].snippet.contains('\n') &&
// when this style is set we want the suggestion to be a message, not inline
sugg.style != SuggestionStyle::HideCodeAlways &&
// trivial suggestion for tooling's sake, never shown
sugg.style != SuggestionStyle::CompletelyHidden &&
// subtle suggestion, never shown inline
sugg.style != SuggestionStyle::ShowAlways
![
// when this style is set we want the suggestion to be a message, not inline
SuggestionStyle::HideCodeAlways,
// trivial suggestion for tooling's sake, never shown
SuggestionStyle::CompletelyHidden,
// subtle suggestion, never shown inline
SuggestionStyle::ShowAlways,
].contains(&sugg.style)
{
let substitution = &sugg.substitutions[0].parts[0].snippet.trim();
let msg = if substitution.len() == 0 || sugg.style.hide_inline() {

0 comments on commit 76456e7

Please sign in to comment.
You can’t perform that action at this time.