diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index ad624f71d0c7a..69f1bfe939570 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -353,56 +353,56 @@ mod tests { #[test] fn test_tls_multitask() { - static my_key: Key<@~str> = &Key; - set(my_key, @~"parent data"); + static my_key: Key<~str> = &Key; + set(my_key, ~"parent data"); do task::spawn { // TLS shouldn't carry over. - assert!(get(my_key, |k| k.map(|k| *k)).is_none()); - set(my_key, @~"child data"); - assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == + assert!(get(my_key, |k| k.map(|k| (*k).clone())).is_none()); + set(my_key, ~"child data"); + assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"child data"); // should be cleaned up for us } // Must work multiple times - assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data"); - assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data"); - assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data"); + assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data"); + assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data"); + assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data"); } #[test] fn test_tls_overwrite() { - static my_key: Key<@~str> = &Key; - set(my_key, @~"first data"); - set(my_key, @~"next data"); // Shouldn't leak. - assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"next data"); + static my_key: Key<~str> = &Key; + set(my_key, ~"first data"); + set(my_key, ~"next data"); // Shouldn't leak. + assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"next data"); } #[test] fn test_tls_pop() { - static my_key: Key<@~str> = &Key; - set(my_key, @~"weasel"); - assert!(*(pop(my_key).unwrap()) == ~"weasel"); + static my_key: Key<~str> = &Key; + set(my_key, ~"weasel"); + assert!(pop(my_key).unwrap() == ~"weasel"); // Pop must remove the data from the map. assert!(pop(my_key).is_none()); } #[test] fn test_tls_modify() { - static my_key: Key<@~str> = &Key; + static my_key: Key<~str> = &Key; modify(my_key, |data| { match data { - Some(@ref val) => fail!("unwelcome value: {}", *val), - None => Some(@~"first data") + Some(ref val) => fail!("unwelcome value: {}", *val), + None => Some(~"first data") } }); modify(my_key, |data| { match data { - Some(@~"first data") => Some(@~"next data"), - Some(@ref val) => fail!("wrong value: {}", *val), + Some(~"first data") => Some(~"next data"), + Some(ref val) => fail!("wrong value: {}", *val), None => fail!("missing value") } }); - assert!(*(pop(my_key).unwrap()) == ~"next data"); + assert!(pop(my_key).unwrap() == ~"next data"); } #[test] @@ -413,67 +413,67 @@ mod tests { // to get recorded as something within a rust stack segment. Then a // subsequent upcall (esp. for logging, think vsnprintf) would run on // a stack smaller than 1 MB. - static my_key: Key<@~str> = &Key; + static my_key: Key<~str> = &Key; do task::spawn { - set(my_key, @~"hax"); + set(my_key, ~"hax"); } } #[test] fn test_tls_multiple_types() { - static str_key: Key<@~str> = &Key; - static box_key: Key<@@()> = &Key; - static int_key: Key<@int> = &Key; + static str_key: Key<~str> = &Key; + static box_key: Key<@()> = &Key; + static int_key: Key = &Key; do task::spawn { - set(str_key, @~"string data"); - set(box_key, @@()); - set(int_key, @42); + set(str_key, ~"string data"); + set(box_key, @()); + set(int_key, 42); } } #[test] fn test_tls_overwrite_multiple_types() { - static str_key: Key<@~str> = &Key; - static box_key: Key<@@()> = &Key; - static int_key: Key<@int> = &Key; + static str_key: Key<~str> = &Key; + static box_key: Key<@()> = &Key; + static int_key: Key = &Key; do task::spawn { - set(str_key, @~"string data"); - set(str_key, @~"string data 2"); - set(box_key, @@()); - set(box_key, @@()); - set(int_key, @42); + set(str_key, ~"string data"); + set(str_key, ~"string data 2"); + set(box_key, @()); + set(box_key, @()); + set(int_key, 42); // This could cause a segfault if overwriting-destruction is done // with the crazy polymorphic transmute rather than the provided // finaliser. - set(int_key, @31337); + set(int_key, 31337); } } #[test] #[should_fail] fn test_tls_cleanup_on_failure() { - static str_key: Key<@~str> = &Key; - static box_key: Key<@@()> = &Key; - static int_key: Key<@int> = &Key; - set(str_key, @~"parent data"); - set(box_key, @@()); + static str_key: Key<~str> = &Key; + static box_key: Key<@()> = &Key; + static int_key: Key = &Key; + set(str_key, ~"parent data"); + set(box_key, @()); do task::spawn { // spawn_linked - set(str_key, @~"string data"); - set(box_key, @@()); - set(int_key, @42); + set(str_key, ~"string data"); + set(box_key, @()); + set(int_key, 42); fail!(); } // Not quite nondeterministic. - set(int_key, @31337); + set(int_key, 31337); fail!(); } #[test] fn test_static_pointer() { - static key: Key<@&'static int> = &Key; + static key: Key<&'static int> = &Key; static VALUE: int = 0; - let v: @&'static int = @&VALUE; + let v: &'static int = &VALUE; set(key, v); } diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 5067f6eb1279b..0e55ad732d714 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -445,28 +445,34 @@ mod tests { #[test] fn test_get_resource() { + use rc::Rc; + use cell::RefCell; + struct R { - i: @mut int, + i: Rc>, } #[unsafe_destructor] impl ::ops::Drop for R { - fn drop(&mut self) { *(self.i) += 1; } + fn drop(&mut self) { + let ii = self.i.borrow(); + ii.set(ii.get() + 1); + } } - fn R(i: @mut int) -> R { + fn R(i: Rc>) -> R { R { i: i } } - let i = @mut 0; + let i = Rc::from_send(RefCell::new(0)); { - let x = R(i); + let x = R(i.clone()); let opt = Some(x); let _y = opt.unwrap(); } - assert_eq!(*i, 1); + assert_eq!(i.borrow().get(), 1); } #[test] diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 6eef640d91233..70df94586d08e 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -3064,7 +3064,7 @@ mod tests { #[test] fn test_truncate() { - let mut v = ~[@6,@5,@4]; + let mut v = ~[~6,~5,~4]; v.truncate(1); assert_eq!(v.len(), 1); assert_eq!(*(v[0]), 6); @@ -3073,7 +3073,7 @@ mod tests { #[test] fn test_clear() { - let mut v = ~[@6,@5,@4]; + let mut v = ~[~6,~5,~4]; v.clear(); assert_eq!(v.len(), 0); // If the unsafe block didn't drop things properly, we blow up here. @@ -3112,14 +3112,14 @@ mod tests { #[test] fn test_dedup_shared() { - let mut v0 = ~[@1, @1, @2, @3]; + let mut v0 = ~[~1, ~1, ~2, ~3]; v0.dedup(); - let mut v1 = ~[@1, @2, @2, @3]; + let mut v1 = ~[~1, ~2, ~2, ~3]; v1.dedup(); - let mut v2 = ~[@1, @2, @3, @3]; + let mut v2 = ~[~1, ~2, ~3, ~3]; v2.dedup(); /* - * If the @pointers were leaked or otherwise misused, valgrind and/or + * If the pointers were leaked or otherwise misused, valgrind and/or * rustrt should raise errors. */ } @@ -3446,7 +3446,7 @@ mod tests { fn test_from_fn_fail() { from_fn(100, |v| { if v == 50 { fail!() } - (~0, @0) + ~0 }); } @@ -3454,10 +3454,11 @@ mod tests { #[should_fail] fn test_from_elem_fail() { use cast; + use rc::Rc; struct S { f: int, - boxes: (~int, @int) + boxes: (~int, Rc) } impl Clone for S { @@ -3469,18 +3470,19 @@ mod tests { } } - let s = S { f: 0, boxes: (~0, @0) }; + let s = S { f: 0, boxes: (~0, Rc::new(0)) }; let _ = from_elem(100, s); } #[test] #[should_fail] fn test_build_fail() { + use rc::Rc; build(None, |push| { - push((~0, @0)); - push((~0, @0)); - push((~0, @0)); - push((~0, @0)); + push((~0, Rc::new(0))); + push((~0, Rc::new(0))); + push((~0, Rc::new(0))); + push((~0, Rc::new(0))); fail!(); }); } @@ -3488,47 +3490,51 @@ mod tests { #[test] #[should_fail] fn test_grow_fn_fail() { + use rc::Rc; let mut v = ~[]; v.grow_fn(100, |i| { if i == 50 { fail!() } - (~0, @0) + (~0, Rc::new(0)) }) } #[test] #[should_fail] fn test_map_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; + use rc::Rc; + let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))]; let mut i = 0; v.map(|_elt| { if i == 2 { fail!() } i += 1; - ~[(~0, @0)] + ~[(~0, Rc::new(0))] }); } #[test] #[should_fail] fn test_flat_map_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; + use rc::Rc; + let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))]; let mut i = 0; flat_map(v, |_elt| { if i == 2 { fail!() } i += 1; - ~[(~0, @0)] + ~[(~0, Rc::new(0))] }); } #[test] #[should_fail] fn test_permute_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; + use rc::Rc; + let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))]; let mut i = 0; for _ in v.permutations() { if i == 2 { @@ -3866,9 +3872,10 @@ mod tests { #[test] #[should_fail] fn test_overflow_does_not_cause_segfault_managed() { - let mut v = ~[@1]; + use rc::Rc; + let mut v = ~[Rc::new(1)]; v.reserve(-1); - v.push(@2); + v.push(Rc::new(2)); } #[test]