rust/tests/ui/traits/trait-upcasting/replace-vptr.rs
Urgau 4c2d6de70e Stabilize RFC3324 dyn upcasting coercion
Aka trait_upcasting feature.

And also adjust the `deref_into_dyn_supertrait` lint.
2023-11-22 13:56:36 +01:00

47 lines
511 B
Rust

// run-pass
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);
}