2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2014-10-29 03:09:49 +00:00
|
|
|
// Test that non-static methods can be assigned to local variables as
|
|
|
|
// function pointers.
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2014-10-29 03:09:49 +00:00
|
|
|
trait Foo {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn foo(&self) -> usize;
|
2014-10-29 03:09:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
struct A(usize);
|
2014-10-29 03:09:49 +00:00
|
|
|
|
|
|
|
impl A {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn bar(&self) -> usize { self.0 }
|
2014-10-29 03:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo for A {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn foo(&self) -> usize { self.bar() }
|
2014-10-29 03:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let f = A::bar;
|
|
|
|
let g = Foo::foo;
|
|
|
|
let a = A(42);
|
|
|
|
|
|
|
|
assert_eq!(f(&a), g(&a));
|
|
|
|
}
|