]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/trait-impl.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[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 // pretty-expanded FIXME #23616
15
16 extern crate traitimpl;
17 use traitimpl::Bar;
18
19 static mut COUNT: uint = 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 int {}
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!(COUNT == 12); }
47
48     // Cross-crait case
49     let x: &Bar = &Foo;
50     x.bar();
51 }