-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #133585 - estebank:issue-133563, r=jieyouxu
Do not call `extern_crate` on current trait on crate mismatch errors When we encounter an error caused by traits/types of different versions of the same crate, filter out the current crate when collecting spans to add to the context so we don't call `extern_crate` on the `DefId` of the current crate, which is meaningless and ICEs. Produced output with this filter: ``` error[E0277]: the trait bound `foo::Struct: Trait` is not satisfied --> y.rs:13:19 | 13 | check_trait::<foo::Struct>(); | ^^^^^^^^^^^ the trait `Trait` is not implemented for `foo::Struct` | note: there are multiple different versions of crate `foo` in the dependency graph --> y.rs:7:1 | 4 | extern crate foo; | ----------------- one version of crate `foo` is used here, as a direct dependency of the current crate 5 | 6 | pub struct Struct; | ----------------- this type implements the required trait 7 | pub trait Trait {} | ^^^^^^^^^^^^^^^ this is the required trait | ::: x.rs:4:1 | 4 | pub struct Struct; | ----------------- this type doesn't implement the required trait 5 | 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 `check_trait` --> y.rs:10:19 | 10 | fn check_trait<T: Trait>() {} | ^^^^^ required by this bound in `check_trait` ``` Fix #133563.
- Loading branch information
Showing
8 changed files
with
241 additions
and
76 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
14 changes: 14 additions & 0 deletions
14
tests/run-make/crate-loading-crate-depends-on-itself/foo-current.rs
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,14 @@ | ||
#![crate_type = "lib"] | ||
#![crate_name = "foo"] | ||
|
||
extern crate foo; | ||
|
||
pub struct Struct; | ||
pub trait Trait {} | ||
impl Trait for Struct {} | ||
|
||
fn check_trait<T: Trait>() {} | ||
|
||
fn ice() { | ||
check_trait::<foo::Struct>(); | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/run-make/crate-loading-crate-depends-on-itself/foo-prev.rs
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_type = "lib"] | ||
#![crate_name = "foo"] | ||
|
||
pub struct Struct; | ||
pub trait Trait {} | ||
impl Trait for Struct {} |
34 changes: 34 additions & 0 deletions
34
tests/run-make/crate-loading-crate-depends-on-itself/foo.stderr
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,34 @@ | ||
error[E0277]: the trait bound `foo::Struct: Trait` is not satisfied | ||
--> foo-current.rs:13:19 | ||
| | ||
13 | check_trait::<foo::Struct>(); | ||
| ^^^^^^^^^^^ the trait `Trait` is not implemented for `foo::Struct` | ||
| | ||
note: there are multiple different versions of crate `foo` in the dependency graph | ||
--> foo-current.rs:7:1 | ||
| | ||
4 | extern crate foo; | ||
| ----------------- one version of crate `foo` is used here, as a direct dependency of the current crate | ||
5 | | ||
6 | pub struct Struct; | ||
| ----------------- this type implements the required trait | ||
7 | pub trait Trait {} | ||
| ^^^^^^^^^^^^^^^ this is the required trait | ||
| | ||
::: foo-prev.rs:X:Y | ||
| | ||
4 | pub struct Struct; | ||
| ----------------- this type doesn't implement the required trait | ||
5 | 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 `check_trait` | ||
--> foo-current.rs:10:19 | ||
| | ||
10 | fn check_trait<T: Trait>() {} | ||
| ^^^^^ required by this bound in `check_trait` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
31 changes: 31 additions & 0 deletions
31
tests/run-make/crate-loading-crate-depends-on-itself/rmake.rs
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,31 @@ | ||
//@ only-linux | ||
//@ ignore-wasm32 | ||
//@ ignore-wasm64 | ||
// ignore-tidy-linelength | ||
|
||
// Verify that if the current crate depends on a different version of the same crate, *and* types | ||
// and traits of the different versions are mixed, we produce diagnostic output and not an ICE. | ||
// #133563 | ||
|
||
use run_make_support::{diff, rust_lib_name, rustc}; | ||
|
||
fn main() { | ||
rustc().input("foo-prev.rs").run(); | ||
|
||
let out = rustc() | ||
.extra_filename("current") | ||
.metadata("current") | ||
.input("foo-current.rs") | ||
.extern_("foo", rust_lib_name("foo")) | ||
.run_fail() | ||
.stderr_utf8(); | ||
|
||
// We don't remap the path of the `foo-prev` crate, so we remap it here. | ||
let mut lines: Vec<_> = out.lines().collect(); | ||
for line in &mut lines { | ||
if line.starts_with(" ::: ") { | ||
*line = " ::: foo-prev.rs:X:Y"; | ||
} | ||
} | ||
diff().expected_file("foo.stderr").actual_text("(rustc)", &lines.join("\n")).run(); | ||
} |
127 changes: 127 additions & 0 deletions
127
tests/run-make/crate-loading/multiple-dep-versions.stderr
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,127 @@ | ||
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` 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 | ||
| | ||
::: 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}; | ||
| ----- `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}; | ||
| ----- `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` 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 | ||
| | ||
::: 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: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0599. | ||
For more information about an error, try `rustc --explain E0277`. |
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