Files
rust/tests/ui/traits/bound/same-crate-name.stderr
T
Romain Perier c8c04663c5 Add a note when a type implements a trait with the same name as the required one
This is useful when you have two dependencies that use different trait for
the same thing and with the same name. The user can accidentally implement
the bad one which might be confusing. This commits refactorizes existing
diagnostics about multiple different crates with the same version and adds
a note when similarly named traits are found. All diagnostics are merged
into a single one.
2025-11-11 17:36:43 +01:00

124 lines
4.7 KiB
Plaintext

error[E0277]: the trait bound `Foo: main::a::Bar` is not satisfied
--> $DIR/same-crate-name.rs:33:20
|
LL | a::try_foo(foo);
| ---------- ^^^ the trait `main::a::Bar` is not implemented for `Foo`
| |
| required by a bound introduced by this call
|
note: there are multiple different versions of crate `crate_a1` in the dependency graph
--> $DIR/auxiliary/crate_a1.rs:1:1
|
LL | pub trait Bar {}
| ^^^^^^^^^^^^^ this is the expected trait
|
::: $DIR/auxiliary/crate_a2.rs:3:1
|
LL | pub trait Bar {}
| ------------- this is the found trait
= help: you can use `cargo tree` to explore your dependency tree
help: the trait `main::a::Bar` is implemented for `ImplementsTraitForUsize<usize>`
--> $DIR/auxiliary/crate_a1.rs:9:1
|
LL | impl Bar for ImplementsTraitForUsize<usize> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `try_foo`
--> $DIR/auxiliary/crate_a1.rs:3:24
|
LL | pub fn try_foo(x: impl Bar) {}
| ^^^ required by this bound in `try_foo`
error[E0277]: the trait bound `DoesNotImplementTrait: main::a::Bar` is not satisfied
--> $DIR/same-crate-name.rs:40:20
|
LL | a::try_foo(implements_no_traits);
| ---------- ^^^^^^^^^^^^^^^^^^^^ the trait `main::a::Bar` is not implemented for `DoesNotImplementTrait`
| |
| required by a bound introduced by this call
|
note: there are multiple different versions of crate `crate_a1` in the dependency graph
--> $DIR/auxiliary/crate_a1.rs:1:1
|
LL | pub trait Bar {}
| ^^^^^^^^^^^^^ this is the expected trait
|
::: $DIR/auxiliary/crate_a2.rs:3:1
|
LL | pub trait Bar {}
| ------------- this is the trait that was imported
= help: you can use `cargo tree` to explore your dependency tree
help: the trait `main::a::Bar` is implemented for `ImplementsTraitForUsize<usize>`
--> $DIR/auxiliary/crate_a1.rs:9:1
|
LL | impl Bar for ImplementsTraitForUsize<usize> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `try_foo`
--> $DIR/auxiliary/crate_a1.rs:3:24
|
LL | pub fn try_foo(x: impl Bar) {}
| ^^^ required by this bound in `try_foo`
error[E0277]: the trait bound `ImplementsWrongTraitConditionally<isize>: main::a::Bar` is not satisfied
--> $DIR/same-crate-name.rs:49:20
|
LL | a::try_foo(other_variant_implements_mismatched_trait);
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `main::a::Bar` is not implemented for `ImplementsWrongTraitConditionally<isize>`
| |
| required by a bound introduced by this call
|
note: there are multiple different versions of crate `crate_a1` in the dependency graph
--> $DIR/auxiliary/crate_a1.rs:1:1
|
LL | pub trait Bar {}
| ^^^^^^^^^^^^^ this is the expected trait
|
::: $DIR/auxiliary/crate_a2.rs:3:1
|
LL | pub trait Bar {}
| ------------- this is the found trait
= help: you can use `cargo tree` to explore your dependency tree
help: the trait `main::a::Bar` is implemented for `ImplementsTraitForUsize<usize>`
--> $DIR/auxiliary/crate_a1.rs:9:1
|
LL | impl Bar for ImplementsTraitForUsize<usize> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `try_foo`
--> $DIR/auxiliary/crate_a1.rs:3:24
|
LL | pub fn try_foo(x: impl Bar) {}
| ^^^ required by this bound in `try_foo`
error[E0277]: the trait bound `ImplementsTraitForUsize<isize>: main::a::Bar` is not satisfied
--> $DIR/same-crate-name.rs:57:20
|
LL | a::try_foo(other_variant_implements_correct_trait);
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `main::a::Bar` is not implemented for `ImplementsTraitForUsize<isize>`
| |
| required by a bound introduced by this call
|
note: there are multiple different versions of crate `crate_a1` in the dependency graph
--> $DIR/auxiliary/crate_a1.rs:1:1
|
LL | pub trait Bar {}
| ^^^^^^^^^^^^^ this is the expected trait
|
::: $DIR/auxiliary/crate_a2.rs:3:1
|
LL | pub trait Bar {}
| ------------- this is the trait that was imported
= help: you can use `cargo tree` to explore your dependency tree
help: the trait `main::a::Bar` is implemented for `ImplementsTraitForUsize<usize>`
--> $DIR/auxiliary/crate_a1.rs:9:1
|
LL | impl Bar for ImplementsTraitForUsize<usize> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `try_foo`
--> $DIR/auxiliary/crate_a1.rs:3:24
|
LL | pub fn try_foo(x: impl Bar) {}
| ^^^ required by this bound in `try_foo`
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0277`.