mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 14:01:51 +00:00
27 lines
386 B
Rust
27 lines
386 B
Rust
//@ 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));
|
|
}
|