Skip to content

Commit 6f16df4

Browse files
committed
std: Remove some @-boxes
1 parent d5d5c50 commit 6f16df4

File tree

3 files changed

+89
-76
lines changed

3 files changed

+89
-76
lines changed

src/libstd/local_data.rs

+49-49
Original file line numberDiff line numberDiff line change
@@ -353,56 +353,56 @@ mod tests {
353353

354354
#[test]
355355
fn test_tls_multitask() {
356-
static my_key: Key<@~str> = &Key;
357-
set(my_key, @~"parent data");
356+
static my_key: Key<~str> = &Key;
357+
set(my_key, ~"parent data");
358358
do task::spawn {
359359
// TLS shouldn't carry over.
360-
assert!(get(my_key, |k| k.map(|k| *k)).is_none());
361-
set(my_key, @~"child data");
362-
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) ==
360+
assert!(get(my_key, |k| k.map(|k| (*k).clone())).is_none());
361+
set(my_key, ~"child data");
362+
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() ==
363363
~"child data");
364364
// should be cleaned up for us
365365
}
366366
// Must work multiple times
367-
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data");
368-
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data");
369-
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data");
367+
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data");
368+
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data");
369+
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data");
370370
}
371371
372372
#[test]
373373
fn test_tls_overwrite() {
374-
static my_key: Key<@~str> = &Key;
375-
set(my_key, @~"first data");
376-
set(my_key, @~"next data"); // Shouldn't leak.
377-
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"next data");
374+
static my_key: Key<~str> = &Key;
375+
set(my_key, ~"first data");
376+
set(my_key, ~"next data"); // Shouldn't leak.
377+
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"next data");
378378
}
379379
380380
#[test]
381381
fn test_tls_pop() {
382-
static my_key: Key<@~str> = &Key;
383-
set(my_key, @~"weasel");
384-
assert!(*(pop(my_key).unwrap()) == ~"weasel");
382+
static my_key: Key<~str> = &Key;
383+
set(my_key, ~"weasel");
384+
assert!(pop(my_key).unwrap() == ~"weasel");
385385
// Pop must remove the data from the map.
386386
assert!(pop(my_key).is_none());
387387
}
388388
389389
#[test]
390390
fn test_tls_modify() {
391-
static my_key: Key<@~str> = &Key;
391+
static my_key: Key<~str> = &Key;
392392
modify(my_key, |data| {
393393
match data {
394-
Some(@ref val) => fail!("unwelcome value: {}", *val),
395-
None => Some(@~"first data")
394+
Some(ref val) => fail!("unwelcome value: {}", *val),
395+
None => Some(~"first data")
396396
}
397397
});
398398
modify(my_key, |data| {
399399
match data {
400-
Some(@~"first data") => Some(@~"next data"),
401-
Some(@ref val) => fail!("wrong value: {}", *val),
400+
Some(~"first data") => Some(~"next data"),
401+
Some(ref val) => fail!("wrong value: {}", *val),
402402
None => fail!("missing value")
403403
}
404404
});
405-
assert!(*(pop(my_key).unwrap()) == ~"next data");
405+
assert!(pop(my_key).unwrap() == ~"next data");
406406
}
407407
408408
#[test]
@@ -413,67 +413,67 @@ mod tests {
413413
// to get recorded as something within a rust stack segment. Then a
414414
// subsequent upcall (esp. for logging, think vsnprintf) would run on
415415
// a stack smaller than 1 MB.
416-
static my_key: Key<@~str> = &Key;
416+
static my_key: Key<~str> = &Key;
417417
do task::spawn {
418-
set(my_key, @~"hax");
418+
set(my_key, ~"hax");
419419
}
420420
}
421421
422422
#[test]
423423
fn test_tls_multiple_types() {
424-
static str_key: Key<@~str> = &Key;
425-
static box_key: Key<@@()> = &Key;
426-
static int_key: Key<@int> = &Key;
424+
static str_key: Key<~str> = &Key;
425+
static box_key: Key<@()> = &Key;
426+
static int_key: Key<int> = &Key;
427427
do task::spawn {
428-
set(str_key, @~"string data");
429-
set(box_key, @@());
430-
set(int_key, @42);
428+
set(str_key, ~"string data");
429+
set(box_key, @());
430+
set(int_key, 42);
431431
}
432432
}
433433
434434
#[test]
435435
fn test_tls_overwrite_multiple_types() {
436-
static str_key: Key<@~str> = &Key;
437-
static box_key: Key<@@()> = &Key;
438-
static int_key: Key<@int> = &Key;
436+
static str_key: Key<~str> = &Key;
437+
static box_key: Key<@()> = &Key;
438+
static int_key: Key<int> = &Key;
439439
do task::spawn {
440-
set(str_key, @~"string data");
441-
set(str_key, @~"string data 2");
442-
set(box_key, @@());
443-
set(box_key, @@());
444-
set(int_key, @42);
440+
set(str_key, ~"string data");
441+
set(str_key, ~"string data 2");
442+
set(box_key, @());
443+
set(box_key, @());
444+
set(int_key, 42);
445445
// This could cause a segfault if overwriting-destruction is done
446446
// with the crazy polymorphic transmute rather than the provided
447447
// finaliser.
448-
set(int_key, @31337);
448+
set(int_key, 31337);
449449
}
450450
}
451451
452452
#[test]
453453
#[should_fail]
454454
fn test_tls_cleanup_on_failure() {
455-
static str_key: Key<@~str> = &Key;
456-
static box_key: Key<@@()> = &Key;
457-
static int_key: Key<@int> = &Key;
458-
set(str_key, @~"parent data");
459-
set(box_key, @@());
455+
static str_key: Key<~str> = &Key;
456+
static box_key: Key<@()> = &Key;
457+
static int_key: Key<int> = &Key;
458+
set(str_key, ~"parent data");
459+
set(box_key, @());
460460
do task::spawn {
461461
// spawn_linked
462-
set(str_key, @~"string data");
463-
set(box_key, @@());
464-
set(int_key, @42);
462+
set(str_key, ~"string data");
463+
set(box_key, @());
464+
set(int_key, 42);
465465
fail!();
466466
}
467467
// Not quite nondeterministic.
468-
set(int_key, @31337);
468+
set(int_key, 31337);
469469
fail!();
470470
}
471471

472472
#[test]
473473
fn test_static_pointer() {
474-
static key: Key<@&'static int> = &Key;
474+
static key: Key<&'static int> = &Key;
475475
static VALUE: int = 0;
476-
let v: @&'static int = @&VALUE;
476+
let v: &'static int = &VALUE;
477477
set(key, v);
478478
}
479479

src/libstd/option.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -445,28 +445,34 @@ mod tests {
445445

446446
#[test]
447447
fn test_get_resource() {
448+
use rc::Rc;
449+
use cell::RefCell;
450+
448451
struct R {
449-
i: @mut int,
452+
i: Rc<RefCell<int>>,
450453
}
451454

452455
#[unsafe_destructor]
453456
impl ::ops::Drop for R {
454-
fn drop(&mut self) { *(self.i) += 1; }
457+
fn drop(&mut self) {
458+
let ii = self.i.borrow();
459+
ii.set(ii.get() + 1);
460+
}
455461
}
456462

457-
fn R(i: @mut int) -> R {
463+
fn R(i: Rc<RefCell<int>>) -> R {
458464
R {
459465
i: i
460466
}
461467
}
462468

463-
let i = @mut 0;
469+
let i = Rc::from_send(RefCell::new(0));
464470
{
465-
let x = R(i);
471+
let x = R(i.clone());
466472
let opt = Some(x);
467473
let _y = opt.unwrap();
468474
}
469-
assert_eq!(*i, 1);
475+
assert_eq!(i.borrow().get(), 1);
470476
}
471477

472478
#[test]

src/libstd/vec.rs

+28-21
Original file line numberDiff line numberDiff line change
@@ -3064,7 +3064,7 @@ mod tests {
30643064

30653065
#[test]
30663066
fn test_truncate() {
3067-
let mut v = ~[@6,@5,@4];
3067+
let mut v = ~[~6,~5,~4];
30683068
v.truncate(1);
30693069
assert_eq!(v.len(), 1);
30703070
assert_eq!(*(v[0]), 6);
@@ -3073,7 +3073,7 @@ mod tests {
30733073

30743074
#[test]
30753075
fn test_clear() {
3076-
let mut v = ~[@6,@5,@4];
3076+
let mut v = ~[~6,~5,~4];
30773077
v.clear();
30783078
assert_eq!(v.len(), 0);
30793079
// If the unsafe block didn't drop things properly, we blow up here.
@@ -3112,14 +3112,14 @@ mod tests {
31123112

31133113
#[test]
31143114
fn test_dedup_shared() {
3115-
let mut v0 = ~[@1, @1, @2, @3];
3115+
let mut v0 = ~[~1, ~1, ~2, ~3];
31163116
v0.dedup();
3117-
let mut v1 = ~[@1, @2, @2, @3];
3117+
let mut v1 = ~[~1, ~2, ~2, ~3];
31183118
v1.dedup();
3119-
let mut v2 = ~[@1, @2, @3, @3];
3119+
let mut v2 = ~[~1, ~2, ~3, ~3];
31203120
v2.dedup();
31213121
/*
3122-
* If the @pointers were leaked or otherwise misused, valgrind and/or
3122+
* If the pointers were leaked or otherwise misused, valgrind and/or
31233123
* rustrt should raise errors.
31243124
*/
31253125
}
@@ -3446,18 +3446,19 @@ mod tests {
34463446
fn test_from_fn_fail() {
34473447
from_fn(100, |v| {
34483448
if v == 50 { fail!() }
3449-
(~0, @0)
3449+
~0
34503450
});
34513451
}
34523452

34533453
#[test]
34543454
#[should_fail]
34553455
fn test_from_elem_fail() {
34563456
use cast;
3457+
use rc::Rc;
34573458

34583459
struct S {
34593460
f: int,
3460-
boxes: (~int, @int)
3461+
boxes: (~int, Rc<int>)
34613462
}
34623463

34633464
impl Clone for S {
@@ -3469,66 +3470,71 @@ mod tests {
34693470
}
34703471
}
34713472

3472-
let s = S { f: 0, boxes: (~0, @0) };
3473+
let s = S { f: 0, boxes: (~0, Rc::new(0)) };
34733474
let _ = from_elem(100, s);
34743475
}
34753476

34763477
#[test]
34773478
#[should_fail]
34783479
fn test_build_fail() {
3480+
use rc::Rc;
34793481
build(None, |push| {
3480-
push((~0, @0));
3481-
push((~0, @0));
3482-
push((~0, @0));
3483-
push((~0, @0));
3482+
push((~0, Rc::new(0)));
3483+
push((~0, Rc::new(0)));
3484+
push((~0, Rc::new(0)));
3485+
push((~0, Rc::new(0)));
34843486
fail!();
34853487
});
34863488
}
34873489

34883490
#[test]
34893491
#[should_fail]
34903492
fn test_grow_fn_fail() {
3493+
use rc::Rc;
34913494
let mut v = ~[];
34923495
v.grow_fn(100, |i| {
34933496
if i == 50 {
34943497
fail!()
34953498
}
3496-
(~0, @0)
3499+
(~0, Rc::new(0))
34973500
})
34983501
}
34993502

35003503
#[test]
35013504
#[should_fail]
35023505
fn test_map_fail() {
3503-
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
3506+
use rc::Rc;
3507+
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
35043508
let mut i = 0;
35053509
v.map(|_elt| {
35063510
if i == 2 {
35073511
fail!()
35083512
}
35093513
i += 1;
3510-
~[(~0, @0)]
3514+
~[(~0, Rc::new(0))]
35113515
});
35123516
}
35133517

35143518
#[test]
35153519
#[should_fail]
35163520
fn test_flat_map_fail() {
3517-
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
3521+
use rc::Rc;
3522+
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
35183523
let mut i = 0;
35193524
flat_map(v, |_elt| {
35203525
if i == 2 {
35213526
fail!()
35223527
}
35233528
i += 1;
3524-
~[(~0, @0)]
3529+
~[(~0, Rc::new(0))]
35253530
});
35263531
}
35273532

35283533
#[test]
35293534
#[should_fail]
35303535
fn test_permute_fail() {
3531-
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
3536+
use rc::Rc;
3537+
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
35323538
let mut i = 0;
35333539
for _ in v.permutations() {
35343540
if i == 2 {
@@ -3866,9 +3872,10 @@ mod tests {
38663872
#[test]
38673873
#[should_fail]
38683874
fn test_overflow_does_not_cause_segfault_managed() {
3869-
let mut v = ~[@1];
3875+
use rc::Rc;
3876+
let mut v = ~[Rc::new(1)];
38703877
v.reserve(-1);
3871-
v.push(@2);
3878+
v.push(Rc::new(2));
38723879
}
38733880

38743881
#[test]

0 commit comments

Comments
 (0)