]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issue-20801.rs
0e8b7fb903769e7797d25d5c38cc91aa107de0f9
[rust.git] / src / test / ui / issue-20801.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-test currently ICEs when using NLL (#52416)
12
13 // We used to ICE when moving out of a `*mut T` or `*const T`.
14
15 struct T(u8);
16
17 static mut GLOBAL_MUT_T: T = T(0);
18
19 static GLOBAL_T: T = T(0);
20
21 fn imm_ref() -> &'static T {
22     unsafe { &GLOBAL_T }
23 }
24
25 fn mut_ref() -> &'static mut T {
26     unsafe { &mut GLOBAL_MUT_T }
27 }
28
29 fn mut_ptr() -> *mut T {
30     unsafe { 0 as *mut T }
31 }
32
33 fn const_ptr() -> *const T {
34     unsafe { 0 as *const T }
35 }
36
37 pub fn main() {
38     let a = unsafe { *mut_ref() };
39     //~^ ERROR cannot move out of borrowed content
40
41     let b = unsafe { *imm_ref() };
42     //~^ ERROR cannot move out of borrowed content
43
44     let c = unsafe { *mut_ptr() };
45     //~^ ERROR cannot move out of dereference of raw pointer
46
47     let d = unsafe { *const_ptr() };
48     //~^ ERROR cannot move out of dereference of raw pointer
49 }