rust/tests/ui/box/new-box.rs

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

31 lines
430 B
Rust
Raw Normal View History

// run-pass
fn f(x: Box<isize>) {
let y: &isize = &*x;
println!("{}", *x);
println!("{}", *y);
}
trait Trait {
fn printme(&self);
}
struct Struct;
impl Trait for Struct {
fn printme(&self) {
println!("hello world!");
}
}
2019-05-28 13:47:21 -05:00
fn g(x: Box<dyn Trait>) {
x.printme();
2019-05-28 13:47:21 -05:00
let y: &dyn Trait = &*x;
y.printme();
}
fn main() {
f(Box::new(1234));
g(Box::new(Struct) as Box<dyn Trait>);
}