1 #![crate_type = "lib"] 2 3 static mut COUNT: u64 = 1; 4 get_count() -> u645pub fn get_count() -> u64 { unsafe { COUNT } } 6 7 #[derive(Copy, Clone)] 8 pub struct Foo; 9 10 impl Foo { run_trait(self)11 pub fn run_trait(self) { 12 unsafe { COUNT *= 17; } 13 // Test internal call. 14 Bar::foo1(&self); 15 Bar::foo2(self); 16 Bar::foo3(Box::new(self)); 17 18 Bar::bar1(&self); 19 Bar::bar2(self); 20 Bar::bar3(Box::new(self)); 21 } 22 } 23 24 pub trait Bar : Sized { foo1(&self)25 fn foo1(&self); foo2(self)26 fn foo2(self); foo3(self: Box<Self>)27 fn foo3(self: Box<Self>); 28 bar1(&self)29 fn bar1(&self) { 30 unsafe { COUNT *= 7; } 31 } bar2(self)32 fn bar2(self) { 33 unsafe { COUNT *= 11; } 34 } bar3(self: Box<Self>)35 fn bar3(self: Box<Self>) { 36 unsafe { COUNT *= 13; } 37 } 38 } 39 40 impl Bar for Foo { foo1(&self)41 fn foo1(&self) { 42 unsafe { COUNT *= 2; } 43 } 44 foo2(self)45 fn foo2(self) { 46 unsafe { COUNT *= 3; } 47 } 48 foo3(self: Box<Foo>)49 fn foo3(self: Box<Foo>) { 50 unsafe { COUNT *= 5; } 51 } 52 } 53