rust/tests/ui/traits/issue-18412.rs

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

27 lines
385 B
Rust
Raw Normal View History

// run-pass
2014-10-29 03:09:49 +00:00
// Test that non-static methods can be assigned to local variables as
// function pointers.
2014-10-29 03:09:49 +00:00
trait Foo {
fn foo(&self) -> usize;
2014-10-29 03:09:49 +00:00
}
struct A(usize);
2014-10-29 03:09:49 +00:00
impl A {
fn bar(&self) -> usize { self.0 }
2014-10-29 03:09:49 +00:00
}
impl Foo for A {
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));
}