Reduce verbosity when suggesting restricting type params

This commit is contained in:
Esteban Küber 2020-02-24 23:25:54 -08:00
parent c764a82310
commit a29f6916d8
2 changed files with 3 additions and 13 deletions

View File

@ -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::<Vec<(usize, String)>>();
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,

View File

@ -12,12 +12,6 @@ LL | self.foo();
which is required by `Foo<T>: Bar`
`T: std::default::Default`
which is required by `Foo<T>: 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<T> 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<T>: 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<T> where T: Bar, T: std::default::Default {