rust/tests/ui/traits/trait-upcasting/replace-vptr.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
618 B
Rust
Raw Normal View History

2021-07-31 14:46:23 +00:00
//@ run-pass
#![feature(trait_upcasting)]
2021-07-31 14:46:23 +00:00
trait A {
2024-02-07 02:42:01 +00:00
fn foo_a(&self); //~ WARN method `foo_a` is never used
2021-07-31 14:46:23 +00:00
}
trait B {
fn foo_b(&self);
}
trait C: A + B {
2024-02-07 02:42:01 +00:00
fn foo_c(&self); //~ WARN method `foo_c` is never used
2021-07-31 14:46:23 +00:00
}
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);
}