Skip to content

Commit c02de78

Browse files
committed
Reduce verbosity when suggesting restricting type params
1 parent a66599f commit c02de78

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

src/librustc_typeck/check/method/suggest.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
535535
report_candidates(span, &mut err, static_sources, sugg_span);
536536
}
537537

538+
let mut restrict_type_params = false;
538539
if !unsatisfied_predicates.is_empty() {
539540
let def_span =
540541
|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> {
647648
.enumerate()
648649
.collect::<Vec<(usize, String)>>();
649650
for ((span, empty_where), obligations) in type_params.into_iter() {
651+
restrict_type_params = true;
650652
err.span_suggestion_verbose(
651653
span,
652654
&format!(
@@ -685,7 +687,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
685687
}
686688
}
687689

688-
if actual.is_numeric() && actual.is_fresh() {
690+
if actual.is_numeric() && actual.is_fresh() || restrict_type_params {
689691
} else {
690692
self.suggest_traits_to_import(
691693
&mut err,

src/test/ui/suggestions/missing-trait-bounds-for-method-call.stderr

-12
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ LL | self.foo();
1212
which is required by `Foo<T>: Bar`
1313
`T: std::default::Default`
1414
which is required by `Foo<T>: Bar`
15-
= help: items from traits can only be used if the trait is implemented and in scope
16-
note: `Bar` defines an item `foo`, perhaps you need to implement it
17-
--> $DIR/missing-trait-bounds-for-method-call.rs:6:1
18-
|
19-
LL | trait Bar {
20-
| ^^^^^^^^^
2115
help: consider restricting the type parameters to satisfy the obligations
2216
|
2317
LL | struct Foo<T> where T: Bar, T: std::default::Default {
@@ -35,12 +29,6 @@ LL | self.foo();
3529
= note: the method `foo` exists but the following trait bounds were not satisfied:
3630
`T: std::default::Default`
3731
which is required by `Fin<T>: Bar`
38-
= help: items from traits can only be used if the trait is implemented and in scope
39-
note: `Bar` defines an item `foo`, perhaps you need to implement it
40-
--> $DIR/missing-trait-bounds-for-method-call.rs:6:1
41-
|
42-
LL | trait Bar {
43-
| ^^^^^^^^^
4432
help: consider restricting the type parameter to satisfy the obligation
4533
|
4634
LL | struct Fin<T> where T: Bar, T: std::default::Default {

0 commit comments

Comments
 (0)