diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2020-02-18 02:13:30 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2020-02-28 11:37:59 -0800 |
| commit | ad4777dbca1d4d1b052db01b1191862c9fbbad64 (patch) | |
| tree | 399130954829f62afcb8578d8e6da0ae0a58ef5d | |
| parent | 8993b99ae28a1f8e3c11231a17e645feee66ea2f (diff) | |
| download | rust-ad4777dbca1d4d1b052db01b1191862c9fbbad64.tar.gz rust-ad4777dbca1d4d1b052db01b1191862c9fbbad64.zip | |
Deduplicate information in E0599
10 files changed, 46 insertions, 48 deletions
diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 3fa5d4baa76..8eb42f01984 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -538,16 +538,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut bound_spans = vec![]; let mut bound_list = unsatisfied_predicates .iter() - .map(|p| { + .filter_map(|p| { let self_ty = p.self_ty(); match &self_ty.kind { - ty::Adt(def, _) => bound_spans.push(( - self.tcx.sess.source_map().def_span(self.tcx.def_span(def.did)), - format!( - "this type doesn't satisfy the bound `{}`", - p.print_only_trait_path() - ), - )), + ty::Adt(def, _) => { + bound_spans.push(( + self.tcx + .sess + .source_map() + .def_span(self.tcx.def_span(def.did)), + format!( + "the method `{}` exists but this type doesn't satisfy \ + the bound `{}: {}`", + item_name, + p.self_ty(), + p.print_only_trait_path() + ), + )); + None + } ty::Dynamic(preds, _) => { for pred in *preds.skip_binder() { match pred { @@ -558,7 +567,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .source_map() .def_span(self.tcx.def_span(tr.def_id)), format!( - "this trait doesn't satisfy the bound `{}`", + "the method `{}` exists but this trait \ + doesn't satisfy the bound `{}: {}`", + item_name, + p.self_ty(), p.print_only_trait_path() ), )), @@ -566,10 +578,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ty::ExistentialPredicate::AutoTrait(_) => {} } } + None } - _ => {} - }; - format!("`{}: {}`", p.self_ty(), p.print_only_trait_path()) + _ => Some(format!( + "`{}: {}`", + p.self_ty(), + p.print_only_trait_path() + )), + } }) .collect::<Vec<_>>(); bound_list.sort(); @@ -579,12 +595,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for (span, msg) in bound_spans.into_iter() { err.span_label(span, &msg); } - let bound_list = bound_list.join("\n"); - err.note(&format!( - "the method `{}` exists but the following trait bounds were not \ - satisfied:\n{}", - item_name, bound_list - )); + if !bound_list.is_empty() { + let bound_list = bound_list.join("\n"); + err.note(&format!( + "the method `{}` exists but the following trait bounds were not \ + satisfied:\n{}", + item_name, bound_list + )); + } } if actual.is_numeric() && actual.is_fresh() { diff --git a/src/test/ui/derives/derive-assoc-type-not-impl.stderr b/src/test/ui/derives/derive-assoc-type-not-impl.stderr index 0b55b3f2ec9..fd74d992299 100644 --- a/src/test/ui/derives/derive-assoc-type-not-impl.stderr +++ b/src/test/ui/derives/derive-assoc-type-not-impl.stderr @@ -5,13 +5,11 @@ LL | struct Bar<T: Foo> { | ------------------ method `clone` not found for this ... LL | struct NotClone; - | ---------------- this type doesn't satisfy the bound `std::clone::Clone` + | ---------------- the method `clone` exists but this type doesn't satisfy the bound `NotClone: std::clone::Clone` ... LL | Bar::<NotClone> { x: 1 }.clone(); | ^^^^^ method not found in `Bar<NotClone>` | - = note: the method `clone` exists but the following trait bounds were not satisfied: - `NotClone: std::clone::Clone` = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `clone`, perhaps you need to implement it: candidate #1: `std::clone::Clone` diff --git a/src/test/ui/issues/issue-31173.stderr b/src/test/ui/issues/issue-31173.stderr index 28b3b872220..4a5940f610e 100644 --- a/src/test/ui/issues/issue-31173.stderr +++ b/src/test/ui/issues/issue-31173.stderr @@ -16,10 +16,7 @@ LL | .collect(); ::: $SRC_DIR/libcore/iter/adapters/mod.rs:LL:COL | LL | pub struct Cloned<I> { - | -------------------- this type doesn't satisfy the bound `std::iter::Iterator` - | - = note: the method `collect` exists but the following trait bounds were not satisfied: - `std::iter::Cloned<std::iter::TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:10:39: 13:6 found_e:_]>>: std::iter::Iterator` + | -------------------- the method `collect` exists but this type doesn't satisfy the bound `std::iter::Cloned<std::iter::TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:10:39: 13:6 found_e:_]>>: std::iter::Iterator` error: aborting due to 2 previous errors diff --git a/src/test/ui/methods/method-call-err-msg.stderr b/src/test/ui/methods/method-call-err-msg.stderr index 2b683f8aa2a..aa38e4da018 100644 --- a/src/test/ui/methods/method-call-err-msg.stderr +++ b/src/test/ui/methods/method-call-err-msg.stderr @@ -38,13 +38,11 @@ LL | pub struct Foo; | --------------- | | | method `take` not found for this - | this type doesn't satisfy the bound `std::iter::Iterator` + | the method `take` exists but this type doesn't satisfy the bound `Foo: std::iter::Iterator` ... LL | .take() | ^^^^ method not found in `Foo` | - = note: the method `take` exists but the following trait bounds were not satisfied: - `Foo: std::iter::Iterator` = help: items from traits can only be used if the trait is implemented and in scope = note: the following traits define an item `take`, perhaps you need to implement one of them: candidate #1: `std::io::Read` diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr index 98d71b460db..dc0bd310de8 100644 --- a/src/test/ui/mismatched_types/issue-36053-2.stderr +++ b/src/test/ui/mismatched_types/issue-36053-2.stderr @@ -7,11 +7,10 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); ::: $SRC_DIR/libcore/iter/adapters/mod.rs:LL:COL | LL | pub struct Filter<I, P> { - | ----------------------- this type doesn't satisfy the bound `std::iter::Iterator` + | ----------------------- the method `count` exists but this type doesn't satisfy the bound `std::iter::Filter<std::iter::Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:11:39: 11:53]>: std::iter::Iterator` | = note: the method `count` exists but the following trait bounds were not satisfied: `[closure@$DIR/issue-36053-2.rs:11:39: 11:53]: std::ops::FnMut<(&_,)>` - `std::iter::Filter<std::iter::Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:11:39: 11:53]>: std::iter::Iterator` error[E0631]: type mismatch in closure arguments --> $DIR/issue-36053-2.rs:11:32 diff --git a/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr b/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr index a7681f9af5b..e95141b393a 100644 --- a/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr +++ b/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr @@ -2,13 +2,10 @@ error[E0599]: no method named `unwrap` found for enum `std::result::Result<(), F --> $DIR/method-help-unsatisfied-bound.rs:5:7 | LL | struct Foo; - | ----------- this type doesn't satisfy the bound `std::fmt::Debug` + | ----------- the method `unwrap` exists but this type doesn't satisfy the bound `Foo: std::fmt::Debug` ... LL | a.unwrap(); | ^^^^^^ method not found in `std::result::Result<(), Foo>` - | - = note: the method `unwrap` exists but the following trait bounds were not satisfied: - `Foo: std::fmt::Debug` error: aborting due to previous error diff --git a/src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr b/src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr index ccbb2aae05d..2738bac8cc8 100644 --- a/src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr +++ b/src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr @@ -8,13 +8,11 @@ LL | struct MyStruct; | ---------------- | | | method `foo_one` not found for this - | this type doesn't satisfy the bound `Foo` + | the method `foo_one` exists but this type doesn't satisfy the bound `MyStruct: Foo` ... LL | println!("{}", MyStruct.foo_one()); | ^^^^^^^ method not found in `MyStruct` | - = note: the method `foo_one` exists but the following trait bounds were not satisfied: - `MyStruct: Foo` = help: items from traits can only be used if the trait is implemented and in scope error: aborting due to previous error diff --git a/src/test/ui/union/union-derive-clone.stderr b/src/test/ui/union/union-derive-clone.stderr index c8537afd3bd..c0d99c56cc0 100644 --- a/src/test/ui/union/union-derive-clone.stderr +++ b/src/test/ui/union/union-derive-clone.stderr @@ -14,13 +14,11 @@ LL | union U5<T> { | ----------- method `clone` not found for this ... LL | struct CloneNoCopy; - | ------------------- this type doesn't satisfy the bound `std::marker::Copy` + | ------------------- the method `clone` exists but this type doesn't satisfy the bound `CloneNoCopy: std::marker::Copy` ... LL | let w = u.clone(); | ^^^^^ method not found in `U5<CloneNoCopy>` | - = note: the method `clone` exists but the following trait bounds were not satisfied: - `CloneNoCopy: std::marker::Copy` = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `clone`, perhaps you need to implement it: candidate #1: `std::clone::Clone` diff --git a/src/test/ui/unique-object-noncopyable.stderr b/src/test/ui/unique-object-noncopyable.stderr index 1ada663129f..b786a3d6d86 100644 --- a/src/test/ui/unique-object-noncopyable.stderr +++ b/src/test/ui/unique-object-noncopyable.stderr @@ -4,15 +4,12 @@ error[E0599]: no method named `clone` found for struct `std::boxed::Box<dyn Foo> LL | trait Foo { | --------- | | - | this trait doesn't satisfy the bound `std::clone::Clone` - | this trait doesn't satisfy the bound `std::marker::Sized` + | the method `clone` exists but this trait doesn't satisfy the bound `dyn Foo: std::clone::Clone` + | the method `clone` exists but this trait doesn't satisfy the bound `dyn Foo: std::marker::Sized` ... LL | let _z = y.clone(); | ^^^^^ method not found in `std::boxed::Box<dyn Foo>` | - = note: the method `clone` exists but the following trait bounds were not satisfied: - `dyn Foo: std::clone::Clone` - `dyn Foo: std::marker::Sized` = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `clone`, perhaps you need to implement it: candidate #1: `std::clone::Clone` diff --git a/src/test/ui/unique-pinned-nocopy.stderr b/src/test/ui/unique-pinned-nocopy.stderr index 2557ea8acb8..26b82ecda48 100644 --- a/src/test/ui/unique-pinned-nocopy.stderr +++ b/src/test/ui/unique-pinned-nocopy.stderr @@ -2,13 +2,11 @@ error[E0599]: no method named `clone` found for struct `std::boxed::Box<R>` in t --> $DIR/unique-pinned-nocopy.rs:12:16 | LL | struct R { - | -------- this type doesn't satisfy the bound `std::clone::Clone` + | -------- the method `clone` exists but this type doesn't satisfy the bound `R: std::clone::Clone` ... LL | let _j = i.clone(); | ^^^^^ method not found in `std::boxed::Box<R>` | - = note: the method `clone` exists but the following trait bounds were not satisfied: - `R: std::clone::Clone` = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `clone`, perhaps you need to implement it: candidate #1: `std::clone::Clone` |
