diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index f9b5ff8e2ab..55b15925bf7 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -535,6 +535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { report_candidates(span, &mut err, static_sources, sugg_span); } + let mut restrict_type_params = false; if !unsatisfied_predicates.is_empty() { let def_span = |def_id| self.tcx.sess.source_map().def_span(self.tcx.def_span(def_id)); @@ -647,6 +648,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .enumerate() .collect::>(); for ((span, empty_where), obligations) in type_params.into_iter() { + restrict_type_params = true; err.span_suggestion_verbose( span, &format!( @@ -685,7 +687,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - if actual.is_numeric() && actual.is_fresh() { + if actual.is_numeric() && actual.is_fresh() || restrict_type_params { } else { self.suggest_traits_to_import( &mut err, diff --git a/src/test/ui/suggestions/missing-trait-bounds-for-method-call.stderr b/src/test/ui/suggestions/missing-trait-bounds-for-method-call.stderr index 1692af351f9..a9b57cfc0bd 100644 --- a/src/test/ui/suggestions/missing-trait-bounds-for-method-call.stderr +++ b/src/test/ui/suggestions/missing-trait-bounds-for-method-call.stderr @@ -12,12 +12,6 @@ LL | self.foo(); which is required by `Foo: Bar` `T: std::default::Default` which is required by `Foo: Bar` - = help: items from traits can only be used if the trait is implemented and in scope -note: `Bar` defines an item `foo`, perhaps you need to implement it - --> $DIR/missing-trait-bounds-for-method-call.rs:6:1 - | -LL | trait Bar { - | ^^^^^^^^^ help: consider restricting the type parameters to satisfy the obligations | LL | struct Foo where T: Bar, T: std::default::Default { @@ -35,12 +29,6 @@ LL | self.foo(); = note: the method `foo` exists but the following trait bounds were not satisfied: `T: std::default::Default` which is required by `Fin: Bar` - = help: items from traits can only be used if the trait is implemented and in scope -note: `Bar` defines an item `foo`, perhaps you need to implement it - --> $DIR/missing-trait-bounds-for-method-call.rs:6:1 - | -LL | trait Bar { - | ^^^^^^^^^ help: consider restricting the type parameter to satisfy the obligation | LL | struct Fin where T: Bar, T: std::default::Default {