]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #91873 - estebank:mention-impls-for-unsatisfied-trait, r=davidtwco
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Mon, 4 Apr 2022 23:53:31 +0000 (01:53 +0200)
committerGitHub <noreply@github.com>
Mon, 4 Apr 2022 23:53:31 +0000 (01:53 +0200)
commita5c81695a95e2a1a8e2ea4310bf670a9c1734387
treeba446eeedcbbef79c9fe8a2c5e74188767e8a7d1
parent60e50fc1cfe0bb693a5f4f93eb83ef70854531e3
parente1ef833bca8fe21cb2cbc42795cda4b589ec6f25
Rollup merge of #91873 - estebank:mention-impls-for-unsatisfied-trait, r=davidtwco

Mention implementers of unsatisfied trait

When encountering an unsatisfied trait bound, if there are no other
suggestions, mention all the types that *do* implement that trait:

```
error[E0277]: the trait bound `f32: Foo` is not satisfied
  --> $DIR/impl_wf.rs:22:6
   |
LL | impl Baz<f32> for f32 { }
   |      ^^^^^^^^ the trait `Foo` is not implemented for `f32`
   |
   = help: the trait `Foo` is implemented for `i32`
note: required by a bound in `Baz`
  --> $DIR/impl_wf.rs:18:31
   |
LL | trait Baz<U: ?Sized> where U: Foo { }
   |                               ^^^ required by this bound in `Baz`
```
```
error[E0277]: the trait bound `u32: Foo` is not satisfied
  --> $DIR/associated-types-path-2.rs:29:5
   |
LL |     f1(2u32, 4u32);
   |     ^^ the trait `Foo` is not implemented for `u32`
   |
   = help: the trait `Foo` is implemented for `i32`
note: required by a bound in `f1`
  --> $DIR/associated-types-path-2.rs:13:14
   |
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
   |              ^^^ required by this bound in `f1`
```

Suggest dereferencing in more cases.

Fix #87437, fix #90970.
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs