about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCharles Lew <crlf0710@gmail.com>2021-07-31 22:46:23 +0800
committerCharles Lew <crlf0710@gmail.com>2021-08-03 01:09:37 +0800
commit63ed62531324cd4660deb7faff58e6c17b93b487 (patch)
tree8e2743bf8f7a120bdff376a45e9f21d396414837 /src
parent7069a8c2b78c5d23205de1cabb4c2a65229dbd8f (diff)
downloadrust-63ed62531324cd4660deb7faff58e6c17b93b487.tar.gz
rust-63ed62531324cd4660deb7faff58e6c17b93b487.zip
Implement pointer casting.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/traits/trait-upcasting/replace-vptr.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/test/ui/traits/trait-upcasting/replace-vptr.rs b/src/test/ui/traits/trait-upcasting/replace-vptr.rs
new file mode 100644
index 00000000000..1164e43611a
--- /dev/null
+++ b/src/test/ui/traits/trait-upcasting/replace-vptr.rs
@@ -0,0 +1,49 @@
+// run-pass
+
+#![feature(trait_upcasting)]
+#![allow(incomplete_features)]
+
+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);
+}