Skip to content

Commit 876483d

Browse files
committed
test: Fix tests.
1 parent f30f54e commit 876483d

31 files changed

+114
-190
lines changed

src/libcore/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ mod tests {
178178
let box = @~"box box box"; // refcount 1
179179
bump_box_refcount(box); // refcount 2
180180
let ptr: *int = transmute(box); // refcount 2
181-
let _box1: @~str = reinterpret_cast(&ptr);
182-
let _box2: @~str = reinterpret_cast(&ptr);
181+
let _box1: @~str = ::cast::transmute_copy(&ptr);
182+
let _box2: @~str = ::cast::transmute_copy(&ptr);
183183
assert!(*_box1 == ~"box box box");
184184
assert!(*_box2 == ~"box box box");
185185
// Will destroy _box1 and _box2. Without the bump, this would

src/libcore/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ pub impl<T:Copy + Zero> Option<T> {
482482
fn test_unwrap_ptr() {
483483
unsafe {
484484
let x = ~0;
485-
let addr_x: *int = transmute(&*x);
485+
let addr_x: *int = ::cast::transmute(&*x);
486486
let opt = Some(x);
487487
let y = opt.unwrap();
488-
let addr_y: *int = transmute(&*y);
488+
let addr_y: *int = ::cast::transmute(&*y);
489489
assert!(addr_x == addr_y);
490490
}
491491
}

src/libcore/rt/thread.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub struct Thread {
2121

2222
pub impl Thread {
2323
fn start(main: ~fn()) -> Thread {
24-
fn substart(main: &fn()) -> *raw_thread {
25-
unsafe { rust_raw_thread_start(&main) }
24+
fn substart(main: &~fn()) -> *raw_thread {
25+
unsafe { rust_raw_thread_start(main) }
2626
}
27-
let raw = substart(main);
27+
let raw = substart(&main);
2828
Thread {
2929
main: main,
3030
raw_thread: raw
@@ -39,6 +39,6 @@ impl Drop for Thread {
3939
}
4040

4141
extern {
42-
pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
42+
pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread;
4343
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
4444
}

src/libcore/rt/uv/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,15 @@ pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
366366
367367
/// Transmute an owned vector to a Buf
368368
pub fn vec_to_uv_buf(v: ~[u8]) -> Buf {
369-
let data = unsafe { malloc(v.len() as size_t) } as *u8;
370-
assert!(data.is_not_null());
371-
do vec::as_imm_buf(v) |b, l| {
372-
let data = data as *mut u8;
373-
unsafe { ptr::copy_memory(data, b, l) }
369+
unsafe {
370+
let data = malloc(v.len() as size_t) as *u8;
371+
assert!(data.is_not_null());
372+
do vec::as_imm_buf(v) |b, l| {
373+
let data = data as *mut u8;
374+
ptr::copy_memory(data, b, l)
375+
}
376+
uvll::buf_init(data, v.len())
374377
}
375-
let buf = unsafe { uvll::buf_init(data, v.len()) };
376-
return buf;
377378
}
378379
379380
/// Transmute a Buf that was once a ~[u8] back to ~[u8]
@@ -384,6 +385,7 @@ pub fn vec_from_uv_buf(buf: Buf) -> Option<~[u8]> {
384385
return Some(v);
385386
} else {
386387
// No buffer
388+
rtdebug!("No buffer!");
387389
return None;
388390
}
389391
}

src/libcore/sys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn pref_align_of_val<T>(_val: &T) -> uint {
154154
#[inline(always)]
155155
pub fn refcount<T>(t: @T) -> uint {
156156
unsafe {
157-
let ref_ptr: *uint = cast::transmute(t);
157+
let ref_ptr: *uint = cast::transmute_copy(&t);
158158
*ref_ptr - 1
159159
}
160160
}

src/librustc/middle/trans/foreign.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -729,16 +729,16 @@ pub fn trans_intrinsic(ccx: @CrateContext,
729729
_ => fail!(~"transmute has non-expr arg"),
730730
};
731731
let pluralize = |n| if 1u == n { "" } else { "s" };
732-
ccx.sess.span_err(sp,
733-
fmt!("transmute called on types with \
734-
different sizes: %s (%u bit%s) to \
735-
%s (%u bit%s)",
736-
ty_to_str(ccx.tcx, in_type),
737-
in_type_size,
738-
pluralize(in_type_size),
739-
ty_to_str(ccx.tcx, out_type),
740-
out_type_size,
741-
pluralize(out_type_size)));
732+
ccx.sess.span_fatal(sp,
733+
fmt!("transmute called on types with \
734+
different sizes: %s (%u bit%s) to \
735+
%s (%u bit%s)",
736+
ty_to_str(ccx.tcx, in_type),
737+
in_type_size,
738+
pluralize(in_type_size),
739+
ty_to_str(ccx.tcx, out_type),
740+
out_type_size,
741+
pluralize(out_type_size)));
742742
}
743743
744744
if !ty::type_is_nil(out_type) {

src/librustc/middle/typeck/check/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,11 +3467,11 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
34673467
~[
34683468
arg(ty::mk_mut_rptr(tcx,
34693469
ty::re_bound(ty::br_anon(0)),
3470-
ty::mk_int(tcx))),
3470+
ty::mk_int())),
34713471
arg(ty::mk_int()),
34723472
arg(ty::mk_int())
34733473
],
3474-
ty::mk_int(tcx))
3474+
ty::mk_int())
34753475
}
34763476
~"atomic_xchg" | ~"atomic_xadd" | ~"atomic_xsub" |
34773477
~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" |
@@ -3480,7 +3480,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
34803480
~[
34813481
arg(ty::mk_mut_rptr(tcx,
34823482
ty::re_bound(ty::br_anon(0)),
3483-
ty::mk_int(tcx))),
3483+
ty::mk_int())),
34843484
arg(ty::mk_int())
34853485
],
34863486
ty::mk_int())
@@ -3550,7 +3550,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
35503550
})),
35513551
arg(ty::mk_u64())
35523552
],
3553-
ty::mk_nil(tcx))
3553+
ty::mk_nil())
35543554
}
35553555
~"sqrtf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
35563556
~"sqrtf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),

src/libstd/sync.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -828,18 +828,22 @@ mod tests {
828828
let m = ~Mutex();
829829
let m2 = m.clone();
830830
let mut sharedstate = ~0;
831-
let ptr: *int = &*sharedstate;
832-
do task::spawn || {
833-
let sharedstate: &mut int =
834-
unsafe { cast::transmute(ptr) };
835-
access_shared(sharedstate, m2, 10);
836-
c.send(());
831+
{
832+
let ptr: *int = &*sharedstate;
833+
do task::spawn || {
834+
let sharedstate: &mut int =
835+
unsafe { cast::transmute(ptr) };
836+
access_shared(sharedstate, m2, 10);
837+
c.send(());
837838
839+
}
838840
}
839-
access_shared(sharedstate, m, 10);
840-
let _ = p.recv();
841+
{
842+
access_shared(sharedstate, m, 10);
843+
let _ = p.recv();
841844
842-
assert!(*sharedstate == 20);
845+
assert!(*sharedstate == 20);
846+
}
843847
844848
fn access_shared(sharedstate: &mut int, m: &Mutex, n: uint) {
845849
for n.times {
@@ -1106,17 +1110,21 @@ mod tests {
11061110
let (p,c) = comm::stream();
11071111
let x2 = (*x).clone();
11081112
let mut sharedstate = ~0;
1109-
let ptr: *int = &*sharedstate;
1110-
do task::spawn || {
1111-
let sharedstate: &mut int =
1112-
unsafe { cast::transmute(ptr) };
1113-
access_shared(sharedstate, &x2, mode1, 10);
1114-
c.send(());
1113+
{
1114+
let ptr: *int = &*sharedstate;
1115+
do task::spawn || {
1116+
let sharedstate: &mut int =
1117+
unsafe { cast::transmute(ptr) };
1118+
access_shared(sharedstate, &x2, mode1, 10);
1119+
c.send(());
1120+
}
11151121
}
1116-
access_shared(sharedstate, x, mode2, 10);
1117-
let _ = p.recv();
1122+
{
1123+
access_shared(sharedstate, x, mode2, 10);
1124+
let _ = p.recv();
11181125
1119-
assert!(*sharedstate == 20);
1126+
assert!(*sharedstate == 20);
1127+
}
11201128
11211129
fn access_shared(sharedstate: &mut int, x: &RWlock, mode: RWlockMode,
11221130
n: uint) {

src/libstd/uv_ll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,9 +1396,9 @@ mod test {
13961396
// not set the data on the connect_req
13971397
// until its initialized
13981398
set_data_for_req(connect_req_ptr as *libc::c_void,
1399-
transmute(&client_data));
1399+
&client_data);
14001400
set_data_for_uv_handle(tcp_handle_ptr as *libc::c_void,
1401-
transmute(&client_data));
1401+
&client_data);
14021402
debug!(~"before run tcp req loop");
14031403
run(test_loop);
14041404
debug!(~"after run tcp req loop");

src/libsyntax/ext/pipes/pipec.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ impl gen_init for protocol {
365365
|s| ext_cx.parse_stmt(
366366
fmt!("data.%s.set_buffer(buffer)",
367367
s.name))),
368-
ext_cx.parse_expr(fmt!("&(data.%s)", self.states[0].name))));
368+
ext_cx.parse_expr(fmt!(
369+
"::core::ptr::to_unsafe_ptr(&(data.%s))",
370+
self.states[0].name))));
369371
370372
quote_expr!({
371373
let buffer = $buffer;

0 commit comments

Comments
 (0)