summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/trait-upcasting/replace-vptr.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/traits/trait-upcasting/replace-vptr.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/traits/trait-upcasting/replace-vptr.rs')
-rw-r--r--tests/ui/traits/trait-upcasting/replace-vptr.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/ui/traits/trait-upcasting/replace-vptr.rs b/tests/ui/traits/trait-upcasting/replace-vptr.rs
new file mode 100644
index 000000000..9ccfc9306
--- /dev/null
+++ b/tests/ui/traits/trait-upcasting/replace-vptr.rs
@@ -0,0 +1,48 @@
+// run-pass
+
+#![feature(trait_upcasting)]
+
+trait A {
+ fn foo_a(&self);
+}
+
+trait B {
+ fn foo_b(&self);
+}
+
+trait C: A + B {
+ fn foo_c(&self);
+}
+
+struct S(i32);
+
+impl A for S {
+ fn foo_a(&self) {
+ unreachable!();
+ }
+}
+
+impl B for S {
+ fn foo_b(&self) {
+ assert_eq!(42, self.0);
+ }
+}
+
+impl C for S {
+ fn foo_c(&self) {
+ unreachable!();
+ }
+}
+
+fn invoke_inner(b: &dyn B) {
+ b.foo_b();
+}
+
+fn invoke_outer(c: &dyn C) {
+ invoke_inner(c);
+}
+
+fn main() {
+ let s = S(42);
+ invoke_outer(&s);
+}