rust/tests/ui/impl-trait/in-trait/object-safety.rs

21 lines
468 B
Rust
Raw Normal View History

2022-09-11 04:13:55 -05:00
use std::fmt::Debug;
trait Foo {
fn baz(&self) -> impl Debug;
}
impl Foo for u32 {
2023-09-01 23:02:11 -05:00
fn baz(&self) -> impl Debug {
2022-09-11 04:13:55 -05:00
32
}
}
fn main() {
let i = Box::new(42_u32) as Box<dyn Foo>;
//~^ ERROR the trait `Foo` cannot be made into an object
//~| ERROR the trait `Foo` cannot be made into an object
let s = i.baz();
//~^ ERROR the trait `Foo` cannot be made into an object
//~| ERROR the trait `Foo` cannot be made into an object
2022-09-11 04:13:55 -05:00
}