Skip to content

Commit a3a43b0

Browse files
committed
Add Sizedness test
1 parent eedc229 commit a3a43b0

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(arbitrary_self_types)]
2+
3+
struct SmartPtr<'a, T: ?Sized>(&'a T);
4+
5+
// Easy mistake is to implement this for T not T: Sized
6+
impl<T> std::ops::Receiver for SmartPtr<'_, T> {
7+
type Target = T;
8+
}
9+
10+
struct A;
11+
12+
trait B {
13+
fn m(self: SmartPtr<Self>) {}
14+
//~^ ERROR: invalid `self` parameter type
15+
}
16+
17+
impl B for A {
18+
fn m(self: SmartPtr<Self>) {}
19+
}
20+
21+
fn main() {
22+
let a = A;
23+
let a = SmartPtr(&A);
24+
a.m();
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0307]: invalid `self` parameter type: `SmartPtr<'_, Self>`
2+
--> $DIR/arbitrary_self_types_sizedness_trait.rs:13:16
3+
|
4+
LL | fn m(self: SmartPtr<Self>) {}
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: type of `self` must be `Self` or some type implementing `Receiver`
8+
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0307`.

0 commit comments

Comments
 (0)