Implement pointer casting.
This commit is contained in:
parent
7069a8c2b7
commit
63ed625313
11 changed files with 256 additions and 88 deletions
49
src/test/ui/traits/trait-upcasting/replace-vptr.rs
Normal file
49
src/test/ui/traits/trait-upcasting/replace-vptr.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue