diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-07-11 22:39:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-11 22:39:05 +0200 |
| commit | d89c18355455ec1542b1ee78f684cd4baed663e7 (patch) | |
| tree | 749017c866db634adedd29b0d636c44c1402af64 /compiler/rustc_errors/src | |
| parent | c431e6f15a5446620c199070b7decf5e935f33bb (diff) | |
| parent | f0a99f9036ff3038ca5a4a7d317fb98a2e9a87ce (diff) | |
| download | rust-d89c18355455ec1542b1ee78f684cd4baed663e7.tar.gz rust-d89c18355455ec1542b1ee78f684cd4baed663e7.zip | |
Rollup merge of #99075 - danobi:dup_type_hint_sugg, r=petrochenkov
Fix duplicated type annotation suggestion Before, there was more or less duplicated suggestions to add type hints. Fix by clearing more generic suggestions when a more specific suggestion is possible. This fixes #93506 .
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_builder.rs | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 9429ad1a897..da321c45875 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -614,6 +614,14 @@ impl Diagnostic { self } + /// Clear any existing suggestions. + pub fn clear_suggestions(&mut self) -> &mut Self { + if let Ok(suggestions) = &mut self.suggestions { + suggestions.clear(); + } + self + } + /// Helper for pushing to `self.suggestions`, if available (not disable). fn push_suggestion(&mut self, suggestion: CodeSuggestion) { if let Ok(suggestions) = &mut self.suggestions { diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index c3341fd68f4..99ac6a3546e 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -461,6 +461,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { forward!(pub fn set_is_lint(&mut self,) -> &mut Self); forward!(pub fn disable_suggestions(&mut self,) -> &mut Self); + forward!(pub fn clear_suggestions(&mut self,) -> &mut Self); forward!(pub fn multipart_suggestion( &mut self, |
