Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not call extern_crate on current trait on crate mismatch errors #133585

Merged
merged 3 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
span.push_span_label(self.tcx.def_span(trait_def_id), "this is the required trait");
for (sp, label) in [trait_def_id, other_trait_def_id]
.iter()
// The current crate-version might depend on another version of the same crate
// (Think "semver-trick"). Do not call `extern_crate` in that case for the local
// crate as that doesn't make sense and ICEs (#133563).
.filter(|def_id| !def_id.is_local())
.filter_map(|def_id| self.tcx.extern_crate(def_id.krate))
.map(|data| {
let dependency = if data.dependency_of == LOCAL_CRATE {
Expand Down
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>();
}
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 {}
32 changes: 32 additions & 0 deletions tests/run-make/crate-loading-crate-depends-on-itself/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@ 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::{rust_lib_name, rustc};

fn main() {
rustc().input("foo-prev.rs").run();

rustc()
.extra_filename("current")
.metadata("current")
.input("foo-current.rs")
.extern_("foo", rust_lib_name("foo"))
.run_fail()
.assert_stderr_contains(r#"
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"#);
}
estebank marked this conversation as resolved.
Show resolved Hide resolved
Loading