diff --git a/library/core/src/ops/deref.rs b/library/core/src/ops/deref.rs index 58bf0e2d73b97..1003edad24484 100644 --- a/library/core/src/ops/deref.rs +++ b/library/core/src/ops/deref.rs @@ -367,6 +367,7 @@ unsafe impl DerefPure for &mut T {} /// ``` #[lang = "receiver"] #[unstable(feature = "arbitrary_self_types", issue = "44874")] +#[rustc_dyn_incompatible_trait] pub trait Receiver: PointeeSized { /// The target type on which the method may be called. #[rustc_diagnostic_item = "receiver_target"] diff --git a/tests/ui/self/arbitrary-self-types-dyn-receiver.rs b/tests/ui/self/arbitrary-self-types-dyn-receiver.rs index fe128301d497a..3be08611c9e22 100644 --- a/tests/ui/self/arbitrary-self-types-dyn-receiver.rs +++ b/tests/ui/self/arbitrary-self-types-dyn-receiver.rs @@ -1,15 +1,20 @@ -//@ run-pass +//@ check-fail #![feature(arbitrary_self_types)] use std::ops::Receiver; trait Trait { fn foo(self: &dyn Receiver); + //~^ ERROR: the trait `std::ops::Receiver` is not dyn compatible + //~| ERROR: the trait `std::ops::Receiver` is not dyn compatible } struct Thing; impl Trait for Thing { fn foo(self: &dyn Receiver) { + //~^ ERROR: the trait `std::ops::Receiver` is not dyn compatible + //~| ERROR: the trait `std::ops::Receiver` is not dyn compatible + //~| ERROR: the trait `std::ops::Receiver` is not dyn compatible println!("huh???"); } } @@ -17,5 +22,6 @@ impl Trait for Thing { fn main() { let x = Box::new(Thing); let y: &dyn Receiver = &x; + //~^ ERROR: the trait `std::ops::Receiver` is not dyn compatible y.foo(); } diff --git a/tests/ui/self/arbitrary-self-types-dyn-receiver.stderr b/tests/ui/self/arbitrary-self-types-dyn-receiver.stderr new file mode 100644 index 0000000000000..24acb56ffb1b3 --- /dev/null +++ b/tests/ui/self/arbitrary-self-types-dyn-receiver.stderr @@ -0,0 +1,85 @@ +error[E0038]: the trait `std::ops::Receiver` is not dyn compatible + --> $DIR/arbitrary-self-types-dyn-receiver.rs:14:5 + | +LL | fn foo(self: &dyn Receiver) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::ops::Receiver` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $SRC_DIR/core/src/ops/deref.rs:LL:COL + | + = note: the trait is not dyn compatible because it opted out of dyn-compatibility + +error[E0038]: the trait `std::ops::Receiver` is not dyn compatible + --> $DIR/arbitrary-self-types-dyn-receiver.rs:14:18 + | +LL | fn foo(self: &dyn Receiver) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::ops::Receiver` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $SRC_DIR/core/src/ops/deref.rs:LL:COL + | + = note: the trait is not dyn compatible because it opted out of dyn-compatibility + +error[E0038]: the trait `std::ops::Receiver` is not dyn compatible + --> $DIR/arbitrary-self-types-dyn-receiver.rs:14:19 + | +LL | fn foo(self: &dyn Receiver) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ `std::ops::Receiver` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $SRC_DIR/core/src/ops/deref.rs:LL:COL + | + = note: the trait is not dyn compatible because it opted out of dyn-compatibility +help: you might have meant to use `Self` to refer to the implementing type + | +LL - fn foo(self: &dyn Receiver) { +LL + fn foo(self: &Self) { + | + +error[E0038]: the trait `std::ops::Receiver` is not dyn compatible + --> $DIR/arbitrary-self-types-dyn-receiver.rs:7:18 + | +LL | fn foo(self: &dyn Receiver); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::ops::Receiver` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $SRC_DIR/core/src/ops/deref.rs:LL:COL + | + = note: the trait is not dyn compatible because it opted out of dyn-compatibility + +error[E0038]: the trait `std::ops::Receiver` is not dyn compatible + --> $DIR/arbitrary-self-types-dyn-receiver.rs:7:19 + | +LL | fn foo(self: &dyn Receiver); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ `std::ops::Receiver` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $SRC_DIR/core/src/ops/deref.rs:LL:COL + | + = note: the trait is not dyn compatible because it opted out of dyn-compatibility +help: you might have meant to use `Self` to refer to the implementing type + | +LL - fn foo(self: &dyn Receiver); +LL + fn foo(self: &Self); + | + +error[E0038]: the trait `std::ops::Receiver` is not dyn compatible + --> $DIR/arbitrary-self-types-dyn-receiver.rs:24:17 + | +LL | let y: &dyn Receiver = &x; + | ^^^^^^^^^^^^^^^^^^^^^^ `std::ops::Receiver` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $SRC_DIR/core/src/ops/deref.rs:LL:COL + | + = note: the trait is not dyn compatible because it opted out of dyn-compatibility + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0038`.