Skip to content

Commit 2f0208c

Browse files
committed
test for upcast detecting bad vtables
1 parent 84fb962 commit 2f0208c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#![feature(trait_upcasting)]
2+
#![allow(incomplete_features)]
3+
4+
trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
5+
fn a(&self) -> i32 {
6+
10
7+
}
8+
9+
fn z(&self) -> i32 {
10+
11
11+
}
12+
13+
fn y(&self) -> i32 {
14+
12
15+
}
16+
}
17+
18+
trait Bar: Foo {
19+
fn b(&self) -> i32 {
20+
20
21+
}
22+
23+
fn w(&self) -> i32 {
24+
21
25+
}
26+
}
27+
28+
trait Baz: Bar {
29+
fn c(&self) -> i32 {
30+
30
31+
}
32+
}
33+
34+
impl Foo for i32 {
35+
fn a(&self) -> i32 {
36+
100
37+
}
38+
}
39+
40+
impl Bar for i32 {
41+
fn b(&self) -> i32 {
42+
200
43+
}
44+
}
45+
46+
impl Baz for i32 {
47+
fn c(&self) -> i32 {
48+
300
49+
}
50+
}
51+
52+
fn main() {
53+
let baz: &dyn Baz = &1;
54+
let baz_fake: &dyn Bar = unsafe { std::mem::transmute(baz) };
55+
let _: &dyn std::fmt::Debug = baz_fake; //~ERROR upcast on a pointer whose vtable does not match its type
56+
}

0 commit comments

Comments
 (0)