mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-27 19:16:36 +00:00
When encountering a type or trait mismatch for two types coming from two different crates with the same name, detect if it is either mixing two types/traits from the same crate on different versions:
```
error[E0308]: mismatched types
--> replaced
|
LL | do_something_type(Type);
| ----------------- ^^^^ expected `dependency::Type`, found `dep_2_reexport::Type`
| |
| arguments to this function are incorrect
|
note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same
--> replaced
|
LL | pub struct Type(pub i32);
| ^^^^^^^^^^^^^^^ this is the expected type `dependency::Type`
|
::: replaced
|
LL | pub struct Type;
| ^^^^^^^^^^^^^^^ this is the found type `dep_2_reexport::Type`
|
::: replaced
|
LL | extern crate dep_2_reexport;
| ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
LL | extern crate dependency;
| ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate
= help: you can use `cargo tree` to explore your dependency tree
note: function defined here
--> replaced
|
LL | pub fn do_something_type(_: Type) {}
| ^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types
--> replaced
|
LL | do_something_trait(Box::new(Type) as Box<dyn Trait2>);
| ------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `dependency::Trait2`, found trait `dep_2_reexport::Trait2`
| |
| arguments to this function are incorrect
|
note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same
--> replaced
|
LL | pub trait Trait2 {}
| ^^^^^^^^^^^^^^^^ this is the expected trait `dependency::Trait2`
|
::: replaced
|
LL | pub trait Trait2 {}
| ^^^^^^^^^^^^^^^^ this is the found trait `dep_2_reexport::Trait2`
|
::: replaced
|
LL | extern crate dep_2_reexport;
| ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
LL | extern crate dependency;
| ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate
= help: you can use `cargo tree` to explore your dependency tree
note: function defined here
--> replaced
|
LL | pub fn do_something_trait(_: Box<dyn Trait2>) {}
| ^^^^^^^^^^^^^^^^^^
```
or if it is different crates that were renamed to the same name:
```
error[E0308]: mismatched types
--> $DIR/type-mismatch-same-crate-name.rs:21:20
|
LL | a::try_foo(foo2);
| ---------- ^^^^ expected `main:🅰️:Foo`, found a different `main:🅰️:Foo`
| |
| arguments to this function are incorrect
|
note: two types coming from two different crates are different types even if they look the same
--> $DIR/auxiliary/crate_a2.rs:1:1
|
LL | pub struct Foo;
| ^^^^^^^^^^^^^^ this is the found type `crate_a2::Foo`
|
::: $DIR/auxiliary/crate_a1.rs:1:1
|
LL | pub struct Foo;
| ^^^^^^^^^^^^^^ this is the expected type `crate_a1::Foo`
|
::: $DIR/type-mismatch-same-crate-name.rs:13:17
|
LL | let foo2 = {extern crate crate_a2 as a; a::Foo};
| --------------------------- one type comes from crate `crate_a2` is used here, which is renamed locally to `a`
...
LL | extern crate crate_a1 as a;
| --------------------------- one type comes from crate `crate_a1` is used here, which is renamed locally to `a`
note: function defined here
--> $DIR/auxiliary/crate_a1.rs:10:8
|
LL | pub fn try_foo(x: Foo){}
| ^^^^^^^
error[E0308]: mismatched types
--> $DIR/type-mismatch-same-crate-name.rs:27:20
|
LL | a::try_bar(bar2);
| ---------- ^^^^ expected trait `main:🅰️:Bar`, found a different trait `main:🅰️:Bar`
| |
| arguments to this function are incorrect
|
note: two types coming from two different crates are different types even if they look the same
--> $DIR/auxiliary/crate_a2.rs:3:1
|
LL | pub trait Bar {}
| ^^^^^^^^^^^^^ this is the found trait `crate_a2::Bar`
|
::: $DIR/auxiliary/crate_a1.rs:3:1
|
LL | pub trait Bar {}
| ^^^^^^^^^^^^^ this is the expected trait `crate_a1::Bar`
|
::: $DIR/type-mismatch-same-crate-name.rs:13:17
|
LL | let foo2 = {extern crate crate_a2 as a; a::Foo};
| --------------------------- one trait comes from crate `crate_a2` is used here, which is renamed locally to `a`
...
LL | extern crate crate_a1 as a;
| --------------------------- one trait comes from crate `crate_a1` is used here, which is renamed locally to `a`
note: function defined here
--> $DIR/auxiliary/crate_a1.rs:11:8
|
LL | pub fn try_bar(x: Box<Bar>){}
| ^^^^^^^
```
This new output unifies the E0308 errors detail with the pre-existing E0277 errors, and better differentiates the "`extern crate` renamed" and "same crate, different versions" cases.
191 lines
6.8 KiB
Plaintext
191 lines
6.8 KiB
Plaintext
error[E0277]: the trait bound `dep_2_reexport::Type: Trait` is not satisfied
|
|
--> replaced
|
|
|
|
|
LL | do_something(Type);
|
|
| ------------ ^^^^ the trait `Trait` is not implemented for `dep_2_reexport::Type`
|
|
| |
|
|
| required by a bound introduced by this call
|
|
|
|
|
note: there are multiple different versions of crate `dependency` in the dependency graph
|
|
--> replaced
|
|
|
|
|
LL | pub struct Type(pub i32);
|
|
| --------------- this type implements the required trait
|
|
LL | pub trait Trait {
|
|
| ^^^^^^^^^^^^^^^ this is the required trait
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | extern crate dep_2_reexport;
|
|
| ---------------------------- one version of crate `dependency` used here, as a dependency of crate `foo`
|
|
LL | extern crate dependency;
|
|
| ------------------------ one version of crate `dependency` used here, as a direct dependency of the current crate
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | pub struct Type;
|
|
| --------------- this type doesn't implement the required trait
|
|
LL | pub trait Trait {
|
|
| --------------- this is the found trait
|
|
= note: two types coming from two different versions of the same crate are different types even if they look the same
|
|
= help: you can use `cargo tree` to explore your dependency tree
|
|
note: required by a bound in `do_something`
|
|
--> replaced
|
|
|
|
|
LL | pub fn do_something<X: Trait>(_: X) {}
|
|
| ^^^^^ required by this bound in `do_something`
|
|
|
|
error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope
|
|
--> replaced
|
|
|
|
|
LL | Type.foo();
|
|
| ^^^ method not found in `Type`
|
|
|
|
|
note: there are multiple different versions of crate `dependency` in the dependency graph
|
|
--> replaced
|
|
|
|
|
LL | pub trait Trait {
|
|
| ^^^^^^^^^^^^^^^ this is the trait that is needed
|
|
LL | fn foo(&self);
|
|
| -------------- the method is available for `dep_2_reexport::Type` here
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | use dependency::{Trait, do_something, do_something_trait, do_something_type};
|
|
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | pub trait Trait {
|
|
| --------------- this is the trait that was imported
|
|
|
|
error[E0599]: no function or associated item named `bar` found for struct `dep_2_reexport::Type` in the current scope
|
|
--> replaced
|
|
|
|
|
LL | Type::bar();
|
|
| ^^^ function or associated item not found in `Type`
|
|
|
|
|
note: there are multiple different versions of crate `dependency` in the dependency graph
|
|
--> replaced
|
|
|
|
|
LL | pub trait Trait {
|
|
| ^^^^^^^^^^^^^^^ this is the trait that is needed
|
|
LL | fn foo(&self);
|
|
LL | fn bar();
|
|
| --------- the associated function is available for `dep_2_reexport::Type` here
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | use dependency::{Trait, do_something, do_something_trait, do_something_type};
|
|
| ----- `Trait` imported here doesn't correspond to the right version of crate `dependency`
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | pub trait Trait {
|
|
| --------------- this is the trait that was imported
|
|
|
|
error[E0277]: the trait bound `OtherType: Trait` is not satisfied
|
|
--> replaced
|
|
|
|
|
LL | do_something(OtherType);
|
|
| ------------ ^^^^^^^^^ the trait `Trait` is not implemented for `OtherType`
|
|
| |
|
|
| required by a bound introduced by this call
|
|
|
|
|
note: there are multiple different versions of crate `dependency` in the dependency graph
|
|
--> replaced
|
|
|
|
|
LL | pub trait Trait {
|
|
| ^^^^^^^^^^^^^^^ this is the required trait
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | extern crate dep_2_reexport;
|
|
| ---------------------------- one version of crate `dependency` used here, as a dependency of crate `foo`
|
|
LL | extern crate dependency;
|
|
| ------------------------ one version of crate `dependency` used here, as a direct dependency of the current crate
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | pub struct OtherType;
|
|
| -------------------- this type doesn't implement the required trait
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | pub trait Trait {
|
|
| --------------- this is the found trait
|
|
= help: you can use `cargo tree` to explore your dependency tree
|
|
note: required by a bound in `do_something`
|
|
--> replaced
|
|
|
|
|
LL | pub fn do_something<X: Trait>(_: X) {}
|
|
| ^^^^^ required by this bound in `do_something`
|
|
|
|
error[E0308]: mismatched types
|
|
--> replaced
|
|
|
|
|
LL | do_something_type(Type);
|
|
| ----------------- ^^^^ expected `dependency::Type`, found `dep_2_reexport::Type`
|
|
| |
|
|
| arguments to this function are incorrect
|
|
|
|
|
note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same
|
|
--> replaced
|
|
|
|
|
LL | pub struct Type(pub i32);
|
|
| ^^^^^^^^^^^^^^^ this is the expected type `dependency::Type`
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | pub struct Type;
|
|
| ^^^^^^^^^^^^^^^ this is the found type `dep_2_reexport::Type`
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | extern crate dep_2_reexport;
|
|
| ---------------------------- one version of crate `dependency` used here, as a dependency of crate `foo`
|
|
LL | extern crate dependency;
|
|
| ------------------------ one version of crate `dependency` used here, as a direct dependency of the current crate
|
|
= help: you can use `cargo tree` to explore your dependency tree
|
|
note: function defined here
|
|
--> replaced
|
|
|
|
|
LL | pub fn do_something_type(_: Type) {}
|
|
| ^^^^^^^^^^^^^^^^^
|
|
|
|
error[E0308]: mismatched types
|
|
--> replaced
|
|
|
|
|
LL | do_something_trait(Box::new(Type) as Box<dyn Trait2>);
|
|
| ------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `dependency::Trait2`, found trait `dep_2_reexport::Trait2`
|
|
| |
|
|
| arguments to this function are incorrect
|
|
|
|
|
note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same
|
|
--> replaced
|
|
|
|
|
LL | pub trait Trait2 {}
|
|
| ^^^^^^^^^^^^^^^^ this is the expected trait `dependency::Trait2`
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | pub trait Trait2 {}
|
|
| ^^^^^^^^^^^^^^^^ this is the found trait `dep_2_reexport::Trait2`
|
|
|
|
|
::: replaced
|
|
|
|
|
LL | extern crate dep_2_reexport;
|
|
| ---------------------------- one version of crate `dependency` used here, as a dependency of crate `foo`
|
|
LL | extern crate dependency;
|
|
| ------------------------ one version of crate `dependency` used here, as a direct dependency of the current crate
|
|
= help: you can use `cargo tree` to explore your dependency tree
|
|
note: function defined here
|
|
--> replaced
|
|
|
|
|
LL | pub fn do_something_trait(_: Box<dyn Trait2>) {}
|
|
| ^^^^^^^^^^^^^^^^^^
|
|
|
|
error: aborting due to 6 previous errors
|
|
|
|
Some errors have detailed explanations: E0277, E0308, E0599.
|
|
For more information about an error, try `rustc --explain E0277`. |