Skip to content

Commit 98dfeb1

Browse files
committed
core: clean up tests (mostly unused unsafe blocks)
1 parent c97bee2 commit 98dfeb1

File tree

6 files changed

+31
-43
lines changed

6 files changed

+31
-43
lines changed

src/libcore/comm.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ pub mod streamp {
112112

113113
#[allow(non_camel_case_types)]
114114
pub mod server {
115-
priv use core::kinds::Owned;
116-
117115
#[allow(non_camel_case_types)]
118116
pub type Open<T> = ::core::pipes::RecvPacket<super::Open<T>>;
119117
}
@@ -388,8 +386,6 @@ pub mod oneshot {
388386
389387
#[allow(non_camel_case_types)]
390388
pub mod server {
391-
priv use core::kinds::Owned;
392-
393389
#[allow(non_camel_case_types)]
394390
pub type Oneshot<T> =
395391
::core::pipes::RecvPacketBuffered<super::Oneshot<T>,

src/libcore/rt/sched/local_sched.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,16 @@ pub fn borrow(f: &fn(&mut Scheduler)) {
6666
/// Because this leaves the Scheduler in thread-local storage it is possible
6767
/// For the Scheduler pointer to be aliased
6868
pub unsafe fn unsafe_borrow() -> &mut Scheduler {
69-
unsafe {
70-
let key = tls_key();
71-
let mut void_sched: *mut c_void = tls::get(key);
72-
assert!(void_sched.is_not_null());
73-
{
74-
let void_sched_ptr = &mut void_sched;
75-
let sched: &mut ~Scheduler = {
76-
transmute::<&mut *mut c_void, &mut ~Scheduler>(void_sched_ptr)
77-
};
78-
let sched: &mut Scheduler = &mut **sched;
79-
return sched;
80-
}
69+
let key = tls_key();
70+
let mut void_sched: *mut c_void = tls::get(key);
71+
assert!(void_sched.is_not_null());
72+
{
73+
let void_sched_ptr = &mut void_sched;
74+
let sched: &mut ~Scheduler = {
75+
transmute::<&mut *mut c_void, &mut ~Scheduler>(void_sched_ptr)
76+
};
77+
let sched: &mut Scheduler = &mut **sched;
78+
return sched;
8179
}
8280
}
8381

src/libcore/rt/uv/net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ fn connect_read() {
388388
vec_to_uv_buf(vec::from_elem(size, 0))
389389
};
390390
do stream_watcher.read_start(alloc)
391-
|stream_watcher, nread, buf, status| {
391+
|stream_watcher, _nread, buf, status| {
392392
393393
let buf = vec_from_uv_buf(buf);
394394
rtdebug!("read cb!");

src/libcore/stackwalk.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ fn test_simple_deep() {
6464
if i == 0 { return }
6565

6666
for walk_stack |_frame| {
67-
unsafe {
68-
breakpoint();
69-
}
67+
breakpoint();
7068
}
7169
run(i - 1);
7270
}

src/libcore/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3346,15 +3346,15 @@ mod tests {
33463346
#[test]
33473347
fn test_shift_byte() {
33483348
let mut s = ~"ABC";
3349-
let b = unsafe { raw::shift_byte(&mut s) };
3349+
let b = raw::shift_byte(&mut s);
33503350
assert!((s == ~"BC"));
33513351
assert!((b == 65u8));
33523352
}
33533353
33543354
#[test]
33553355
fn test_pop_byte() {
33563356
let mut s = ~"ABC";
3357-
let b = unsafe { raw::pop_byte(&mut s) };
3357+
let b = raw::pop_byte(&mut s);
33583358
assert!((s == ~"AB"));
33593359
assert!((b == 67u8));
33603360
}

src/libcore/task/local_data.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,32 +150,28 @@ fn test_tls_modify() {
150150
151151
#[test]
152152
fn test_tls_crust_automorestack_memorial_bug() {
153-
unsafe {
154-
// This might result in a stack-canary clobber if the runtime fails to
155-
// set sp_limit to 0 when calling the cleanup extern - it might
156-
// automatically jump over to the rust stack, which causes next_c_sp
157-
// to get recorded as something within a rust stack segment. Then a
158-
// subsequent upcall (esp. for logging, think vsnprintf) would run on
159-
// a stack smaller than 1 MB.
160-
fn my_key(_x: @~str) { }
161-
do task::spawn {
162-
unsafe { local_data_set(my_key, @~"hax"); }
163-
}
153+
// This might result in a stack-canary clobber if the runtime fails to
154+
// set sp_limit to 0 when calling the cleanup extern - it might
155+
// automatically jump over to the rust stack, which causes next_c_sp
156+
// to get recorded as something within a rust stack segment. Then a
157+
// subsequent upcall (esp. for logging, think vsnprintf) would run on
158+
// a stack smaller than 1 MB.
159+
fn my_key(_x: @~str) { }
160+
do task::spawn {
161+
unsafe { local_data_set(my_key, @~"hax"); }
164162
}
165163
}
166164
167165
#[test]
168166
fn test_tls_multiple_types() {
169-
unsafe {
170-
fn str_key(_x: @~str) { }
171-
fn box_key(_x: @@()) { }
172-
fn int_key(_x: @int) { }
173-
do task::spawn {
174-
unsafe {
175-
local_data_set(str_key, @~"string data");
176-
local_data_set(box_key, @@());
177-
local_data_set(int_key, @42);
178-
}
167+
fn str_key(_x: @~str) { }
168+
fn box_key(_x: @@()) { }
169+
fn int_key(_x: @int) { }
170+
do task::spawn {
171+
unsafe {
172+
local_data_set(str_key, @~"string data");
173+
local_data_set(box_key, @@());
174+
local_data_set(int_key, @42);
179175
}
180176
}
181177
}

0 commit comments

Comments
 (0)