Skip to content

Commit a144333

Browse files
Alexander Regueirocrlf0710
Alexander Regueiro
authored andcommitted
Added tests.
1 parent b867376 commit a144333

10 files changed

+764
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// run-pass
2+
3+
#![feature(trait_upcasting)]
4+
5+
trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
6+
fn a(&self) -> i32 { 10 }
7+
8+
fn z(&self) -> i32 { 11 }
9+
10+
fn y(&self) -> i32 { 12 }
11+
}
12+
13+
trait Bar: Foo {
14+
fn b(&self) -> i32 { 20 }
15+
16+
fn w(&self) -> i32 { 21 }
17+
}
18+
19+
trait Baz: Bar {
20+
fn c(&self) -> i32 { 30 }
21+
}
22+
23+
impl Foo for i32 {
24+
fn a(&self) -> i32 { 100 }
25+
}
26+
27+
impl Bar for i32 {
28+
fn b(&self) -> i32 { 200 }
29+
}
30+
31+
impl Baz for i32 {
32+
fn c(&self) -> i32 { 300 }
33+
}
34+
35+
fn main() {
36+
let baz: &dyn Baz = &1;
37+
let _: &dyn std::fmt::Debug = baz;
38+
let _: &(dyn Send + Sync) = baz;
39+
let _: &dyn Send = baz;
40+
let _: &dyn Sync = baz;
41+
assert_eq!(*baz, 1);
42+
assert_eq!(baz.a(), 100);
43+
assert_eq!(baz.b(), 200);
44+
assert_eq!(baz.c(), 300);
45+
assert_eq!(baz.z(), 11);
46+
assert_eq!(baz.y(), 12);
47+
assert_eq!(baz.w(), 21);
48+
49+
let bar: &dyn Bar = baz;
50+
let _: &dyn std::fmt::Debug = bar;
51+
let _: &(dyn Send + Sync) = bar;
52+
let _: &dyn Send = bar;
53+
let _: &dyn Sync = bar;
54+
assert_eq!(*bar, 1);
55+
assert_eq!(bar.a(), 100);
56+
assert_eq!(bar.b(), 200);
57+
assert_eq!(bar.z(), 11);
58+
assert_eq!(bar.y(), 12);
59+
assert_eq!(bar.w(), 21);
60+
61+
let foo: &dyn Foo = baz;
62+
let _: &dyn std::fmt::Debug = foo;
63+
let _: &(dyn Send + Sync) = foo;
64+
let _: &dyn Send = foo;
65+
let _: &dyn Sync = foo;
66+
assert_eq!(*foo, 1);
67+
assert_eq!(foo.a(), 100);
68+
assert_eq!(foo.z(), 11);
69+
assert_eq!(foo.y(), 12);
70+
71+
let foo: &dyn Foo = bar;
72+
let _: &dyn std::fmt::Debug = foo;
73+
let _: &(dyn Send + Sync) = foo;
74+
let _: &dyn Send = foo;
75+
let _: &dyn Sync = foo;
76+
assert_eq!(*foo, 1);
77+
assert_eq!(foo.a(), 100);
78+
assert_eq!(foo.z(), 11);
79+
assert_eq!(foo.y(), 12);
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait A: B + A {}
2+
//~^ ERROR cycle detected when computing the supertraits of `A` [E0391]
3+
4+
trait B {}
5+
6+
impl A for () {}
7+
8+
impl B for () {}
9+
10+
fn main() {
11+
let a: Box<dyn A> = Box::new(());
12+
let _b: Box<dyn B> = a;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0391]: cycle detected when computing the supertraits of `A`
2+
--> $DIR/cyclic-trait-resolution.rs:1:14
3+
|
4+
LL | trait A: B + A {}
5+
| ^
6+
|
7+
= note: ...which again requires computing the supertraits of `A`, completing the cycle
8+
note: cycle used when collecting item types in top-level module
9+
--> $DIR/cyclic-trait-resolution.rs:1:1
10+
|
11+
LL | trait A: B + A {}
12+
| ^^^^^^^^^^^^^^
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0391`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// run-pass
2+
3+
#![feature(trait_upcasting)]
4+
5+
trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
6+
fn a(&self) -> i32 { 10 }
7+
8+
fn z(&self) -> i32 { 11 }
9+
10+
fn y(&self) -> i32 { 12 }
11+
}
12+
13+
trait Bar1: Foo {
14+
fn b(&self) -> i32 { 20 }
15+
16+
fn w(&self) -> i32 { 21 }
17+
}
18+
19+
trait Bar2: Foo {
20+
fn c(&self) -> i32 { 30 }
21+
22+
fn v(&self) -> i32 { 31 }
23+
}
24+
25+
trait Baz: Bar1 + Bar2 {
26+
fn d(&self) -> i32 { 40 }
27+
}
28+
29+
impl Foo for i32 {
30+
fn a(&self) -> i32 { 100 }
31+
}
32+
33+
impl Bar1 for i32 {
34+
fn b(&self) -> i32 { 200 }
35+
}
36+
37+
impl Bar2 for i32 {
38+
fn c(&self) -> i32 { 300 }
39+
}
40+
41+
impl Baz for i32 {
42+
fn d(&self) -> i32 { 400 }
43+
}
44+
45+
fn main() {
46+
let baz: &dyn Baz = &1;
47+
let _: &dyn std::fmt::Debug = baz;
48+
let _: &(dyn Send + Sync) = baz;
49+
let _: &dyn Send = baz;
50+
let _: &dyn Sync = baz;
51+
assert_eq!(*baz, 1);
52+
assert_eq!(baz.a(), 100);
53+
assert_eq!(baz.b(), 200);
54+
assert_eq!(baz.c(), 300);
55+
assert_eq!(baz.d(), 400);
56+
assert_eq!(baz.z(), 11);
57+
assert_eq!(baz.y(), 12);
58+
assert_eq!(baz.w(), 21);
59+
assert_eq!(baz.v(), 31);
60+
61+
let bar1: &dyn Bar1 = baz;
62+
let _: &dyn std::fmt::Debug = bar1;
63+
let _: &(dyn Send + Sync) = bar1;
64+
let _: &dyn Send = bar1;
65+
let _: &dyn Sync = bar1;
66+
assert_eq!(*bar1, 1);
67+
assert_eq!(bar1.a(), 100);
68+
assert_eq!(bar1.b(), 200);
69+
assert_eq!(bar1.z(), 11);
70+
assert_eq!(bar1.y(), 12);
71+
assert_eq!(bar1.w(), 21);
72+
73+
let bar2: &dyn Bar2 = baz;
74+
let _: &dyn std::fmt::Debug = bar2;
75+
let _: &(dyn Send + Sync) = bar2;
76+
let _: &dyn Send = bar2;
77+
let _: &dyn Sync = bar2;
78+
assert_eq!(*bar2, 1);
79+
assert_eq!(bar2.a(), 100);
80+
assert_eq!(bar2.c(), 300);
81+
assert_eq!(bar2.z(), 11);
82+
assert_eq!(bar2.y(), 12);
83+
assert_eq!(bar2.v(), 31);
84+
85+
let foo: &dyn Foo = baz;
86+
let _: &dyn std::fmt::Debug = foo;
87+
let _: &(dyn Send + Sync) = foo;
88+
let _: &dyn Send = foo;
89+
let _: &dyn Sync = foo;
90+
assert_eq!(*foo, 1);
91+
assert_eq!(foo.a(), 100);
92+
93+
let foo: &dyn Foo = bar1;
94+
let _: &dyn std::fmt::Debug = foo;
95+
let _: &(dyn Send + Sync) = foo;
96+
let _: &dyn Send = foo;
97+
let _: &dyn Sync = foo;
98+
assert_eq!(*foo, 1);
99+
assert_eq!(foo.a(), 100);
100+
101+
let foo: &dyn Foo = bar2;
102+
let _: &dyn std::fmt::Debug = foo;
103+
let _: &(dyn Send + Sync) = foo;
104+
let _: &dyn Send = foo;
105+
let _: &dyn Sync = foo;
106+
assert_eq!(*foo, 1);
107+
assert_eq!(foo.a(), 100);
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#![feature(trait_upcasting)]
2+
3+
trait Foo {
4+
fn a(&self) -> i32 { 10 }
5+
6+
fn z(&self) -> i32 { 11 }
7+
8+
fn y(&self) -> i32 { 12 }
9+
}
10+
11+
trait Bar {
12+
fn b(&self) -> i32 { 20 }
13+
14+
fn w(&self) -> i32 { 21 }
15+
}
16+
17+
trait Baz {
18+
fn c(&self) -> i32 { 30 }
19+
}
20+
21+
impl Foo for i32 {
22+
fn a(&self) -> i32 { 100 }
23+
}
24+
25+
impl Bar for i32 {
26+
fn b(&self) -> i32 { 200 }
27+
}
28+
29+
impl Baz for i32 {
30+
fn c(&self) -> i32 { 300 }
31+
}
32+
33+
fn main() {
34+
let baz: &dyn Baz = &1;
35+
let _: &dyn std::fmt::Debug = baz;
36+
//~^ ERROR `dyn Baz` doesn't implement `std::fmt::Debug` [E0277]
37+
let _: &dyn Send = baz;
38+
//~^ ERROR `dyn Baz` cannot be sent between threads safely [E0277]
39+
let _: &dyn Sync = baz;
40+
//~^ ERROR `dyn Baz` cannot be shared between threads safely [E0277]
41+
42+
let bar: &dyn Bar = baz;
43+
//~^ ERROR the trait bound `dyn Baz: Bar` is not satisfied [E0277]
44+
let _: &dyn std::fmt::Debug = bar;
45+
//~^ ERROR `dyn Bar` doesn't implement `std::fmt::Debug` [E0277]
46+
let _: &dyn Send = bar;
47+
//~^ ERROR `dyn Bar` cannot be sent between threads safely [E0277]
48+
let _: &dyn Sync = bar;
49+
//~^ ERROR `dyn Bar` cannot be shared between threads safely [E0277]
50+
51+
let foo: &dyn Foo = baz;
52+
//~^ ERROR the trait bound `dyn Baz: Foo` is not satisfied [E0277]
53+
let _: &dyn std::fmt::Debug = foo;
54+
//~^ ERROR `dyn Foo` doesn't implement `std::fmt::Debug` [E0277]
55+
let _: &dyn Send = foo;
56+
//~^ ERROR `dyn Foo` cannot be sent between threads safely [E0277]
57+
let _: &dyn Sync = foo;
58+
//~^ ERROR `dyn Foo` cannot be shared between threads safely [E0277]
59+
60+
let foo: &dyn Foo = bar;
61+
//~^ ERROR the trait bound `dyn Bar: Foo` is not satisfied [E0277]
62+
let _: &dyn std::fmt::Debug = foo;
63+
//~^ ERROR `dyn Foo` doesn't implement `std::fmt::Debug` [E0277]
64+
let _: &dyn Send = foo;
65+
//~^ ERROR `dyn Foo` cannot be sent between threads safely [E0277]
66+
let _: &dyn Sync = foo;
67+
//~^ ERROR `dyn Foo` cannot be shared between threads safely [E0277]
68+
}

0 commit comments

Comments
 (0)