fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// run-rustfix 2use std::ops::Deref; 3use std::ops::DerefMut; 4struct Bar(u8); 5struct Foo(Bar); 6struct Emm(Foo); 7impl Deref for Bar{ 8 type Target = u8; 9 fn deref(&self) -> &Self::Target { 10 &self.0 11 } 12} 13impl Deref for Foo { 14 type Target = Bar; 15 fn deref(&self) -> &Self::Target { 16 &self.0 17 } 18} 19impl Deref for Emm { 20 type Target = Foo; 21 fn deref(&self) -> &Self::Target { 22 &self.0 23 } 24} 25impl DerefMut for Bar{ 26 fn deref_mut(&mut self) -> &mut Self::Target { 27 &mut self.0 28 } 29} 30impl DerefMut for Foo { 31 fn deref_mut(&mut self) -> &mut Self::Target { 32 &mut self.0 33 } 34} 35impl DerefMut for Emm { 36 fn deref_mut(&mut self) -> &mut Self::Target { 37 &mut self.0 38 } 39} 40fn main() { 41 // Suggest dereference with arbitrary mutability 42 let a = Emm(Foo(Bar(0))); 43 let _: *const u8 = &***a; //~ ERROR mismatched types 44 45 let mut a = Emm(Foo(Bar(0))); 46 let _: *mut u8 = &mut ***a; //~ ERROR mismatched types 47 48 let a = Emm(Foo(Bar(0))); 49 let _: *const u8 = &***a; //~ ERROR mismatched types 50 51 let mut a = Emm(Foo(Bar(0))); 52 let _: *mut u8 = &mut ***a; //~ ERROR mismatched types 53}