Skip to content

Commit 02f2ee3

Browse files
committed
Merge pull request rust-lang-nursery#18 from tov/no-user-unsafe
Updated tests to work with nightly 1.0.0-beta (9854143cb 2015-04-02)
2 parents 6e0a8a9 + 3250eea commit 02f2ee3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/lazy_static.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,14 @@ macro_rules! lazy_static {
8989
#[inline(always)]
9090
fn require_sync<T: Sync>(_: &T) { }
9191

92+
#[inline(always)]
93+
fn initialize() -> Box<$T> { Box::new($e) }
94+
9295
unsafe {
9396
static mut __static: *const $T = 0 as *const $T;
9497
static mut __ONCE: Once = ONCE_INIT;
9598
__ONCE.call_once(|| {
96-
__static = transmute::<Box<$T>, *const $T>(Box::new(($e)));
99+
__static = transmute::<Box<$T>, *const $T>(initialize());
97100
});
98101
let static_ref = &*__static;
99102
require_sync(static_ref);

tests/test.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ lazy_static! {
1313
m.insert(2, "ghi");
1414
m
1515
};
16+
// This should not compile if the unsafe is removed.
17+
static ref UNSAFE: u32 = unsafe {
18+
std::mem::transmute::<i32, u32>(-1)
19+
};
1620
// This *should* triggger warn(dead_code) by design.
1721
static ref UNUSED: () = ();
1822
}
@@ -23,11 +27,12 @@ fn times_two(n: u32) -> u32 {
2327

2428
#[test]
2529
fn test_basic() {
26-
assert_eq!(&STRING[..], "hello");
30+
assert_eq!(&**STRING, "hello");
2731
assert_eq!(*NUMBER, 6);
2832
assert!(HASHMAP.get(&1).is_some());
2933
assert!(HASHMAP.get(&3).is_none());
30-
assert_eq!(&ARRAY_BOXES[..], &[Box::new(1), Box::new(2), Box::new(3)][..]);
34+
assert_eq!(&*ARRAY_BOXES, &[Box::new(1), Box::new(2), Box::new(3)]);
35+
assert_eq!(*UNSAFE, std::u32::MAX);
3136
}
3237

3338
#[test]

0 commit comments

Comments
 (0)