2015-02-10 08:01:31 -06:00
|
|
|
// We used to ICE when moving out of a `*mut T` or `*const T`.
|
|
|
|
|
|
|
|
struct T(u8);
|
|
|
|
|
|
|
|
static mut GLOBAL_MUT_T: T = T(0);
|
|
|
|
|
|
|
|
static GLOBAL_T: T = T(0);
|
|
|
|
|
|
|
|
fn imm_ref() -> &'static T {
|
|
|
|
unsafe { &GLOBAL_T }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn mut_ref() -> &'static mut T {
|
|
|
|
unsafe { &mut GLOBAL_MUT_T }
|
2023-12-22 06:12:01 -06:00
|
|
|
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
2015-02-10 08:01:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mut_ptr() -> *mut T {
|
2019-06-17 05:52:37 -05:00
|
|
|
unsafe { core::ptr::null_mut() }
|
2015-02-10 08:01:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn const_ptr() -> *const T {
|
2019-06-17 05:52:37 -05:00
|
|
|
unsafe { core::ptr::null() }
|
2015-02-10 08:01:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let a = unsafe { *mut_ref() };
|
2019-05-05 06:02:32 -05:00
|
|
|
//~^ ERROR cannot move out of a mutable reference
|
2015-02-10 08:01:31 -06:00
|
|
|
|
|
|
|
let b = unsafe { *imm_ref() };
|
2019-05-05 06:02:32 -05:00
|
|
|
//~^ ERROR cannot move out of a shared reference
|
2015-02-10 08:01:31 -06:00
|
|
|
|
|
|
|
let c = unsafe { *mut_ptr() };
|
2019-05-05 06:02:32 -05:00
|
|
|
//~^ ERROR cannot move out of a raw pointer
|
2015-02-10 08:01:31 -06:00
|
|
|
|
|
|
|
let d = unsafe { *const_ptr() };
|
2019-05-05 06:02:32 -05:00
|
|
|
//~^ ERROR cannot move out of a raw pointer
|
2015-02-10 08:01:31 -06:00
|
|
|
}
|