]>
Commit | Line | Data |
---|---|---|
85aaf69f SL |
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 | // We used to ICE when moving out of a `*mut T` or `*const T`. | |
12 | ||
13 | struct T(u8); | |
14 | ||
15 | static mut GLOBAL_MUT_T: T = T(0); | |
16 | ||
17 | static GLOBAL_T: T = T(0); | |
18 | ||
19 | fn imm_ref() -> &'static T { | |
20 | unsafe { &GLOBAL_T } | |
21 | } | |
22 | ||
23 | fn mut_ref() -> &'static mut T { | |
24 | unsafe { &mut GLOBAL_MUT_T } | |
25 | } | |
26 | ||
27 | fn mut_ptr() -> *mut T { | |
c34b1796 | 28 | unsafe { 0 as *mut T } |
85aaf69f SL |
29 | } |
30 | ||
31 | fn const_ptr() -> *const T { | |
c34b1796 | 32 | unsafe { 0 as *const T } |
85aaf69f SL |
33 | } |
34 | ||
35 | pub fn main() { | |
36 | let a = unsafe { *mut_ref() }; | |
37 | //~^ ERROR cannot move out of borrowed content | |
38 | ||
39 | let b = unsafe { *imm_ref() }; | |
40 | //~^ ERROR cannot move out of borrowed content | |
41 | ||
42 | let c = unsafe { *mut_ptr() }; | |
43 | //~^ ERROR cannot move out of dereference of unsafe pointer | |
44 | ||
45 | let d = unsafe { *const_ptr() }; | |
46 | //~^ ERROR cannot move out of dereference of unsafe pointer | |
47 | } |