]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/trait-impl.rs
10025a76f798f43b71f2b0c925b930067e706abb
[rustc.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
15 extern crate traitimpl;
16 use traitimpl::Bar;
17
18 static mut COUNT: usize = 1;
19
20 trait T {
21 fn t(&self) {}
22 }
23
24 impl<'a> T+'a {
25 fn foo(&self) {
26 unsafe { COUNT *= 2; }
27 }
28 fn bar() {
29 unsafe { COUNT *= 3; }
30 }
31 }
32
33 impl T for isize {}
34
35 struct Foo;
36 impl<'a> Bar<'a> for Foo {}
37
38 fn main() {
39 let x: &T = &42;
40
41 x.foo();
42 T::foo(x);
43 T::bar();
44
45 unsafe { assert!(COUNT == 12); }
46
47 // Cross-crait case
48 let x: &Bar = &Foo;
49 x.bar();
50 }