]> git.proxmox.com Git - rustc.git/blame - src/test/ui/traits/impl.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / traits / impl.rs
CommitLineData
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
6extern crate traitimpl;
7use traitimpl::Bar;
8
c34b1796 9static mut COUNT: usize = 1;
1a4d82fc 10
85aaf69f
SL
11trait T {
12 fn t(&self) {}
13}
1a4d82fc 14
dc9dc135 15impl<'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 24impl T for isize {}
1a4d82fc
JJ
25
26struct Foo;
27impl<'a> Bar<'a> for Foo {}
28
29fn 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}