diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2019-02-11 11:16:22 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2019-02-11 11:16:22 -0800 |
| commit | 87dd2e1df95f96dbf08a0f3ae77a2dcbd6d384e9 (patch) | |
| tree | 359b8c1ce7741448d2d33f09b0e6061d16e27a81 /src/librustc_errors | |
| parent | 235523c7d4acdbd38a6b31c53b7969475d460e97 (diff) | |
| download | rust-87dd2e1df95f96dbf08a0f3ae77a2dcbd6d384e9.tar.gz rust-87dd2e1df95f96dbf08a0f3ae77a2dcbd6d384e9.zip | |
Use hidden suggestions for unused imports lint
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/diagnostic.rs | 30 | ||||
| -rw-r--r-- | src/librustc_errors/diagnostic_builder.rs | 18 | ||||
| -rw-r--r-- | src/librustc_errors/emitter.rs | 4 |
3 files changed, 49 insertions, 3 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 588cdfcb1af..f0083949396 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -250,6 +250,32 @@ impl Diagnostic { self } + /// Prints out a message with for a multipart suggestion without showing the suggested code. + /// + /// This is intended to be used for suggestions that are obvious in what the changes need to + /// be from the message, showing the span label inline would be visually unpleasant + /// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't + /// improve understandability. + pub fn tool_only_multipart_suggestion( + &mut self, + msg: &str, + suggestion: Vec<(Span, String)>, + applicability: Applicability, + ) -> &mut Self { + self.suggestions.push(CodeSuggestion { + substitutions: vec![Substitution { + parts: suggestion + .into_iter() + .map(|(span, snippet)| SubstitutionPart { snippet, span }) + .collect(), + }], + msg: msg.to_owned(), + style: SuggestionStyle::CompletelyHidden, + applicability, + }); + self + } + /// Prints out a message with a suggested edit of the code. /// /// In case of short messages and a simple suggestion, rustc displays it as a label: @@ -318,7 +344,7 @@ impl Diagnostic { }], msg: msg.to_owned(), style: SuggestionStyle::HideCodeInline, - applicability: applicability, + applicability, }); self } @@ -341,7 +367,7 @@ impl Diagnostic { }], msg: msg.to_owned(), style: SuggestionStyle::HideCodeInline, - applicability: applicability, + applicability, }); self } diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 9f838987f0c..4ed7b0a2456 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -205,6 +205,24 @@ impl<'a> DiagnosticBuilder<'a> { self } + pub fn tool_only_multipart_suggestion( + &mut self, + msg: &str, + suggestion: Vec<(Span, String)>, + applicability: Applicability, + ) -> &mut Self { + if !self.allow_suggestions { + return self + } + self.diagnostic.tool_only_multipart_suggestion( + msg, + suggestion, + applicability, + ); + self + } + + pub fn span_suggestion( &mut self, sp: Span, diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 5e7c5315d68..eaae1e9e848 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -48,7 +48,9 @@ impl Emitter for EmitterWriter { // 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 + sugg.style != SuggestionStyle::HideCodeAlways && + // trivial suggestion for tooling's sake, never shown + sugg.style != SuggestionStyle::CompletelyHidden { let substitution = &sugg.substitutions[0].parts[0].snippet.trim(); let msg = if substitution.len() == 0 || sugg.style.hide_inline() { |
