Skip to content

Commit edc8c76

Browse files
committed
add tests for the arbitrary_self_types, which won't pass yet
1 parent 7ade24f commit edc8c76

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(arbitrary_self_types)]
2+
3+
use std::rc::Rc;
4+
5+
struct Foo;
6+
7+
impl Foo {
8+
fn foo(self: Rc<Self>) {} //~ ERROR arbitrary self types are only allowed for trait methods
9+
}
10+
11+
fn main() {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![feature(arbitrary_self_types)]
2+
3+
use std::rc::Rc;
4+
5+
trait Foo {
6+
fn foo(self: Rc<Self>) -> usize;
7+
}
8+
9+
trait Bar {
10+
fn foo(self: Rc<Self>) -> usize where Self: Sized;
11+
fn bar(self: Box<Self>) -> usize;
12+
}
13+
14+
impl Foo for usize {
15+
fn foo(self: Rc<Self>) -> usize {
16+
*self
17+
}
18+
}
19+
20+
impl Bar for usize {
21+
fn foo(self: Rc<Self>) -> usize {
22+
*self
23+
}
24+
25+
fn bar(self: Box<Self>) -> usize {
26+
*self
27+
}
28+
}
29+
30+
fn make_foo() {
31+
let x = Box::new(5usize) as Box<Foo>;
32+
//~^ ERROR E0038
33+
//~| NOTE the method `foo` has an arbitrary self type
34+
//~| NOTE the trait `Foo` cannot be made into an object
35+
}
36+
37+
fn make_bar() {
38+
let x = Box::new(5usize) as Box<Bar>;
39+
x.bar();
40+
}
41+
42+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::rc::Rc;
2+
3+
trait Foo {
4+
fn foo(self: Rc<Box<Self>>); //~ ERROR arbitrary self types are unstable
5+
}
6+
7+
struct Bar;
8+
9+
impl Foo for Bar {
10+
fn foo(self: Rc<Box<Self>>) {} //~ ERROR arbitrary self types are unstable
11+
}
12+
13+
impl Bar {
14+
fn bar(self: Box<Rc<Self>>) {} //~ ERROR arbitrary self types are unstable
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)