diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2021-06-28 11:22:47 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2021-07-30 09:26:31 -0700 |
| commit | 0b8f192cfee2f107867e7b9a0b0f781a5cb48787 (patch) | |
| tree | 7740090507212c2bf5f630672125bab43d68d093 /compiler/rustc_errors | |
| parent | 5fb3394cbdf0622c9d0c292feb55db0f4c828dc3 (diff) | |
| download | rust-0b8f192cfee2f107867e7b9a0b0f781a5cb48787.tar.gz rust-0b8f192cfee2f107867e7b9a0b0f781a5cb48787.zip | |
Use multispan suggestions more often
* Use more accurate span for `async move` suggestion * Use more accurate span for deref suggestion * Use `multipart_suggestion` more often
Diffstat (limited to 'compiler/rustc_errors')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_builder.rs | 14 |
2 files changed, 38 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 45661ac1562..8199c44ee2a 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -444,6 +444,30 @@ impl Diagnostic { self } + /// Prints out a message with multiple suggested edits of the code. + /// See also [`Diagnostic::span_suggestion()`]. + pub fn multipart_suggestions( + &mut self, + msg: &str, + suggestions: impl Iterator<Item = Vec<(Span, String)>>, + applicability: Applicability, + ) -> &mut Self { + self.suggestions.push(CodeSuggestion { + substitutions: suggestions + .map(|sugg| Substitution { + parts: sugg + .into_iter() + .map(|(span, snippet)| SubstitutionPart { snippet, span }) + .collect(), + }) + .collect(), + msg: msg.to_owned(), + style: SuggestionStyle::ShowCode, + applicability, + tool_metadata: Default::default(), + }); + self + } /// Prints out a message with a suggested edit of the code. If the suggestion is presented /// inline, it will only show the message and not the suggestion. /// diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 282877d5dd1..d35b2924803 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -301,6 +301,20 @@ impl<'a> DiagnosticBuilder<'a> { self } + /// See [`Diagnostic::multipart_suggestions()`]. + pub fn multipart_suggestions( + &mut self, + msg: &str, + suggestions: impl Iterator<Item = Vec<(Span, String)>>, + applicability: Applicability, + ) -> &mut Self { + if !self.0.allow_suggestions { + return self; + } + self.0.diagnostic.multipart_suggestions(msg, suggestions, applicability); + self + } + /// See [`Diagnostic::span_suggestion_short()`]. pub fn span_suggestion_short( &mut self, |
