Skip to content

Commit c0d5aa8

Browse files
committed
Make unsatisfied trait bounds note multiline
Make diagnostic note for existing method with unsatisfied trait bounds multiline for cleaner output. ``` = note: the method `count` exists but the following trait bounds were not satisfied: `[closure@../../src/test/compile-fail/issue-36053-2.rs:17:39: 17:53] : std::ops::FnMut<(&_,)>` `std::iter::Filter<std::iter::Fuse<std::iter::Once<&str>> [closure@../../src/test/compile-fail/issue-36053-2.rs:17:39: 17:53]> : std::iter::Iterator` Before: ``` = note: the method `count` exists but the following trait bounds were not satisfied: `[closure@../../src/test/compile-fail/issue-36053-2.rs:17:39: 17:53] : std::ops::FnMut<(&_,)>`, `std::iter::Filter<std::iter::Fuse<std::iter::Once<&str>>, [closure@../../src/test/compile-fail/issue-36053-2.rs:17:39: 17:53]> : std::iter::Iterator` ```
1 parent 386b0b9 commit c0d5aa8

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/librustc_typeck/check/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
251251
let bound_list = unsatisfied_predicates.iter()
252252
.map(|p| format!("`{} : {}`", p.self_ty(), p))
253253
.collect::<Vec<_>>()
254-
.join(", ");
254+
.join("\n");
255255
err.note(&format!("the method `{}` exists but the following trait bounds \
256-
were not satisfied: {}",
256+
were not satisfied:\n{}",
257257
item_name,
258258
bound_list));
259259
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ error: no method named `count` found for type `std::iter::Filter<std::iter::Fuse
44
17 | once::<&str>("str").fuse().filter(|a: &str| true).count();
55
| ^^^^^
66
|
7-
= note: the method `count` exists but the following trait bounds were not satisfied: `[closure@$DIR/issue-36053-2.rs:17:39: 17:53] : std::ops::FnMut<(&_,)>`, `std::iter::Filter<std::iter::Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:17:39: 17:53]> : std::iter::Iterator`
7+
= note: the method `count` exists but the following trait bounds were not satisfied:
8+
`[closure@$DIR/issue-36053-2.rs:17:39: 17:53] : std::ops::FnMut<(&_,)>`
9+
`std::iter::Filter<std::iter::Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:17:39: 17:53]> : std::iter::Iterator`
810

911
error[E0281]: type mismatch: `[closure@$DIR/issue-36053-2.rs:17:39: 17:53]` implements the trait `for<'r> std::ops::FnMut<(&'r str,)>`, but the trait `for<'r> std::ops::FnMut<(&'r &str,)>` is required
1012
--> $DIR/issue-36053-2.rs:17:32

src/test/compile-fail/method-help-unsatisfied-bound.rs src/test/ui/mismatched_types/method-help-unsatisfied-bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ fn main() {
1414
let a: Result<(), Foo> = Ok(());
1515
a.unwrap();
1616
//~^ ERROR no method named `unwrap` found for type `std::result::Result<(), Foo>`
17-
//~| NOTE the following trait bounds were not satisfied: `Foo : std::fmt::Debug`
17+
//~| NOTE the method `unwrap` exists but the following trait bounds were not satisfied
1818
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: no method named `unwrap` found for type `std::result::Result<(), Foo>` in the current scope
2+
--> $DIR/method-help-unsatisfied-bound.rs:15:7
3+
|
4+
15 | a.unwrap();
5+
| ^^^^^^
6+
|
7+
= note: the method `unwrap` exists but the following trait bounds were not satisfied:
8+
`Foo : std::fmt::Debug`
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)