rust/tests/ui/traits/trait-upcasting/invalid-upcast.rs

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

87 lines
1.6 KiB
Rust
Raw Normal View History

2019-11-04 20:18:39 -06:00
#![feature(trait_upcasting)]
trait Foo {
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 {
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 {
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 _: &dyn std::fmt::Debug = baz;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn Send = baz;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn Sync = baz;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let bar: &dyn Bar = baz;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn std::fmt::Debug = bar;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn Send = bar;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn Sync = bar;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let foo: &dyn Foo = baz;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn std::fmt::Debug = foo;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn Send = foo;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn Sync = foo;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let foo: &dyn Foo = bar;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn std::fmt::Debug = foo;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn Send = foo;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
let _: &dyn Sync = foo;
//~^ ERROR mismatched types [E0308]
2019-11-04 20:18:39 -06:00
}