]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/trait-impl.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / trait-impl.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test calling methods on an impl for a bare trait.
12
13 // aux-build:traitimpl.rs
14 extern crate traitimpl;
15 use traitimpl::Bar;
16
17 static mut COUNT: uint = 1;
18
19 trait T {}
20
21 impl<'a> T+'a {
22     fn foo(&self) {
23         unsafe { COUNT *= 2; }
24     }
25     fn bar() {
26         unsafe { COUNT *= 3; }
27     }
28 }
29
30 impl T for int {}
31
32 struct Foo;
33 impl<'a> Bar<'a> for Foo {}
34
35 fn main() {
36     let x: &T = &42i;
37
38     x.foo();
39     T::foo(x);
40     T::bar();
41
42     unsafe { assert!(COUNT == 12); }
43
44     // Cross-crait case
45     let x: &Bar = &Foo;
46     x.bar();
47 }