Skip to content

Commit 78bceb1

Browse files
authored
Unrolled build for rust-lang#130275
Rollup merge of rust-lang#130275 - compiler-errors:extern-crate, r=lcnr Don't call `extern_crate` when local crate name is the same as a dependency and we have a trait error rust-lang#124944 implemented logic to point out when a trait bound failure involves a *trait* and *type* who come from identically named but different crates. This logic calls the `extern_crate` query which is not valid on `LOCAL_CRATE` cnum, so let's filter that out eagerly. Fixes rust-lang#130272 Fixes rust-lang#129184
2 parents e9e13a6 + 9d5d03b commit 78bceb1

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16691669
let name = self.tcx.crate_name(trait_def_id.krate);
16701670
let spans: Vec<_> = [trait_def_id, found_type]
16711671
.into_iter()
1672+
.filter(|def_id| def_id.krate != LOCAL_CRATE)
16721673
.filter_map(|def_id| self.tcx.extern_crate(def_id.krate))
16731674
.map(|data| {
16741675
let dependency = if data.dependency_of == LOCAL_CRATE {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub struct B;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ aux-build:foreign_struct_trait_unimplemented.rs
2+
3+
extern crate foreign_struct_trait_unimplemented;
4+
5+
pub trait Test {}
6+
7+
struct A;
8+
impl Test for A {}
9+
10+
fn needs_test(_: impl Test) {}
11+
12+
fn main() {
13+
needs_test(foreign_struct_trait_unimplemented::B);
14+
//~^ ERROR the trait bound `B: Test` is not satisfied
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0277]: the trait bound `B: Test` is not satisfied
2+
--> $DIR/foreign_struct_trait_unimplemented.rs:13:16
3+
|
4+
LL | needs_test(foreign_struct_trait_unimplemented::B);
5+
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Test` is not implemented for `B`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
help: there are multiple different versions of crate `foreign_struct_trait_unimplemented` in the dependency graph
10+
--> $DIR/foreign_struct_trait_unimplemented.rs:3:1
11+
|
12+
LL | extern crate foreign_struct_trait_unimplemented;
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one version of crate `foreign_struct_trait_unimplemented` is used here, as a direct dependency of the current crate
14+
= help: you can use `cargo tree` to explore your dependency tree
15+
note: required by a bound in `needs_test`
16+
--> $DIR/foreign_struct_trait_unimplemented.rs:10:23
17+
|
18+
LL | fn needs_test(_: impl Test) {}
19+
| ^^^^ required by this bound in `needs_test`
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)