Skip to content

Don't call extern_crate when local crate name is the same as a dependency and we have a trait error #130275

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

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -1669,6 +1669,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let name = self.tcx.crate_name(trait_def_id.krate);
let spans: Vec<_> = [trait_def_id, found_type]
.into_iter()
.filter(|def_id| def_id.krate != LOCAL_CRATE)
.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 @@
pub struct B;
15 changes: 15 additions & 0 deletions tests/ui/typeck/foreign_struct_trait_unimplemented.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ aux-build:foreign_struct_trait_unimplemented.rs

extern crate foreign_struct_trait_unimplemented;

pub trait Test {}

struct A;
impl Test for A {}

fn needs_test(_: impl Test) {}

fn main() {
needs_test(foreign_struct_trait_unimplemented::B);
//~^ ERROR the trait bound `B: Test` is not satisfied
}
23 changes: 23 additions & 0 deletions tests/ui/typeck/foreign_struct_trait_unimplemented.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0277]: the trait bound `B: Test` is not satisfied
--> $DIR/foreign_struct_trait_unimplemented.rs:13:16
|
LL | needs_test(foreign_struct_trait_unimplemented::B);
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Test` is not implemented for `B`
| |
| required by a bound introduced by this call
|
help: there are multiple different versions of crate `foreign_struct_trait_unimplemented` in the dependency graph
--> $DIR/foreign_struct_trait_unimplemented.rs:3:1
|
LL | extern crate foreign_struct_trait_unimplemented;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one version of crate `foreign_struct_trait_unimplemented` is used here, as a direct dependency of the current crate
= help: you can use `cargo tree` to explore your dependency tree
note: required by a bound in `needs_test`
--> $DIR/foreign_struct_trait_unimplemented.rs:10:23
|
LL | fn needs_test(_: impl Test) {}
| ^^^^ required by this bound in `needs_test`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Loading