diff options
| author | Daniel Xu <dxu@dxuuu.xyz> | 2022-07-08 21:03:03 -0500 |
|---|---|---|
| committer | Daniel Xu <dxu@dxuuu.xyz> | 2022-07-08 21:03:03 -0500 |
| commit | 34e9e6dff1449bddd9a66e744423797e01aec43c (patch) | |
| tree | 3fa4ba6ab1c5b3b8f83b698e480fca9f29ff2dff /compiler/rustc_errors/src | |
| parent | 06754d8852bea286a3a76d373ccd17e66afb5a8b (diff) | |
| download | rust-34e9e6dff1449bddd9a66e744423797e01aec43c.tar.gz rust-34e9e6dff1449bddd9a66e744423797e01aec43c.zip | |
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, |
