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, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 34f4a9f7902..8d7c6b26ba1 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -2094,6 +2094,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { // | // = note: cannot satisfy `_: Tt` + // Clear any more general suggestions in favor of our specific one + err.clear_suggestions(); + err.span_suggestion_verbose( span.shrink_to_hi(), &format!( diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index 98c22af387e..e282884289d 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -411,7 +411,7 @@ LL | #[derive(SessionDiagnostic)] | = help: normalized in stderr note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg` - --> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:538:19 + --> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:539:19 | LL | arg: impl IntoDiagnosticArg, | ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` diff --git a/src/test/ui/inference/erase-type-params-in-label.stderr b/src/test/ui/inference/erase-type-params-in-label.stderr index 7bb281802d2..5c52e7bcfab 100644 --- a/src/test/ui/inference/erase-type-params-in-label.stderr +++ b/src/test/ui/inference/erase-type-params-in-label.stderr @@ -10,10 +10,6 @@ note: required by a bound in `foo` | LL | fn foo(t: T, k: K) -> Foo { | ^^^^^^^ required by this bound in `foo` -help: consider giving `foo` an explicit type, where the type for type parameter `W` is specified - | -LL | let foo: Foo = foo(1, ""); - | ++++++++++++++++++++++ help: consider specifying the type arguments in the function call | LL | let foo = foo::(1, ""); @@ -31,10 +27,6 @@ note: required by a bound in `bar` | LL | fn bar(t: T, k: K) -> Bar { | ^^^^^^^ required by this bound in `bar` -help: consider giving `bar` an explicit type, where the type for type parameter `Z` is specified - | -LL | let bar: Bar = bar(1, ""); - | +++++++++++++++++++ help: consider specifying the type arguments in the function call | LL | let bar = bar::(1, ""); diff --git a/src/test/ui/inference/issue-71732.stderr b/src/test/ui/inference/issue-71732.stderr index db153d38aaa..04673a375cf 100644 --- a/src/test/ui/inference/issue-71732.stderr +++ b/src/test/ui/inference/issue-71732.stderr @@ -13,10 +13,6 @@ note: required by a bound in `HashMap::::get` | LL | K: Borrow, | ^^^^^^^^^ required by this bound in `HashMap::::get` -help: consider specifying the generic argument - | -LL | .get::(&"key".into()) - | +++++ help: consider specifying the type argument in the function call | LL | .get::(&"key".into()) diff --git a/src/test/ui/traits/issue-77982.stderr b/src/test/ui/traits/issue-77982.stderr index a2d23c4e9df..2b832e27c52 100644 --- a/src/test/ui/traits/issue-77982.stderr +++ b/src/test/ui/traits/issue-77982.stderr @@ -13,10 +13,6 @@ note: required by a bound in `HashMap::::get` | LL | K: Borrow, | ^^^^^^^^^ required by this bound in `HashMap::::get` -help: consider specifying the generic argument - | -LL | opts.get::(opt.as_ref()); - | +++++ help: consider specifying the type argument in the function call | LL | opts.get::(opt.as_ref()); diff --git a/src/test/ui/traits/multidispatch-convert-ambig-dest.stderr b/src/test/ui/traits/multidispatch-convert-ambig-dest.stderr index 25f8d538377..cbec3593421 100644 --- a/src/test/ui/traits/multidispatch-convert-ambig-dest.stderr +++ b/src/test/ui/traits/multidispatch-convert-ambig-dest.stderr @@ -30,10 +30,6 @@ LL | fn test(_: T, _: U) | ---- required by a bound in this LL | where T : Convert | ^^^^^^^^^^ required by this bound in `test` -help: consider specifying the generic arguments - | -LL | test::(22, std::default::Default::default()); - | ++++++++++ help: consider specifying the type arguments in the function call | LL | test::(22, std::default::Default::default()); diff --git a/src/test/ui/type/type-annotation-needed.stderr b/src/test/ui/type/type-annotation-needed.stderr index 7d7890c8b80..4af4c22f751 100644 --- a/src/test/ui/type/type-annotation-needed.stderr +++ b/src/test/ui/type/type-annotation-needed.stderr @@ -10,10 +10,6 @@ note: required by a bound in `foo` | LL | fn foo>(x: i32) {} | ^^^^^^^^^^^^ required by this bound in `foo` -help: consider specifying the generic argument - | -LL | foo::(42); - | +++++ help: consider specifying the type argument in the function call | LL | foo::(42);