blob: fe1cfb3dffa9e8f30d99ec7c2f5808c9625d80ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
// run-pass
// Test that non-static methods can be assigned to local variables as
// function pointers.
trait Foo {
fn foo(&self) -> usize;
}
struct A(usize);
impl A {
fn bar(&self) -> usize { self.0 }
}
impl Foo for A {
fn foo(&self) -> usize { self.bar() }
}
fn main() {
let f = A::bar;
let g = Foo::foo;
let a = A(42);
assert_eq!(f(&a), g(&a));
}
|