Skip to content

Commit

Permalink
Rollup merge of rust-lang#41489 - estebank:trait-bounds-diagnosstic, …
Browse files Browse the repository at this point in the history
…r=arielb1

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`
```
  • Loading branch information
Mark-Simulacrum authored May 16, 2017
2 parents 4d09a0e + c0d5aa8 commit a49d6c1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let bound_list = unsatisfied_predicates.iter()
.map(|p| format!("`{} : {}`", p.self_ty(), p))
.collect::<Vec<_>>()
.join(", ");
.join("\n");
err.note(&format!("the method `{}` exists but the following trait bounds \
were not satisfied: {}",
were not satisfied:\n{}",
item_name,
bound_list));
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/mismatched_types/issue-36053-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ error: no method named `count` found for type `std::iter::Filter<std::iter::Fuse
17 | once::<&str>("str").fuse().filter(|a: &str| true).count();
| ^^^^^
|
= 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`
= 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`

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
--> $DIR/issue-36053-2.rs:17:32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ fn main() {
let a: Result<(), Foo> = Ok(());
a.unwrap();
//~^ ERROR no method named `unwrap` found for type `std::result::Result<(), Foo>`
//~| NOTE the following trait bounds were not satisfied: `Foo : std::fmt::Debug`
//~| NOTE the method `unwrap` exists but the following trait bounds were not satisfied
}
11 changes: 11 additions & 0 deletions src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: no method named `unwrap` found for type `std::result::Result<(), Foo>` in the current scope
--> $DIR/method-help-unsatisfied-bound.rs:15:7
|
15 | a.unwrap();
| ^^^^^^
|
= note: the method `unwrap` exists but the following trait bounds were not satisfied:
`Foo : std::fmt::Debug`

error: aborting due to previous error

0 comments on commit a49d6c1

Please sign in to comment.