]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
1a4d82fc JJ |
2 | // Test calling methods on an impl for a bare trait. |
3 | ||
4 | // aux-build:traitimpl.rs | |
c34b1796 | 5 | |
1a4d82fc JJ |
6 | extern crate traitimpl; |
7 | use traitimpl::Bar; | |
8 | ||
c34b1796 | 9 | static mut COUNT: usize = 1; |
1a4d82fc | 10 | |
85aaf69f SL |
11 | trait T { |
12 | fn t(&self) {} | |
13 | } | |
1a4d82fc | 14 | |
dc9dc135 | 15 | impl<'a> dyn T+'a { |
1a4d82fc JJ |
16 | fn foo(&self) { |
17 | unsafe { COUNT *= 2; } | |
18 | } | |
19 | fn bar() { | |
20 | unsafe { COUNT *= 3; } | |
21 | } | |
22 | } | |
23 | ||
c34b1796 | 24 | impl T for isize {} |
1a4d82fc JJ |
25 | |
26 | struct Foo; | |
27 | impl<'a> Bar<'a> for Foo {} | |
28 | ||
29 | fn main() { | |
dc9dc135 | 30 | let x: &dyn T = &42; |
1a4d82fc JJ |
31 | |
32 | x.foo(); | |
6a06907d XL |
33 | <dyn T>::foo(x); |
34 | <dyn T>::bar(); | |
1a4d82fc | 35 | |
62682a34 | 36 | unsafe { assert_eq!(COUNT, 12); } |
1a4d82fc JJ |
37 | |
38 | // Cross-crait case | |
dc9dc135 | 39 | let x: &dyn Bar = &Foo; |
1a4d82fc JJ |
40 | x.bar(); |
41 | } |