From 98dfeb173fc1fbe8724abf8cf0943bd32653dd65 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Apr 2013 20:40:37 -0400 Subject: [PATCH] core: clean up tests (mostly unused unsafe blocks) --- src/libcore/comm.rs | 4 --- src/libcore/rt/sched/local_sched.rs | 22 ++++++++--------- src/libcore/rt/uv/net.rs | 2 +- src/libcore/stackwalk.rs | 4 +-- src/libcore/str.rs | 4 +-- src/libcore/task/local_data.rs | 38 +++++++++++++---------------- 6 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index fc13463bd1c2..2656115dca25 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -112,8 +112,6 @@ pub mod streamp { #[allow(non_camel_case_types)] pub mod server { - priv use core::kinds::Owned; - #[allow(non_camel_case_types)] pub type Open = ::core::pipes::RecvPacket>; } @@ -388,8 +386,6 @@ pub mod oneshot { #[allow(non_camel_case_types)] pub mod server { - priv use core::kinds::Owned; - #[allow(non_camel_case_types)] pub type Oneshot = ::core::pipes::RecvPacketBuffered, diff --git a/src/libcore/rt/sched/local_sched.rs b/src/libcore/rt/sched/local_sched.rs index 2ab50252ac69..77fbadf0bb7b 100644 --- a/src/libcore/rt/sched/local_sched.rs +++ b/src/libcore/rt/sched/local_sched.rs @@ -66,18 +66,16 @@ pub fn borrow(f: &fn(&mut Scheduler)) { /// Because this leaves the Scheduler in thread-local storage it is possible /// For the Scheduler pointer to be aliased pub unsafe fn unsafe_borrow() -> &mut Scheduler { - unsafe { - let key = tls_key(); - let mut void_sched: *mut c_void = tls::get(key); - assert!(void_sched.is_not_null()); - { - let void_sched_ptr = &mut void_sched; - let sched: &mut ~Scheduler = { - transmute::<&mut *mut c_void, &mut ~Scheduler>(void_sched_ptr) - }; - let sched: &mut Scheduler = &mut **sched; - return sched; - } + let key = tls_key(); + let mut void_sched: *mut c_void = tls::get(key); + assert!(void_sched.is_not_null()); + { + let void_sched_ptr = &mut void_sched; + let sched: &mut ~Scheduler = { + transmute::<&mut *mut c_void, &mut ~Scheduler>(void_sched_ptr) + }; + let sched: &mut Scheduler = &mut **sched; + return sched; } } diff --git a/src/libcore/rt/uv/net.rs b/src/libcore/rt/uv/net.rs index 0dc1a4d86cbc..b4a08c149289 100644 --- a/src/libcore/rt/uv/net.rs +++ b/src/libcore/rt/uv/net.rs @@ -388,7 +388,7 @@ fn connect_read() { vec_to_uv_buf(vec::from_elem(size, 0)) }; do stream_watcher.read_start(alloc) - |stream_watcher, nread, buf, status| { + |stream_watcher, _nread, buf, status| { let buf = vec_from_uv_buf(buf); rtdebug!("read cb!"); diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index 99bbc93056bb..21e75354e740 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -64,9 +64,7 @@ fn test_simple_deep() { if i == 0 { return } for walk_stack |_frame| { - unsafe { - breakpoint(); - } + breakpoint(); } run(i - 1); } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 837f9c1a9ade..d72b4a71e2a6 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -3346,7 +3346,7 @@ mod tests { #[test] fn test_shift_byte() { let mut s = ~"ABC"; - let b = unsafe { raw::shift_byte(&mut s) }; + let b = raw::shift_byte(&mut s); assert!((s == ~"BC")); assert!((b == 65u8)); } @@ -3354,7 +3354,7 @@ mod tests { #[test] fn test_pop_byte() { let mut s = ~"ABC"; - let b = unsafe { raw::pop_byte(&mut s) }; + let b = raw::pop_byte(&mut s); assert!((s == ~"AB")); assert!((b == 67u8)); } diff --git a/src/libcore/task/local_data.rs b/src/libcore/task/local_data.rs index 261671f6de9a..6050aca6dc1f 100644 --- a/src/libcore/task/local_data.rs +++ b/src/libcore/task/local_data.rs @@ -150,32 +150,28 @@ fn test_tls_modify() { #[test] fn test_tls_crust_automorestack_memorial_bug() { - unsafe { - // This might result in a stack-canary clobber if the runtime fails to - // set sp_limit to 0 when calling the cleanup extern - it might - // automatically jump over to the rust stack, which causes next_c_sp - // to get recorded as something within a rust stack segment. Then a - // subsequent upcall (esp. for logging, think vsnprintf) would run on - // a stack smaller than 1 MB. - fn my_key(_x: @~str) { } - do task::spawn { - unsafe { local_data_set(my_key, @~"hax"); } - } + // This might result in a stack-canary clobber if the runtime fails to + // set sp_limit to 0 when calling the cleanup extern - it might + // automatically jump over to the rust stack, which causes next_c_sp + // to get recorded as something within a rust stack segment. Then a + // subsequent upcall (esp. for logging, think vsnprintf) would run on + // a stack smaller than 1 MB. + fn my_key(_x: @~str) { } + do task::spawn { + unsafe { local_data_set(my_key, @~"hax"); } } } #[test] fn test_tls_multiple_types() { - unsafe { - fn str_key(_x: @~str) { } - fn box_key(_x: @@()) { } - fn int_key(_x: @int) { } - do task::spawn { - unsafe { - local_data_set(str_key, @~"string data"); - local_data_set(box_key, @@()); - local_data_set(int_key, @42); - } + fn str_key(_x: @~str) { } + fn box_key(_x: @@()) { } + fn int_key(_x: @int) { } + do task::spawn { + unsafe { + local_data_set(str_key, @~"string data"); + local_data_set(box_key, @@()); + local_data_set(int_key, @42); } } }