From 5594db097540d831cb7d98a662c7f3df7011411b Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 25 Apr 2022 08:51:26 +0200 Subject: [PATCH] do not consider two extern types to be similar --- .../src/traits/error_reporting/mod.rs | 1 + .../ui/extern/extern-type-diag-not-similar.rs | 22 +++++++++++++++++++ .../extern-type-diag-not-similar.stderr | 16 ++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/test/ui/extern/extern-type-diag-not-similar.rs create mode 100644 src/test/ui/extern/extern-type-diag-not-similar.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 50e4fafdd6c82..082402a38e3f5 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1727,6 +1727,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { } else if cat_a == cat_b { match (a.kind(), b.kind()) { (ty::Adt(def_a, _), ty::Adt(def_b, _)) => def_a == def_b, + (ty::Foreign(def_a), ty::Foreign(def_b)) => def_a == def_b, // Matching on references results in a lot of unhelpful // suggestions, so let's just not do that for now. // diff --git a/src/test/ui/extern/extern-type-diag-not-similar.rs b/src/test/ui/extern/extern-type-diag-not-similar.rs new file mode 100644 index 0000000000000..39d00a6c1bc31 --- /dev/null +++ b/src/test/ui/extern/extern-type-diag-not-similar.rs @@ -0,0 +1,22 @@ +// We previously mentioned other extern types in the error message here. +// +// Two extern types shouldn't really be considered similar just +// because they are both extern types. + +#![feature(extern_types)] +extern { + type ShouldNotBeMentioned; +} + +extern { + type Foo; +} + +unsafe impl Send for ShouldNotBeMentioned {} + +fn assert_send() {} + +fn main() { + assert_send::() + //~^ ERROR `Foo` cannot be sent between threads safely +} diff --git a/src/test/ui/extern/extern-type-diag-not-similar.stderr b/src/test/ui/extern/extern-type-diag-not-similar.stderr new file mode 100644 index 0000000000000..75836f7eca19c --- /dev/null +++ b/src/test/ui/extern/extern-type-diag-not-similar.stderr @@ -0,0 +1,16 @@ +error[E0277]: `Foo` cannot be sent between threads safely + --> $DIR/extern-type-diag-not-similar.rs:20:19 + | +LL | assert_send::() + | ^^^ `Foo` cannot be sent between threads safely + | + = help: the trait `Send` is not implemented for `Foo` +note: required by a bound in `assert_send` + --> $DIR/extern-type-diag-not-similar.rs:17:19 + | +LL | fn assert_send() {} + | ^^^^ required by this bound in `assert_send` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.