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