rust/tests/ui/impl-trait/non-defining-uses/avoid-inference-constraints-from-blanket-3.stderr
Esteban Küber 1d860902f6 When a trait isn't implemented, but another similar impl is found, point at it:
```
error[E0277]: the trait bound `u32: Trait` is not satisfied
  --> $DIR/trait_objects_fail.rs:26:9
   |
LL |     foo(&10_u32);
   |         ^^^^^^^ the trait `Trait` is not implemented for `u32`
   |
help: the trait `Trait<12>` is not implemented for `u32`
      but trait `Trait<2>` is implemented for it
  --> $DIR/trait_objects_fail.rs:7:1
   |
LL | impl Trait<2> for u32 {}
   | ^^^^^^^^^^^^^^^^^^^^^
   = note: required for the cast from `&u32` to `&dyn Trait`
```

Pointing at the `impl` definition that *could* apply given a different self type is particularly useful when it has a blanket self type, as it might not be obvious and is not trivially greppable:

```
error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied
  --> $DIR/issue-62742.rs:4:5
   |
LL |     WrongImpl::foo(0i32);
   |     ^^^^^^^^^ unsatisfied trait bound
   |
help: the trait `Raw<_>` is not implemented for `RawImpl<_>`
      but trait `Raw<[_]>` is implemented for it
  --> $DIR/issue-62742.rs:29:1
   |
LL | impl<T> Raw<[T]> for RawImpl<T> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `SafeImpl`
  --> $DIR/issue-62742.rs:33:35
   |
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
   |                                   ^^^^^^ required by this bound in `SafeImpl`
```
2025-10-31 20:38:31 +00:00

30 lines
1.1 KiB
Plaintext

error[E0277]: the trait bound `String: Trait<u32>` is not satisfied
--> $DIR/avoid-inference-constraints-from-blanket-3.rs:22:5
|
LL | impls_trait(x);
| ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
help: the trait `Trait<u32>` is not implemented for `String`
but trait `Trait<u64>` is implemented for it
--> $DIR/avoid-inference-constraints-from-blanket-3.rs:17:1
|
LL | impl Trait<u64> for String {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for that trait implementation, expected `u64`, found `u32`
note: required for `String` to implement `Trait<u32>`
--> $DIR/avoid-inference-constraints-from-blanket-3.rs:16:15
|
LL | impl<T: Copy> Trait<u32> for T {}
| ---- ^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
note: required by a bound in `impls_trait`
--> $DIR/avoid-inference-constraints-from-blanket-3.rs:18:19
|
LL | fn impls_trait<T: Trait<U>, U>(_: T) {}
| ^^^^^^^^ required by this bound in `impls_trait`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.