diff options
| author | Ralf Jung <post@ralfj.de> | 2020-06-15 12:00:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-15 12:00:59 +0200 |
| commit | d97e8ca33524399620aef1c0053f8b593bfbf521 (patch) | |
| tree | be3ee681901ecf70fde8aebece3212c2e7d43241 /src/librustc_errors | |
| parent | eef9356e39d58800e77727a9045b8326a5fb20e5 (diff) | |
| parent | 03552ec3fa4828329874a17d1b8966a0c03809d8 (diff) | |
Rollup merge of #72740 - estebank:recursive-indirection, r=matthewjasper
On recursive ADT, provide indirection structured suggestion
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/diagnostic.rs | 23 | ||||
| -rw-r--r-- | src/librustc_errors/diagnostic_builder.rs | 13 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index cff83c3d5cd..acaa26c6ad2 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -296,6 +296,29 @@ impl Diagnostic { self } + pub fn multipart_suggestions( + &mut self, + msg: &str, + suggestions: Vec<Vec<(Span, String)>>, + applicability: Applicability, + ) -> &mut Self { + self.suggestions.push(CodeSuggestion { + substitutions: suggestions + .into_iter() + .map(|suggestion| Substitution { + parts: suggestion + .into_iter() + .map(|(span, snippet)| SubstitutionPart { snippet, span }) + .collect(), + }) + .collect(), + msg: msg.to_owned(), + style: SuggestionStyle::ShowCode, + applicability, + }); + 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 diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 2dbd9f4e52f..22bf8fe34aa 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -260,6 +260,19 @@ impl<'a> DiagnosticBuilder<'a> { self } + pub fn multipart_suggestions( + &mut self, + msg: &str, + suggestions: Vec<Vec<(Span, String)>>, + applicability: Applicability, + ) -> &mut Self { + if !self.0.allow_suggestions { + return self; + } + self.0.diagnostic.multipart_suggestions(msg, suggestions, applicability); + self + } + pub fn tool_only_multipart_suggestion( &mut self, msg: &str, |
