diff options
| author | bors <bors@rust-lang.org> | 2018-02-01 04:47:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-02-01 04:47:46 +0000 |
| commit | 26792f0607bea2b03daa5195c2688fd53289042b (patch) | |
| tree | 35a3660501f3d9c285d4fbfcdf2efd01777574a5 /src/librustc_errors | |
| parent | 8ccab7eed5f4fc93500fbf242e575073ca70d7cb (diff) | |
| parent | 540f95d9fad41a605e4c8b898d77f47374a76cbd (diff) | |
| download | rust-26792f0607bea2b03daa5195c2688fd53289042b.tar.gz rust-26792f0607bea2b03daa5195c2688fd53289042b.zip | |
Auto merge of #47540 - Manishearth:suggestion, r=nrc
Add approximate suggestions for rustfix This adds `span_approximate_suggestion()` that lets you emit a suggestion marked as "non-machine applicable" in the JSON output. UI users see no difference. This is for when rustc and clippy wish to emit suggestions which will make sense to the reader (e.g. they may have placeholders like `<type>`) but are not source-applicable, so that rustfix/etc can ignore these. fixes #39254
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/diagnostic.rs | 37 | ||||
| -rw-r--r-- | src/librustc_errors/diagnostic_builder.rs | 10 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 6 |
3 files changed, 53 insertions, 0 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 2e654fe9929..40e4efb397d 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -222,6 +222,7 @@ impl Diagnostic { }], msg: msg.to_owned(), show_code_when_inline: false, + approximate: false, }); self } @@ -252,6 +253,7 @@ impl Diagnostic { }], msg: msg.to_owned(), show_code_when_inline: true, + approximate: false, }); self } @@ -267,6 +269,41 @@ impl Diagnostic { }).collect(), msg: msg.to_owned(), show_code_when_inline: true, + approximate: false, + }); + self + } + + /// This is a suggestion that may contain mistakes or fillers and should + /// be read and understood by a human. + pub fn span_approximate_suggestion(&mut self, sp: Span, msg: &str, + suggestion: String) -> &mut Self { + self.suggestions.push(CodeSuggestion { + substitutions: vec![Substitution { + parts: vec![SubstitutionPart { + snippet: suggestion, + span: sp, + }], + }], + msg: msg.to_owned(), + show_code_when_inline: true, + approximate: true, + }); + self + } + + pub fn span_approximate_suggestions(&mut self, sp: Span, msg: &str, + suggestions: Vec<String>) -> &mut Self { + self.suggestions.push(CodeSuggestion { + substitutions: suggestions.into_iter().map(|snippet| Substitution { + parts: vec![SubstitutionPart { + snippet, + span: sp, + }], + }).collect(), + msg: msg.to_owned(), + show_code_when_inline: true, + approximate: true, }); self } diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 61674ada6fa..2536fc648c7 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -186,6 +186,16 @@ impl<'a> DiagnosticBuilder<'a> { msg: &str, suggestions: Vec<String>) -> &mut Self); + forward!(pub fn span_approximate_suggestion(&mut self, + sp: Span, + msg: &str, + suggestion: String) + -> &mut Self); + forward!(pub fn span_approximate_suggestions(&mut self, + sp: Span, + msg: &str, + suggestions: Vec<String>) + -> &mut Self); forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self); forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self); diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 47eb04621a1..236698ed2d4 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -83,6 +83,12 @@ pub struct CodeSuggestion { pub substitutions: Vec<Substitution>, pub msg: String, pub show_code_when_inline: bool, + /// Whether or not the suggestion is approximate + /// + /// Sometimes we may show suggestions with placeholders, + /// which are useful for users but not useful for + /// tools like rustfix + pub approximate: bool, } #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] |
