rust/tests/ui/impl-trait/non-defining-uses
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
..
ambiguous-ops.current.stderr support calls on opaque types :< 2025-09-18 12:58:38 +02:00
ambiguous-ops.rs support calls on opaque types :< 2025-09-18 12:58:38 +02:00
as-projection-term.rs use defining uses of all bodies to constrain non-defining uses 2025-09-01 22:08:03 +02:00
avoid-inference-constraints-from-blanket-2.next.stderr incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
avoid-inference-constraints-from-blanket-2.rs incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
avoid-inference-constraints-from-blanket-3.rs incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
avoid-inference-constraints-from-blanket-3.stderr When a trait isn't implemented, but another similar impl is found, point at it: 2025-10-31 20:38:31 +00:00
avoid-inference-constraints-from-blanket.rs incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
call-expr-incorrect-choice-diagnostics.current.stderr add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
call-expr-incorrect-choice-diagnostics.next.stderr add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
call-expr-incorrect-choice-diagnostics.rs add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
deref-constrains-self-ty.current.stderr add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
deref-constrains-self-ty.rs add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
double-wrap-with-defining-use.current.stderr add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
double-wrap-with-defining-use.rs add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
function-call-on-infer.rs support calls on opaque types :< 2025-09-18 12:58:38 +02:00
ice-issue-146191.current.stderr add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
ice-issue-146191.next.stderr add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
ice-issue-146191.rs add tests, silence type annotations needed errors for opaques 2025-09-18 12:58:39 +02:00
impl-deref-function-call.rs support calls on opaque types :< 2025-09-18 12:58:38 +02:00
multiple-opaques-ambig.rs incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
multiple-opaques-ok.rs incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
no-rigid-alias.rs incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
recursive-call.rs use defining uses of all bodies to constrain non-defining uses 2025-09-01 22:08:03 +02:00
shex_compat-regression-test.rs support calls on opaque types :< 2025-09-18 12:58:38 +02:00
use-blanket-impl.rs incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
use-item-bound-over-blanket-impl.rs incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
use-item-bound.rs incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00