summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/vtable
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /tests/ui/traits/vtable
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/traits/vtable')
-rw-r--r--tests/ui/traits/vtable/multiple-markers.rs47
-rw-r--r--tests/ui/traits/vtable/multiple-markers.stderr52
2 files changed, 99 insertions, 0 deletions
diff --git a/tests/ui/traits/vtable/multiple-markers.rs b/tests/ui/traits/vtable/multiple-markers.rs
new file mode 100644
index 000000000..1e6e30870
--- /dev/null
+++ b/tests/ui/traits/vtable/multiple-markers.rs
@@ -0,0 +1,47 @@
+// Regression test for <https://github.com/rust-lang/rust/issues/113840>
+//
+// This test makes sure that multiple marker (method-less) traits can reuse the
+// same pointer for upcasting.
+//
+// build-fail
+#![crate_type = "lib"]
+#![feature(rustc_attrs)]
+
+// Markers
+trait M0 {}
+trait M1 {}
+trait M2 {}
+
+// Just a trait with a method
+trait T {
+ fn method(&self) {}
+}
+
+#[rustc_dump_vtable]
+trait A: M0 + M1 + M2 + T {} //~ error: vtable entries for `<S as A>`:
+
+#[rustc_dump_vtable]
+trait B: M0 + M1 + T + M2 {} //~ error: vtable entries for `<S as B>`:
+
+#[rustc_dump_vtable]
+trait C: M0 + T + M1 + M2 {} //~ error: vtable entries for `<S as C>`:
+
+#[rustc_dump_vtable]
+trait D: T + M0 + M1 + M2 {} //~ error: vtable entries for `<S as D>`:
+
+struct S;
+
+impl M0 for S {}
+impl M1 for S {}
+impl M2 for S {}
+impl T for S {}
+impl A for S {}
+impl B for S {}
+impl C for S {}
+impl D for S {}
+
+pub fn require_vtables() {
+ fn require_vtables(_: &dyn A, _: &dyn B, _: &dyn C, _: &dyn D) {}
+
+ require_vtables(&S, &S, &S, &S)
+}
diff --git a/tests/ui/traits/vtable/multiple-markers.stderr b/tests/ui/traits/vtable/multiple-markers.stderr
new file mode 100644
index 000000000..4497c703a
--- /dev/null
+++ b/tests/ui/traits/vtable/multiple-markers.stderr
@@ -0,0 +1,52 @@
+error: vtable entries for `<S as A>`: [
+ MetadataDropInPlace,
+ MetadataSize,
+ MetadataAlign,
+ Method(<S as T>::method),
+ ]
+ --> $DIR/multiple-markers.rs:21:1
+ |
+LL | trait A: M0 + M1 + M2 + T {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: vtable entries for `<S as B>`: [
+ MetadataDropInPlace,
+ MetadataSize,
+ MetadataAlign,
+ Method(<S as T>::method),
+ TraitVPtr(<S as M2>),
+ ]
+ --> $DIR/multiple-markers.rs:24:1
+ |
+LL | trait B: M0 + M1 + T + M2 {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: vtable entries for `<S as C>`: [
+ MetadataDropInPlace,
+ MetadataSize,
+ MetadataAlign,
+ Method(<S as T>::method),
+ TraitVPtr(<S as M1>),
+ TraitVPtr(<S as M2>),
+ ]
+ --> $DIR/multiple-markers.rs:27:1
+ |
+LL | trait C: M0 + T + M1 + M2 {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: vtable entries for `<S as D>`: [
+ MetadataDropInPlace,
+ MetadataSize,
+ MetadataAlign,
+ Method(<S as T>::method),
+ TraitVPtr(<S as M0>),
+ TraitVPtr(<S as M1>),
+ TraitVPtr(<S as M2>),
+ ]
+ --> $DIR/multiple-markers.rs:30:1
+ |
+LL | trait D: T + M0 + M1 + M2 {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
+