-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
static mut: allow reference to arbitrary types, not just slices and a…
…rrays
- Loading branch information
Showing
5 changed files
with
38 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// run-pass | ||
#![allow(dead_code)] | ||
|
||
// Checks that mutable static items can have mutable slices and other references | ||
|
||
|
||
static mut TEST: &'static mut [isize] = &mut [1]; | ||
static mut EMPTY: &'static mut [isize] = &mut []; | ||
static mut INT: &'static mut isize = &mut 1; | ||
|
||
// And the same for raw pointers. | ||
|
||
static mut TEST_RAW: *mut [isize] = &mut [1isize] as *mut _; | ||
static mut EMPTY_RAW: *mut [isize] = &mut [] as *mut _; | ||
static mut INT_RAW: *mut isize = &mut 1isize as *mut _; | ||
|
||
pub fn main() { | ||
unsafe { | ||
TEST[0] += 1; | ||
assert_eq!(TEST[0], 2); | ||
*INT_RAW += 1; | ||
assert_eq!(*INT_RAW, 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters