diff --git a/tests/ui/self/arbitrary_self_types_generic_receiver.rs b/tests/ui/self/arbitrary_self_types_generic_receiver.rs new file mode 100644 index 000000000000..0739fb778b60 --- /dev/null +++ b/tests/ui/self/arbitrary_self_types_generic_receiver.rs @@ -0,0 +1,50 @@ +#![feature(arbitrary_self_types)] + +struct PtrA(T); + +impl core::ops::Receiver for PtrA { + type Target = T; +} + +struct PtrB(T); + +trait SomePtr: core::ops::Receiver::SomeTarget> { + type SomeTarget; +} + +impl SomePtr for PtrB { + type SomeTarget = T; +} + +impl core::ops::Receiver for PtrB { + type Target = T; +} + +struct Content; + +impl Content { + fn a>(self: &R) {} + //~^ ERROR invalid generic + fn b>(self: &mut R) {} + //~^ ERROR invalid generic + fn c>(self: R) {} + //~^ ERROR invalid generic + fn d>(self: R) {} + //~^ ERROR invalid generic + fn e(self: impl SomePtr) {} + //~^ ERROR invalid generic +} + +fn main() { + PtrA(Content).a(); + PtrA(Content).b(); + PtrA(Content).c(); + std::rc::Rc::new(Content).a(); + std::rc::Rc::new(Content).b(); + std::rc::Rc::new(Content).c(); + PtrB(Content).a(); + PtrB(Content).b(); + PtrB(Content).c(); + PtrB(Content).d(); + PtrB(Content).e(); +} diff --git a/tests/ui/self/arbitrary_self_types_generic_receiver.stderr b/tests/ui/self/arbitrary_self_types_generic_receiver.stderr new file mode 100644 index 000000000000..788c55ea2f1c --- /dev/null +++ b/tests/ui/self/arbitrary_self_types_generic_receiver.stderr @@ -0,0 +1,48 @@ +error[E0801]: invalid generic `self` parameter type: `&R` + --> $DIR/arbitrary_self_types_generic_receiver.rs:26:53 + | +LL | fn a>(self: &R) {} + | ^^ + | + = note: type of `self` must not be a method generic parameter type + = help: use a concrete type such as `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error[E0801]: invalid generic `self` parameter type: `&mut R` + --> $DIR/arbitrary_self_types_generic_receiver.rs:28:53 + | +LL | fn b>(self: &mut R) {} + | ^^^^^^ + | + = note: type of `self` must not be a method generic parameter type + = help: use a concrete type such as `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error[E0801]: invalid generic `self` parameter type: `R` + --> $DIR/arbitrary_self_types_generic_receiver.rs:30:53 + | +LL | fn c>(self: R) {} + | ^ + | + = note: type of `self` must not be a method generic parameter type + = help: use a concrete type such as `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error[E0801]: invalid generic `self` parameter type: `R` + --> $DIR/arbitrary_self_types_generic_receiver.rs:32:45 + | +LL | fn d>(self: R) {} + | ^ + | + = note: type of `self` must not be a method generic parameter type + = help: use a concrete type such as `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error[E0801]: invalid generic `self` parameter type: `impl SomePtr` + --> $DIR/arbitrary_self_types_generic_receiver.rs:34:16 + | +LL | fn e(self: impl SomePtr) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: type of `self` must not be a method generic parameter type + = help: use a concrete type such as `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0801`.