Skip to content

Commit b5d1228

Browse files
committed
Add a (failing test) for issue 113840
1 parent f33936c commit b5d1228

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/113840>
2+
//
3+
// This test makes sure that multiple marker (method-less) traits can reuse the
4+
// same pointer for upcasting.
5+
//
6+
// build-fail
7+
#![crate_type = "lib"]
8+
#![feature(rustc_attrs)]
9+
10+
// Markers
11+
trait M0 {}
12+
trait M1 {}
13+
trait M2 {}
14+
15+
// Just a trait with a method
16+
trait T {
17+
fn method(&self) {}
18+
}
19+
20+
#[rustc_dump_vtable]
21+
trait A: M0 + M1 + M2 + T {} //~ error: vtable entries for `<S as A>`:
22+
23+
#[rustc_dump_vtable]
24+
trait B: M0 + M1 + T + M2 {} //~ error: vtable entries for `<S as B>`:
25+
26+
#[rustc_dump_vtable]
27+
trait C: M0 + T + M1 + M2 {} //~ error: vtable entries for `<S as C>`:
28+
29+
#[rustc_dump_vtable]
30+
trait D: T + M0 + M1 + M2 {} //~ error: vtable entries for `<S as D>`:
31+
32+
struct S;
33+
34+
impl M0 for S {}
35+
impl M1 for S {}
36+
impl M2 for S {}
37+
impl T for S {}
38+
impl A for S {}
39+
impl B for S {}
40+
impl C for S {}
41+
impl D for S {}
42+
43+
pub fn require_vtables() {
44+
fn require_vtables(_: &dyn A, _: &dyn B, _: &dyn C, _: &dyn D) {}
45+
46+
require_vtables(&S, &S, &S, &S)
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
error: vtable entries for `<S as A>`: [
2+
MetadataDropInPlace,
3+
MetadataSize,
4+
MetadataAlign,
5+
TraitVPtr(<S as M1>),
6+
TraitVPtr(<S as M2>),
7+
Method(<S as T>::method),
8+
TraitVPtr(<S as T>),
9+
]
10+
--> $DIR/multiple-markers.rs:21:1
11+
|
12+
LL | trait A: M0 + M1 + M2 + T {}
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: vtable entries for `<S as B>`: [
16+
MetadataDropInPlace,
17+
MetadataSize,
18+
MetadataAlign,
19+
TraitVPtr(<S as M1>),
20+
Method(<S as T>::method),
21+
TraitVPtr(<S as T>),
22+
TraitVPtr(<S as M2>),
23+
]
24+
--> $DIR/multiple-markers.rs:24:1
25+
|
26+
LL | trait B: M0 + M1 + T + M2 {}
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
28+
29+
error: vtable entries for `<S as C>`: [
30+
MetadataDropInPlace,
31+
MetadataSize,
32+
MetadataAlign,
33+
Method(<S as T>::method),
34+
TraitVPtr(<S as T>),
35+
TraitVPtr(<S as M1>),
36+
TraitVPtr(<S as M2>),
37+
]
38+
--> $DIR/multiple-markers.rs:27:1
39+
|
40+
LL | trait C: M0 + T + M1 + M2 {}
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
42+
43+
error: vtable entries for `<S as D>`: [
44+
MetadataDropInPlace,
45+
MetadataSize,
46+
MetadataAlign,
47+
Method(<S as T>::method),
48+
TraitVPtr(<S as M0>),
49+
TraitVPtr(<S as M1>),
50+
TraitVPtr(<S as M2>),
51+
]
52+
--> $DIR/multiple-markers.rs:30:1
53+
|
54+
LL | trait D: T + M0 + M1 + M2 {}
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
56+
57+
error: aborting due to 4 previous errors
58+

0 commit comments

Comments
 (0)