diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-10-26 11:29:53 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-26 11:29:53 +0530 |
| commit | f2c2e582bdb8ca9d1a09643d516e22b6d3406581 (patch) | |
| tree | 33d4fb962cf57a3ad0c83a8caf55d1e74730f336 /compiler/rustc_errors | |
| parent | bf6bfcddf6bf9774022001d5a5d1f859d39a0a8a (diff) | |
| parent | 8bc43f99e91a94868fe08bb72b7ce66d7656d0b5 (diff) | |
| download | rust-f2c2e582bdb8ca9d1a09643d516e22b6d3406581.tar.gz rust-f2c2e582bdb8ca9d1a09643d516e22b6d3406581.zip | |
Rollup merge of #103209 - Xiretza:multiple-suggestions, r=davidtwco
Diagnostic derives: allow specifying multiple alternative suggestions This allows porting `span_suggestions()` to diagnostic structs. Doesn't work for `multipart_suggestions()` because the rank would be reversed - the struct would specify multiple spans, each of which has multiple possible replacements, while `multipart_suggestions()` creates multiple possible replacements, each with multiple spans.
Diffstat (limited to 'compiler/rustc_errors')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index a63fc0ca285..23f29a24fe7 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -691,6 +691,24 @@ impl Diagnostic { suggestions: impl Iterator<Item = String>, applicability: Applicability, ) -> &mut Self { + self.span_suggestions_with_style( + sp, + msg, + suggestions, + applicability, + SuggestionStyle::ShowCode, + ) + } + + /// [`Diagnostic::span_suggestions()`] but you can set the [`SuggestionStyle`]. + pub fn span_suggestions_with_style( + &mut self, + sp: Span, + msg: impl Into<SubdiagnosticMessage>, + suggestions: impl Iterator<Item = String>, + applicability: Applicability, + style: SuggestionStyle, + ) -> &mut Self { let mut suggestions: Vec<_> = suggestions.collect(); suggestions.sort(); @@ -706,14 +724,15 @@ impl Diagnostic { self.push_suggestion(CodeSuggestion { substitutions, msg: self.subdiagnostic_message_to_diagnostic_message(msg), - style: SuggestionStyle::ShowCode, + style, applicability, }); self } - /// Prints out a message with multiple suggested edits of the code. - /// See also [`Diagnostic::span_suggestion()`]. + /// Prints out a message with multiple suggested edits of the code, where each edit consists of + /// multiple parts. + /// See also [`Diagnostic::multipart_suggestion()`]. pub fn multipart_suggestions( &mut self, msg: impl Into<SubdiagnosticMessage>, @@ -745,6 +764,7 @@ impl Diagnostic { }); 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. /// |
