mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Deduplicate information in E0599
This commit is contained in:
parent
8993b99ae2
commit
ad4777dbca
@ -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() {
|
||||
|
@ -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`
|
||||
|
@ -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
|
||||
|
||||
|
@ -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`
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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`
|
||||
|
@ -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`
|
||||
|
@ -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`
|
||||
|
Loading…
Reference in New Issue
Block a user