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
304 B
Rust
Raw Normal View History

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