Skip to content

Commit 7f2ce3d

Browse files
committed
test: Fix tests.
1 parent 22f3492 commit 7f2ce3d

31 files changed

+114
-190
lines changed

src/libcore/cast.rs

+2-2
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

+2-2
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

+4-4
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

+9-7
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

+1-1
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

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -3473,11 +3473,11 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
34733473
~[
34743474
arg(ty::mk_mut_rptr(tcx,
34753475
ty::re_bound(ty::br_anon(0)),
3476-
ty::mk_int(tcx))),
3476+
ty::mk_int())),
34773477
arg(ty::mk_int()),
34783478
arg(ty::mk_int())
34793479
],
3480-
ty::mk_int(tcx))
3480+
ty::mk_int())
34813481
}
34823482
~"atomic_xchg" | ~"atomic_xadd" | ~"atomic_xsub" |
34833483
~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" |
@@ -3486,7 +3486,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
34863486
~[
34873487
arg(ty::mk_mut_rptr(tcx,
34883488
ty::re_bound(ty::br_anon(0)),
3489-
ty::mk_int(tcx))),
3489+
ty::mk_int())),
34903490
arg(ty::mk_int())
34913491
],
34923492
ty::mk_int())
@@ -3556,7 +3556,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
35563556
})),
35573557
arg(ty::mk_u64())
35583558
],
3559-
ty::mk_nil(tcx))
3559+
ty::mk_nil())
35603560
}
35613561
~"sqrtf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
35623562
~"sqrtf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),

src/libstd/sync.rs

+26-18
Original file line numberDiff line numberDiff line change
@@ -830,18 +830,22 @@ mod tests {
830830
let m = ~Mutex();
831831
let m2 = m.clone();
832832
let mut sharedstate = ~0;
833-
let ptr: *int = &*sharedstate;
834-
do task::spawn || {
835-
let sharedstate: &mut int =
836-
unsafe { cast::transmute(ptr) };
837-
access_shared(sharedstate, m2, 10);
838-
c.send(());
833+
{
834+
let ptr: *int = &*sharedstate;
835+
do task::spawn || {
836+
let sharedstate: &mut int =
837+
unsafe { cast::transmute(ptr) };
838+
access_shared(sharedstate, m2, 10);
839+
c.send(());
839840
841+
}
840842
}
841-
access_shared(sharedstate, m, 10);
842-
let _ = p.recv();
843+
{
844+
access_shared(sharedstate, m, 10);
845+
let _ = p.recv();
843846
844-
assert!(*sharedstate == 20);
847+
assert!(*sharedstate == 20);
848+
}
845849
846850
fn access_shared(sharedstate: &mut int, m: &Mutex, n: uint) {
847851
for n.times {
@@ -1108,17 +1112,21 @@ mod tests {
11081112
let (p,c) = comm::stream();
11091113
let x2 = (*x).clone();
11101114
let mut sharedstate = ~0;
1111-
let ptr: *int = &*sharedstate;
1112-
do task::spawn || {
1113-
let sharedstate: &mut int =
1114-
unsafe { cast::transmute(ptr) };
1115-
access_shared(sharedstate, &x2, mode1, 10);
1116-
c.send(());
1115+
{
1116+
let ptr: *int = &*sharedstate;
1117+
do task::spawn || {
1118+
let sharedstate: &mut int =
1119+
unsafe { cast::transmute(ptr) };
1120+
access_shared(sharedstate, &x2, mode1, 10);
1121+
c.send(());
1122+
}
11171123
}
1118-
access_shared(sharedstate, x, mode2, 10);
1119-
let _ = p.recv();
1124+
{
1125+
access_shared(sharedstate, x, mode2, 10);
1126+
let _ = p.recv();
11201127
1121-
assert!(*sharedstate == 20);
1128+
assert!(*sharedstate == 20);
1129+
}
11221130
11231131
fn access_shared(sharedstate: &mut int, x: &RWlock, mode: RWlockMode,
11241132
n: uint) {

src/libstd/uv_ll.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1400,9 +1400,9 @@ mod test {
14001400
// not set the data on the connect_req
14011401
// until its initialized
14021402
set_data_for_req(connect_req_ptr as *libc::c_void,
1403-
transmute(&client_data));
1403+
&client_data);
14041404
set_data_for_uv_handle(tcp_handle_ptr as *libc::c_void,
1405-
transmute(&client_data));
1405+
&client_data);
14061406
debug!(~"before run tcp req loop");
14071407
run(test_loop);
14081408
debug!(~"after run tcp req loop");

src/libsyntax/ext/pipes/pipec.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ impl gen_init for protocol {
370370
|s| ext_cx.parse_stmt(
371371
fmt!("data.%s.set_buffer(buffer)",
372372
s.name))),
373-
ext_cx.parse_expr(fmt!("&(data.%s)", self.states[0].name))));
373+
ext_cx.parse_expr(fmt!(
374+
"::core::ptr::to_unsafe_ptr(&(data.%s))",
375+
self.states[0].name))));
374376
375377
quote_expr!({
376378
let buffer = $buffer;

src/test/bench/graph500-bfs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result {
226226
}
227227
228228
/// A parallel version of the bfs function.
229-
fn pbfs(&&graph: arc::ARC<graph>, key: node_id) -> bfs_result {
229+
fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
230230
// This works by doing functional updates of a color vector.
231231
232232
enum color {
@@ -237,7 +237,7 @@ fn pbfs(&&graph: arc::ARC<graph>, key: node_id) -> bfs_result {
237237
black(node_id)
238238
};
239239
240-
let graph_vec = arc::get(&graph); // FIXME #3387 requires this temp
240+
let graph_vec = arc::get(graph); // FIXME #3387 requires this temp
241241
let mut colors = do vec::from_fn(graph_vec.len()) |i| {
242242
if i as node_id == key {
243243
gray(key)
@@ -272,7 +272,7 @@ fn pbfs(&&graph: arc::ARC<graph>, key: node_id) -> bfs_result {
272272
let color_vec = arc::get(&color); // FIXME #3387 requires this temp
273273
colors = do par::mapi(*color_vec) {
274274
let colors = arc::clone(&color);
275-
let graph = arc::clone(&graph);
275+
let graph = arc::clone(graph);
276276
let result: ~fn(+x: uint, +y: &color) -> color = |i, c| {
277277
let colors = arc::get(&colors);
278278
let graph = arc::get(&graph);
@@ -497,7 +497,7 @@ fn main() {
497497
}
498498
499499
let start = time::precise_time_s();
500-
let bfs_tree = pbfs(graph_arc, *root);
500+
let bfs_tree = pbfs(&graph_arc, *root);
501501
let stop = time::precise_time_s();
502502
503503
total_par += stop - start;

src/test/bench/msgsend-pipes-shared.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum request {
3434
stop
3535
}
3636

37-
fn server(requests: Port<request>, responses: comm::Chan<uint>) {
37+
fn server(requests: &Port<request>, responses: &comm::Chan<uint>) {
3838
let mut count = 0u;
3939
let mut done = false;
4040
while !done {
@@ -76,7 +76,7 @@ fn run(args: &[~str]) {
7676
};
7777
}
7878
do task::spawn || {
79-
server(from_parent, to_parent);
79+
server(&from_parent, &to_parent);
8080
}
8181

8282
for vec::each(worker_results) |r| {

src/test/bench/msgsend-pipes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ enum request {
3030
stop
3131
}
3232

33-
fn server(requests: PortSet<request>, responses: Chan<uint>) {
33+
fn server(requests: &PortSet<request>, responses: &Chan<uint>) {
3434
let mut count = 0;
3535
let mut done = false;
3636
while !done {
@@ -73,7 +73,7 @@ fn run(args: &[~str]) {
7373
};
7474
}
7575
do task::spawn || {
76-
server(from_parent, to_parent);
76+
server(&from_parent, &to_parent);
7777
}
7878

7979
for vec::each(worker_results) |r| {

src/test/bench/shootout-k-nucleotide-pipes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ fn windows_with_carry(bb: &[u8], nn: uint,
104104
}
105105

106106
fn make_sequence_processor(sz: uint,
107-
from_parent: comm::Port<~[u8]>,
108-
to_parent: comm::Chan<~str>) {
107+
from_parent: &comm::Port<~[u8]>,
108+
to_parent: &comm::Chan<~str>) {
109109
let mut freqs: HashMap<~[u8], uint> = HashMap::new();
110110
let mut carry: ~[u8] = ~[];
111111
let mut total: uint = 0u;
@@ -140,7 +140,7 @@ fn make_sequence_processor(sz: uint,
140140
// given a FASTA file on stdin, process sequence THREE
141141
fn main() {
142142
let args = os::args();
143-
let rdr = if os::getenv(~"RUST_BENCH").is_some() {
143+
let rdr = if os::getenv(~"RUST_BENCH").is_some() {
144144
// FIXME: Using this compile-time env variable is a crummy way to
145145
// get to this massive data set, but include_bin! chokes on it (#2598)
146146
let path = Path(env!("CFG_SRC_DIR"))
@@ -168,7 +168,7 @@ fn main() {
168168
let (from_parent, to_child) = comm::stream();
169169
170170
do task::spawn_with(from_parent) |from_parent| {
171-
make_sequence_processor(sz, from_parent, to_parent_);
171+
make_sequence_processor(sz, &from_parent, &to_parent_);
172172
};
173173
174174
to_child

src/test/bench/shootout-pfib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ use core::result;
3030
use core::result::{Ok, Err};
3131

3232
fn fib(n: int) -> int {
33-
fn pfib(c: Chan<int>, n: int) {
33+
fn pfib(c: &Chan<int>, n: int) {
3434
if n == 0 {
3535
c.send(0);
3636
} else if n <= 2 {
3737
c.send(1);
3838
} else {
3939
let p = PortSet::new();
4040
let ch = p.chan();
41-
task::spawn(|| pfib(ch, n - 1) );
41+
task::spawn(|| pfib(&ch, n - 1) );
4242
let ch = p.chan();
43-
task::spawn(|| pfib(ch, n - 2) );
43+
task::spawn(|| pfib(&ch, n - 2) );
4444
c.send(p.recv() + p.recv());
4545
}
4646
}
4747

4848
let (p, ch) = stream();
49-
let _t = task::spawn(|| pfib(ch, n) );
49+
let _t = task::spawn(|| pfib(&ch, n) );
5050
p.recv()
5151
}
5252

src/test/compile-fail/arg-style-mismatch.rs

-15
This file was deleted.

0 commit comments

Comments
 (0)