1 #![warn(clippy::cast_ref_to_mut)]
2 #![allow(clippy::no_effect)]
3 
4 extern "C" {
5     // N.B., mutability can be easily incorrect in FFI calls -- as
6     // in C, the default is mutable pointers.
ffi(c: *mut u8)7     fn ffi(c: *mut u8);
int_ffi(c: *mut i32)8     fn int_ffi(c: *mut i32);
9 }
10 
main()11 fn main() {
12     let s = String::from("Hello");
13     let a = &s;
14     unsafe {
15         let num = &3i32;
16         let mut_num = &mut 3i32;
17         // Should be warned against
18         (*(a as *const _ as *mut String)).push_str(" world");
19         *(a as *const _ as *mut _) = String::from("Replaced");
20         *(a as *const _ as *mut String) += " world";
21         // Shouldn't be warned against
22         println!("{}", *(num as *const _ as *const i16));
23         println!("{}", *(mut_num as *mut _ as *mut i16));
24         ffi(a.as_ptr() as *mut _);
25         int_ffi(num as *const _ as *mut _);
26         int_ffi(&3 as *const _ as *mut _);
27         let mut value = 3;
28         let value: *const i32 = &mut value;
29         *(value as *const i16 as *mut i16) = 42;
30     }
31 }
32