Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 4, 2019
1 parent 02f57f8 commit 76456e7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
84 changes: 43 additions & 41 deletions src/librustc_errors/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -313,7 +331,7 @@ impl Diagnostic {
}],
}],
msg: msg.to_owned(),
style: SuggestionStyle::ShowCode,
style,
applicability,
});
self
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
14 changes: 8 additions & 6 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 76456e7

Please sign in to comment.