]> git.proxmox.com Git - rustc.git/blame - src/test/ui/issues/issue-20801.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / test / ui / issues / issue-20801.rs
CommitLineData
85aaf69f
SL
1// We used to ICE when moving out of a `*mut T` or `*const T`.
2
3struct T(u8);
4
5static mut GLOBAL_MUT_T: T = T(0);
6
7static GLOBAL_T: T = T(0);
8
9fn imm_ref() -> &'static T {
10 unsafe { &GLOBAL_T }
11}
12
13fn mut_ref() -> &'static mut T {
14 unsafe { &mut GLOBAL_MUT_T }
15}
16
17fn mut_ptr() -> *mut T {
dc9dc135 18 unsafe { core::ptr::null_mut() }
85aaf69f
SL
19}
20
21fn const_ptr() -> *const T {
dc9dc135 22 unsafe { core::ptr::null() }
85aaf69f
SL
23}
24
25pub fn main() {
26 let a = unsafe { *mut_ref() };
dc9dc135 27 //~^ ERROR cannot move out of a mutable reference
85aaf69f
SL
28
29 let b = unsafe { *imm_ref() };
dc9dc135 30 //~^ ERROR cannot move out of a shared reference
85aaf69f
SL
31
32 let c = unsafe { *mut_ptr() };
dc9dc135 33 //~^ ERROR cannot move out of a raw pointer
85aaf69f
SL
34
35 let d = unsafe { *const_ptr() };
dc9dc135 36 //~^ ERROR cannot move out of a raw pointer
85aaf69f 37}