forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arbitrary self types v2: generics test.
There's some discussion on the RFC about whether generic receivers should be allowed, but in the end the conclusion was that they should be blocked (at least for some definition of 'generic'). This blocking landed in an earlier PR; this commit adds additional tests to ensure the interaction with the rest of the Arbitrary Self Types v2 feature is as expected. This test may be a little duplicative but it seems better to land it than not.
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![feature(arbitrary_self_types)] | ||
|
||
struct PtrA<T>(T); | ||
|
||
impl<T> core::ops::Receiver for PtrA<T> { | ||
type Target = T; | ||
} | ||
|
||
struct PtrB<T>(T); | ||
|
||
trait SomePtr: core::ops::Receiver<Target=<Self as SomePtr>::SomeTarget> { | ||
type SomeTarget; | ||
} | ||
|
||
impl<T> SomePtr for PtrB<T> { | ||
type SomeTarget = T; | ||
} | ||
|
||
impl<T> core::ops::Receiver for PtrB<T> { | ||
type Target = T; | ||
} | ||
|
||
struct Content; | ||
|
||
impl Content { | ||
fn a<R: core::ops::Receiver<Target=Self>>(self: &R) {} | ||
//~^ ERROR invalid generic | ||
fn b<R: core::ops::Receiver<Target=Self>>(self: &mut R) {} | ||
//~^ ERROR invalid generic | ||
fn c<R: core::ops::Receiver<Target=Self>>(self: R) {} | ||
//~^ ERROR invalid generic | ||
fn d<R: SomePtr<SomeTarget=Self>>(self: R) {} | ||
//~^ ERROR invalid generic | ||
fn e(self: impl SomePtr<SomeTarget=Self>) {} | ||
//~^ 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(); | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/ui/self/arbitrary_self_types_generic_receiver.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
error[E0801]: invalid generic `self` parameter type: `&R` | ||
--> $DIR/arbitrary_self_types_generic_receiver.rs:26:53 | ||
| | ||
LL | fn a<R: core::ops::Receiver<Target=Self>>(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>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (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<R: core::ops::Receiver<Target=Self>>(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>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (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<R: core::ops::Receiver<Target=Self>>(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>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (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<R: SomePtr<SomeTarget=Self>>(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>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) | ||
|
||
error[E0801]: invalid generic `self` parameter type: `impl SomePtr<SomeTarget = Self>` | ||
--> $DIR/arbitrary_self_types_generic_receiver.rs:34:16 | ||
| | ||
LL | fn e(self: impl SomePtr<SomeTarget=Self>) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= 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>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (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`. |