-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #124944 - estebank:multiple-crate-versions, r=fee1-dead
On trait bound mismatch, detect multiple crate versions in dep tree When encountering an E0277, if the type and the trait both come from a crate with the same name but different crate number, we explain that there are multiple crate versions in the dependency tree. If there's a type that fulfills the bound, and it has the same name as the passed in type and has the same crate name, we explain that the same type in two different versions of the same crate *are different*. ``` error[E0277]: the trait bound `Type: dependency::Trait` is not satisfied --> src/main.rs:4:18 | 4 | do_something(Type); | ------------ ^^^^ the trait `dependency::Trait` is not implemented for `Type` | | | required by a bound introduced by this call | help: you have multiple different versions of crate `dependency` in your dependency graph --> src/main.rs:1:5 | 1 | use bar::do_something; | ^^^ one version of crate `dependency` is used here, as a dependency of crate `bar` 2 | use dependency::Type; | ^^^^^^^^^^ one version of crate `dependency` is used here, as a direct dependency of the current crate note: two types coming from two different versions of the same crate are different types even if they look the same --> /home/gh-estebank/crate_versions/baz-2/src/lib.rs:1:1 | 1 | pub struct Type; | ^^^^^^^^^^^^^^^ this type doesn't implement the required trait | ::: /home/gh-estebank/crate_versions/baz/src/lib.rs:1:1 | 1 | pub struct Type; | ^^^^^^^^^^^^^^^ this type implements the required trait 2 | pub trait Trait {} | --------------- this is the required trait note: required by a bound in `bar::do_something` --> /home/gh-estebank/crate_versions/baz/src/lib.rs:4:24 | 4 | pub fn do_something<X: Trait>(_: X) {} | ^^^^^ required by this bound in `do_something` ``` Address #22750.
- Loading branch information
Showing
7 changed files
with
209 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![crate_name = "dependency"] | ||
#![crate_type = "rlib"] | ||
pub struct Type; | ||
pub trait Trait {} | ||
impl Trait for Type {} | ||
pub fn do_something<X: Trait>(_: X) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![crate_name = "dependency"] | ||
#![crate_type = "rlib"] | ||
pub struct Type(pub i32); | ||
pub trait Trait {} | ||
impl Trait for Type {} | ||
pub fn do_something<X: Trait>(_: X) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
extern crate dep_2_reexport; | ||
extern crate dependency; | ||
use dep_2_reexport::do_something; | ||
use dependency::Type; | ||
|
||
fn main() { | ||
do_something(Type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//@ only-linux | ||
//@ ignore-wasm32 | ||
//@ ignore-wasm64 | ||
|
||
use run_make_support::rfs::copy; | ||
use run_make_support::{assert_contains, rust_lib_name, rustc}; | ||
|
||
fn main() { | ||
rustc().input("multiple-dep-versions-1.rs").run(); | ||
rustc().input("multiple-dep-versions-2.rs").extra_filename("2").metadata("2").run(); | ||
|
||
let out = rustc() | ||
.input("multiple-dep-versions.rs") | ||
.extern_("dependency", rust_lib_name("dependency")) | ||
.extern_("dep_2_reexport", rust_lib_name("dependency2")) | ||
.run_fail() | ||
.assert_stderr_contains( | ||
"you have multiple different versions of crate `dependency` in your dependency graph", | ||
) | ||
.assert_stderr_contains( | ||
"two types coming from two different versions of the same crate are different types \ | ||
even if they look the same", | ||
) | ||
.assert_stderr_contains("this type doesn't implement the required trait") | ||
.assert_stderr_contains("this type implements the required trait") | ||
.assert_stderr_contains("this is the required trait"); | ||
} |