1
Fork 0
rust/src/test/run-pass/traits/trait-impl.rs

42 lines
569 B
Rust
Raw Normal View History

// run-pass
2014-10-30 15:41:07 +13:00
// Test calling methods on an impl for a bare trait.
// aux-build:traitimpl.rs
extern crate traitimpl;
use traitimpl::Bar;
static mut COUNT: usize = 1;
2014-10-30 15:41:07 +13:00
2015-02-18 15:58:07 -08:00
trait T {
fn t(&self) {}
}
2014-10-30 15:41:07 +13:00
impl<'a> T+'a {
fn foo(&self) {
unsafe { COUNT *= 2; }
}
fn bar() {
unsafe { COUNT *= 3; }
}
}
impl T for isize {}
2014-10-30 15:41:07 +13:00
struct Foo;
impl<'a> Bar<'a> for Foo {}
2014-10-30 15:41:07 +13:00
fn main() {
2015-01-25 22:05:03 +01:00
let x: &T = &42;
2014-10-30 15:41:07 +13:00
x.foo();
T::foo(x);
T::bar();
unsafe { assert_eq!(COUNT, 12); }
// Cross-crait case
let x: &Bar = &Foo;
x.bar();
2014-10-30 15:41:07 +13:00
}