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