rust/tests/ui/traits/trait-upcasting/subtrait-method.rs

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

70 lines
1.2 KiB
Rust
Raw Normal View History

2019-11-04 20:18:39 -06:00
#![feature(trait_upcasting)]
trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
fn a(&self) -> i32 {
10
}
2019-11-04 20:18:39 -06:00
fn z(&self) -> i32 {
11
}
2019-11-04 20:18:39 -06:00
fn y(&self) -> i32 {
12
}
2019-11-04 20:18:39 -06:00
}
trait Bar: Foo {
fn b(&self) -> i32 {
20
}
2019-11-04 20:18:39 -06:00
fn w(&self) -> i32 {
21
}
2019-11-04 20:18:39 -06:00
}
trait Baz: Bar {
fn c(&self) -> i32 {
30
}
2019-11-04 20:18:39 -06:00
}
impl Foo for i32 {
fn a(&self) -> i32 {
100
}
2019-11-04 20:18:39 -06:00
}
impl Bar for i32 {
fn b(&self) -> i32 {
200
}
2019-11-04 20:18:39 -06:00
}
impl Baz for i32 {
fn c(&self) -> i32 {
300
}
2019-11-04 20:18:39 -06:00
}
fn main() {
let baz: &dyn Baz = &1;
let bar: &dyn Bar = baz;
bar.c();
//~^ ERROR no method named `c` found for reference `&dyn Bar` in the current scope [E0599]
let foo: &dyn Foo = baz;
foo.b();
//~^ ERROR no method named `b` found for reference `&dyn Foo` in the current scope [E0599]
foo.c();
//~^ ERROR no method named `c` found for reference `&dyn Foo` in the current scope [E0599]
let foo: &dyn Foo = bar;
foo.b();
//~^ ERROR no method named `b` found for reference `&dyn Foo` in the current scope [E0599]
foo.c();
//~^ ERROR no method named `c` found for reference `&dyn Foo` in the current scope [E0599]
}