Skip to content

Commit 2e8399d

Browse files
committed
Deduplicate information in E0599
1 parent 70255ef commit 2e8399d

File tree

10 files changed

+46
-48
lines changed

10 files changed

+46
-48
lines changed

src/librustc_typeck/check/method/suggest.rs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -538,16 +538,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
538538
let mut bound_spans = vec![];
539539
let mut bound_list = unsatisfied_predicates
540540
.iter()
541-
.map(|p| {
541+
.filter_map(|p| {
542542
let self_ty = p.self_ty();
543543
match &self_ty.kind {
544-
ty::Adt(def, _) => bound_spans.push((
545-
self.tcx.sess.source_map().def_span(self.tcx.def_span(def.did)),
546-
format!(
547-
"this type doesn't satisfy the bound `{}`",
548-
p.print_only_trait_path()
549-
),
550-
)),
544+
ty::Adt(def, _) => {
545+
bound_spans.push((
546+
self.tcx
547+
.sess
548+
.source_map()
549+
.def_span(self.tcx.def_span(def.did)),
550+
format!(
551+
"the method `{}` exists but this type doesn't satisfy \
552+
the bound `{}: {}`",
553+
item_name,
554+
p.self_ty(),
555+
p.print_only_trait_path()
556+
),
557+
));
558+
None
559+
}
551560
ty::Dynamic(preds, _) => {
552561
for pred in *preds.skip_binder() {
553562
match pred {
@@ -558,18 +567,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
558567
.source_map()
559568
.def_span(self.tcx.def_span(tr.def_id)),
560569
format!(
561-
"this trait doesn't satisfy the bound `{}`",
570+
"the method `{}` exists but this trait \
571+
doesn't satisfy the bound `{}: {}`",
572+
item_name,
573+
p.self_ty(),
562574
p.print_only_trait_path()
563575
),
564576
)),
565577
ty::ExistentialPredicate::Projection(_)
566578
| ty::ExistentialPredicate::AutoTrait(_) => {}
567579
}
568580
}
581+
None
569582
}
570-
_ => {}
571-
};
572-
format!("`{}: {}`", p.self_ty(), p.print_only_trait_path())
583+
_ => Some(format!(
584+
"`{}: {}`",
585+
p.self_ty(),
586+
p.print_only_trait_path()
587+
)),
588+
}
573589
})
574590
.collect::<Vec<_>>();
575591
bound_list.sort();
@@ -579,12 +595,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
579595
for (span, msg) in bound_spans.into_iter() {
580596
err.span_label(span, &msg);
581597
}
582-
let bound_list = bound_list.join("\n");
583-
err.note(&format!(
584-
"the method `{}` exists but the following trait bounds were not \
585-
satisfied:\n{}",
586-
item_name, bound_list
587-
));
598+
if !bound_list.is_empty() {
599+
let bound_list = bound_list.join("\n");
600+
err.note(&format!(
601+
"the method `{}` exists but the following trait bounds were not \
602+
satisfied:\n{}",
603+
item_name, bound_list
604+
));
605+
}
588606
}
589607

590608
if actual.is_numeric() && actual.is_fresh() {

src/test/ui/derives/derive-assoc-type-not-impl.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ LL | struct Bar<T: Foo> {
55
| ------------------ method `clone` not found for this
66
...
77
LL | struct NotClone;
8-
| ---------------- this type doesn't satisfy the bound `std::clone::Clone`
8+
| ---------------- the method `clone` exists but this type doesn't satisfy the bound `NotClone: std::clone::Clone`
99
...
1010
LL | Bar::<NotClone> { x: 1 }.clone();
1111
| ^^^^^ method not found in `Bar<NotClone>`
1212
|
13-
= note: the method `clone` exists but the following trait bounds were not satisfied:
14-
`NotClone: std::clone::Clone`
1513
= help: items from traits can only be used if the trait is implemented and in scope
1614
= note: the following trait defines an item `clone`, perhaps you need to implement it:
1715
candidate #1: `std::clone::Clone`

src/test/ui/issues/issue-31173.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ LL | .collect();
1616
::: $SRC_DIR/libcore/iter/adapters/mod.rs:LL:COL
1717
|
1818
LL | pub struct Cloned<I> {
19-
| -------------------- this type doesn't satisfy the bound `std::iter::Iterator`
20-
|
21-
= note: the method `collect` exists but the following trait bounds were not satisfied:
22-
`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`
19+
| -------------------- 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`
2320

2421
error: aborting due to 2 previous errors
2522

src/test/ui/methods/method-call-err-msg.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ LL | pub struct Foo;
3838
| ---------------
3939
| |
4040
| method `take` not found for this
41-
| this type doesn't satisfy the bound `std::iter::Iterator`
41+
| the method `take` exists but this type doesn't satisfy the bound `Foo: std::iter::Iterator`
4242
...
4343
LL | .take()
4444
| ^^^^ method not found in `Foo`
4545
|
46-
= note: the method `take` exists but the following trait bounds were not satisfied:
47-
`Foo: std::iter::Iterator`
4846
= help: items from traits can only be used if the trait is implemented and in scope
4947
= note: the following traits define an item `take`, perhaps you need to implement one of them:
5048
candidate #1: `std::io::Read`

src/test/ui/mismatched_types/issue-36053-2.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count();
77
::: $SRC_DIR/libcore/iter/adapters/mod.rs:LL:COL
88
|
99
LL | pub struct Filter<I, P> {
10-
| ----------------------- this type doesn't satisfy the bound `std::iter::Iterator`
10+
| ----------------------- 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`
1111
|
1212
= note: the method `count` exists but the following trait bounds were not satisfied:
1313
`[closure@$DIR/issue-36053-2.rs:11:39: 11:53]: std::ops::FnMut<(&_,)>`
14-
`std::iter::Filter<std::iter::Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:11:39: 11:53]>: std::iter::Iterator`
1514

1615
error[E0631]: type mismatch in closure arguments
1716
--> $DIR/issue-36053-2.rs:11:32

src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ error[E0599]: no method named `unwrap` found for enum `std::result::Result<(), F
22
--> $DIR/method-help-unsatisfied-bound.rs:5:7
33
|
44
LL | struct Foo;
5-
| ----------- this type doesn't satisfy the bound `std::fmt::Debug`
5+
| ----------- the method `unwrap` exists but this type doesn't satisfy the bound `Foo: std::fmt::Debug`
66
...
77
LL | a.unwrap();
88
| ^^^^^^ method not found in `std::result::Result<(), Foo>`
9-
|
10-
= note: the method `unwrap` exists but the following trait bounds were not satisfied:
11-
`Foo: std::fmt::Debug`
129

1310
error: aborting due to previous error
1411

src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ LL | struct MyStruct;
88
| ----------------
99
| |
1010
| method `foo_one` not found for this
11-
| this type doesn't satisfy the bound `Foo`
11+
| the method `foo_one` exists but this type doesn't satisfy the bound `MyStruct: Foo`
1212
...
1313
LL | println!("{}", MyStruct.foo_one());
1414
| ^^^^^^^ method not found in `MyStruct`
1515
|
16-
= note: the method `foo_one` exists but the following trait bounds were not satisfied:
17-
`MyStruct: Foo`
1816
= help: items from traits can only be used if the trait is implemented and in scope
1917

2018
error: aborting due to previous error

src/test/ui/union/union-derive-clone.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ LL | union U5<T> {
1414
| ----------- method `clone` not found for this
1515
...
1616
LL | struct CloneNoCopy;
17-
| ------------------- this type doesn't satisfy the bound `std::marker::Copy`
17+
| ------------------- the method `clone` exists but this type doesn't satisfy the bound `CloneNoCopy: std::marker::Copy`
1818
...
1919
LL | let w = u.clone();
2020
| ^^^^^ method not found in `U5<CloneNoCopy>`
2121
|
22-
= note: the method `clone` exists but the following trait bounds were not satisfied:
23-
`CloneNoCopy: std::marker::Copy`
2422
= help: items from traits can only be used if the trait is implemented and in scope
2523
= note: the following trait defines an item `clone`, perhaps you need to implement it:
2624
candidate #1: `std::clone::Clone`

src/test/ui/unique-object-noncopyable.stderr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ error[E0599]: no method named `clone` found for struct `std::boxed::Box<dyn Foo>
44
LL | trait Foo {
55
| ---------
66
| |
7-
| this trait doesn't satisfy the bound `std::clone::Clone`
8-
| this trait doesn't satisfy the bound `std::marker::Sized`
7+
| the method `clone` exists but this trait doesn't satisfy the bound `dyn Foo: std::clone::Clone`
8+
| the method `clone` exists but this trait doesn't satisfy the bound `dyn Foo: std::marker::Sized`
99
...
1010
LL | let _z = y.clone();
1111
| ^^^^^ method not found in `std::boxed::Box<dyn Foo>`
1212
|
13-
= note: the method `clone` exists but the following trait bounds were not satisfied:
14-
`dyn Foo: std::clone::Clone`
15-
`dyn Foo: std::marker::Sized`
1613
= help: items from traits can only be used if the trait is implemented and in scope
1714
= note: the following trait defines an item `clone`, perhaps you need to implement it:
1815
candidate #1: `std::clone::Clone`

src/test/ui/unique-pinned-nocopy.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ error[E0599]: no method named `clone` found for struct `std::boxed::Box<R>` in t
22
--> $DIR/unique-pinned-nocopy.rs:12:16
33
|
44
LL | struct R {
5-
| -------- this type doesn't satisfy the bound `std::clone::Clone`
5+
| -------- the method `clone` exists but this type doesn't satisfy the bound `R: std::clone::Clone`
66
...
77
LL | let _j = i.clone();
88
| ^^^^^ method not found in `std::boxed::Box<R>`
99
|
10-
= note: the method `clone` exists but the following trait bounds were not satisfied:
11-
`R: std::clone::Clone`
1210
= help: items from traits can only be used if the trait is implemented and in scope
1311
= note: the following trait defines an item `clone`, perhaps you need to implement it:
1412
candidate #1: `std::clone::Clone`

0 commit comments

Comments
 (0)