os-rust/tests/ui/traits/region-pointer-simple.rs

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

22 lines
305 B
Rust
Raw Normal View History

//@ run-pass
2012-10-05 16:55:42 -07:00
trait Foo {
fn f(&self) -> isize;
2012-10-05 16:55:42 -07:00
}
struct A {
x: isize
2012-10-05 16:55:42 -07:00
}
impl Foo for A {
fn f(&self) -> isize {
println!("Today's number is {}", self.x);
2012-10-05 16:55:42 -07:00
return self.x;
}
}
pub fn main() {
2012-10-05 16:55:42 -07:00
let a = A { x: 3 };
2019-05-28 14:47:21 -04:00
let b = (&a) as &dyn Foo;
assert_eq!(b.f(), 3);
2012-10-05 16:55:42 -07:00
}