Skip to content

Commit 2e4cd83

Browse files
committed
auto merge of #11082 : brson/rust/noat, r=alexcrichton
2 parents 9b1e7db + 6f16df4 commit 2e4cd83

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
@@ -3254,7 +3254,7 @@ mod tests {
32543254

32553255
#[test]
32563256
fn test_truncate() {
3257-
let mut v = ~[@6,@5,@4];
3257+
let mut v = ~[~6,~5,~4];
32583258
v.truncate(1);
32593259
assert_eq!(v.len(), 1);
32603260
assert_eq!(*(v[0]), 6);
@@ -3263,7 +3263,7 @@ mod tests {
32633263

32643264
#[test]
32653265
fn test_clear() {
3266-
let mut v = ~[@6,@5,@4];
3266+
let mut v = ~[~6,~5,~4];
32673267
v.clear();
32683268
assert_eq!(v.len(), 0);
32693269
// If the unsafe block didn't drop things properly, we blow up here.
@@ -3302,14 +3302,14 @@ mod tests {
33023302

33033303
#[test]
33043304
fn test_dedup_shared() {
3305-
let mut v0 = ~[@1, @1, @2, @3];
3305+
let mut v0 = ~[~1, ~1, ~2, ~3];
33063306
v0.dedup();
3307-
let mut v1 = ~[@1, @2, @2, @3];
3307+
let mut v1 = ~[~1, ~2, ~2, ~3];
33083308
v1.dedup();
3309-
let mut v2 = ~[@1, @2, @3, @3];
3309+
let mut v2 = ~[~1, ~2, ~3, ~3];
33103310
v2.dedup();
33113311
/*
3312-
* If the @pointers were leaked or otherwise misused, valgrind and/or
3312+
* If the pointers were leaked or otherwise misused, valgrind and/or
33133313
* rustrt should raise errors.
33143314
*/
33153315
}
@@ -3694,18 +3694,19 @@ mod tests {
36943694
fn test_from_fn_fail() {
36953695
from_fn(100, |v| {
36963696
if v == 50 { fail!() }
3697-
(~0, @0)
3697+
~0
36983698
});
36993699
}
37003700

37013701
#[test]
37023702
#[should_fail]
37033703
fn test_from_elem_fail() {
37043704
use cast;
3705+
use rc::Rc;
37053706

37063707
struct S {
37073708
f: int,
3708-
boxes: (~int, @int)
3709+
boxes: (~int, Rc<int>)
37093710
}
37103711

37113712
impl Clone for S {
@@ -3717,66 +3718,71 @@ mod tests {
37173718
}
37183719
}
37193720

3720-
let s = S { f: 0, boxes: (~0, @0) };
3721+
let s = S { f: 0, boxes: (~0, Rc::new(0)) };
37213722
let _ = from_elem(100, s);
37223723
}
37233724

37243725
#[test]
37253726
#[should_fail]
37263727
fn test_build_fail() {
3728+
use rc::Rc;
37273729
build(None, |push| {
3728-
push((~0, @0));
3729-
push((~0, @0));
3730-
push((~0, @0));
3731-
push((~0, @0));
3730+
push((~0, Rc::new(0)));
3731+
push((~0, Rc::new(0)));
3732+
push((~0, Rc::new(0)));
3733+
push((~0, Rc::new(0)));
37323734
fail!();
37333735
});
37343736
}
37353737

37363738
#[test]
37373739
#[should_fail]
37383740
fn test_grow_fn_fail() {
3741+
use rc::Rc;
37393742
let mut v = ~[];
37403743
v.grow_fn(100, |i| {
37413744
if i == 50 {
37423745
fail!()
37433746
}
3744-
(~0, @0)
3747+
(~0, Rc::new(0))
37453748
})
37463749
}
37473750

37483751
#[test]
37493752
#[should_fail]
37503753
fn test_map_fail() {
3751-
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
3754+
use rc::Rc;
3755+
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
37523756
let mut i = 0;
37533757
v.map(|_elt| {
37543758
if i == 2 {
37553759
fail!()
37563760
}
37573761
i += 1;
3758-
~[(~0, @0)]
3762+
~[(~0, Rc::new(0))]
37593763
});
37603764
}
37613765

37623766
#[test]
37633767
#[should_fail]
37643768
fn test_flat_map_fail() {
3765-
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
3769+
use rc::Rc;
3770+
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
37663771
let mut i = 0;
37673772
flat_map(v, |_elt| {
37683773
if i == 2 {
37693774
fail!()
37703775
}
37713776
i += 1;
3772-
~[(~0, @0)]
3777+
~[(~0, Rc::new(0))]
37733778
});
37743779
}
37753780

37763781
#[test]
37773782
#[should_fail]
37783783
fn test_permute_fail() {
3779-
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
3784+
use rc::Rc;
3785+
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
37803786
let mut i = 0;
37813787
for _ in v.permutations() {
37823788
if i == 2 {
@@ -4114,9 +4120,10 @@ mod tests {
41144120
#[test]
41154121
#[should_fail]
41164122
fn test_overflow_does_not_cause_segfault_managed() {
4117-
let mut v = ~[@1];
4123+
use rc::Rc;
4124+
let mut v = ~[Rc::new(1)];
41184125
v.reserve(-1);
4119-
v.push(@2);
4126+
v.push(Rc::new(2));
41204127
}
41214128

41224129
#[test]

0 commit comments

Comments
 (0)