Skip to content

Commit 0f11c81

Browse files
Rollup merge of #96384 - lcnr:extern-types-similar, r=compiler-errors
do not consider two extern types to be similar
2 parents 0a869c3 + 5594db0 commit 0f11c81

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
17271727
} else if cat_a == cat_b {
17281728
match (a.kind(), b.kind()) {
17291729
(ty::Adt(def_a, _), ty::Adt(def_b, _)) => def_a == def_b,
1730+
(ty::Foreign(def_a), ty::Foreign(def_b)) => def_a == def_b,
17301731
// Matching on references results in a lot of unhelpful
17311732
// suggestions, so let's just not do that for now.
17321733
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// We previously mentioned other extern types in the error message here.
2+
//
3+
// Two extern types shouldn't really be considered similar just
4+
// because they are both extern types.
5+
6+
#![feature(extern_types)]
7+
extern {
8+
type ShouldNotBeMentioned;
9+
}
10+
11+
extern {
12+
type Foo;
13+
}
14+
15+
unsafe impl Send for ShouldNotBeMentioned {}
16+
17+
fn assert_send<T: Send + ?Sized>() {}
18+
19+
fn main() {
20+
assert_send::<Foo>()
21+
//~^ ERROR `Foo` cannot be sent between threads safely
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: `Foo` cannot be sent between threads safely
2+
--> $DIR/extern-type-diag-not-similar.rs:20:19
3+
|
4+
LL | assert_send::<Foo>()
5+
| ^^^ `Foo` cannot be sent between threads safely
6+
|
7+
= help: the trait `Send` is not implemented for `Foo`
8+
note: required by a bound in `assert_send`
9+
--> $DIR/extern-type-diag-not-similar.rs:17:19
10+
|
11+
LL | fn assert_send<T: Send + ?Sized>() {}
12+
| ^^^^ required by this bound in `assert_send`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)