diff --git a/src/doc/guide-ffi.md b/src/doc/guide-ffi.md index f0ffd46e6c2cc..059ae4cb308e9 100644 --- a/src/doc/guide-ffi.md +++ b/src/doc/guide-ffi.md @@ -293,7 +293,7 @@ extern { fn main() { // Create the object that will be referenced in the callback - let mut rust_object = ~RustObject{ a: 5 }; + let mut rust_object = box RustObject { a: 5 }; unsafe { register_callback(&mut *rust_object, callback); diff --git a/src/doc/guide-lifetimes.md b/src/doc/guide-lifetimes.md index c734eccddc04e..48c50471c25f5 100644 --- a/src/doc/guide-lifetimes.md +++ b/src/doc/guide-lifetimes.md @@ -41,9 +41,9 @@ point, but allocated in a different place: ~~~ # struct Point {x: f64, y: f64} -let on_the_stack : Point = Point {x: 3.0, y: 4.0}; -let managed_box : @Point = @Point {x: 5.0, y: 1.0}; -let owned_box : ~Point = ~Point {x: 7.0, y: 9.0}; +let on_the_stack : Point = Point {x: 3.0, y: 4.0}; +let managed_box : @Point = @Point {x: 5.0, y: 1.0}; +let owned_box : Box = box Point {x: 7.0, y: 9.0}; ~~~ Suppose we wanted to write a procedure that computed the distance between any @@ -72,9 +72,9 @@ Now we can call `compute_distance()` in various ways: ~~~ # struct Point {x: f64, y: f64} -# let on_the_stack : Point = Point{x: 3.0, y: 4.0}; -# let managed_box : @Point = @Point{x: 5.0, y: 1.0}; -# let owned_box : ~Point = ~Point{x: 7.0, y: 9.0}; +# let on_the_stack : Point = Point{x: 3.0, y: 4.0}; +# let managed_box : @Point = @Point{x: 5.0, y: 1.0}; +# let owned_box : Box = box Point{x: 7.0, y: 9.0}; # fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } compute_distance(&on_the_stack, managed_box); compute_distance(managed_box, owned_box); @@ -151,12 +151,12 @@ Now, as before, we can define rectangles in a few different ways: # struct Point {x: f64, y: f64} # struct Size {w: f64, h: f64} // as before # struct Rectangle {origin: Point, size: Size} -let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, - size: Size {w: 3.0, h: 4.0}}; -let rect_managed = @Rectangle {origin: Point {x: 3.0, y: 4.0}, - size: Size {w: 3.0, h: 4.0}}; -let rect_owned = ~Rectangle {origin: Point {x: 5.0, y: 6.0}, - size: Size {w: 3.0, h: 4.0}}; +let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, + size: Size {w: 3.0, h: 4.0}}; +let rect_managed = @Rectangle {origin: Point {x: 3.0, y: 4.0}, + size: Size {w: 3.0, h: 4.0}}; +let rect_owned = box Rectangle {origin: Point {x: 5.0, y: 6.0}, + size: Size {w: 3.0, h: 4.0}}; ~~~ In each case, we can extract out individual subcomponents with the `&` @@ -168,7 +168,7 @@ operator. For example, I could write: # struct Rectangle {origin: Point, size: Size} # let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, size: Size {w: 3.0, h: 4.0}}; # let rect_managed = @Rectangle {origin: Point {x: 3.0, y: 4.0}, size: Size {w: 3.0, h: 4.0}}; -# let rect_owned = ~Rectangle {origin: Point {x: 5.0, y: 6.0}, size: Size {w: 3.0, h: 4.0}}; +# let rect_owned = box Rectangle {origin: Point {x: 5.0, y: 6.0}, size: Size {w: 3.0, h: 4.0}}; # fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } compute_distance(&rect_stack.origin, &rect_managed.origin); ~~~ @@ -276,12 +276,12 @@ the following function is legal: # fn some_condition() -> bool { true } # struct Foo { f: int } fn example3() -> int { - let mut x = ~Foo {f: 3}; + let mut x = box Foo {f: 3}; if some_condition() { let y = &x.f; // -+ L return *y; // | } // -+ - x = ~Foo {f: 4}; + x = box Foo {f: 4}; // ... # return 0; } @@ -301,9 +301,9 @@ rejected by the compiler): ~~~ {.ignore} fn example3() -> int { - let mut x = ~X {f: 3}; + let mut x = box X {f: 3}; let y = &x.f; - x = ~X {f: 4}; // Error reported here. + x = box X {f: 4}; // Error reported here. *y } ~~~ @@ -314,13 +314,13 @@ memory immediately before the re-assignment of `x`: ~~~ {.notrust} Stack Exchange Heap - x +----------+ - | ~{f:int} | ----+ - y +----------+ | - | &int | ----+ - +----------+ | +---------+ - +--> | f: 3 | - +---------+ + x +-------------+ + | box {f:int} | ----+ + y +-------------+ | + | &int | ----+ + +-------------+ | +---------+ + +--> | f: 3 | + +---------+ ~~~ Once the reassignment occurs, the memory will look like this: @@ -328,13 +328,13 @@ Once the reassignment occurs, the memory will look like this: ~~~ {.notrust} Stack Exchange Heap - x +----------+ +---------+ - | ~{f:int} | -------> | f: 4 | - y +----------+ +---------+ - | &int | ----+ - +----------+ | +---------+ - +--> | (freed) | - +---------+ + x +-------------+ +---------+ + | box {f:int} | -------> | f: 4 | + y +-------------+ +---------+ + | &int | ----+ + +-------------+ | +---------+ + +--> | (freed) | + +---------+ ~~~ Here you can see that the variable `y` still points at the old box, @@ -349,12 +349,12 @@ mutations: ~~~ {.ignore} fn example3() -> int { struct R { g: int } - struct S { f: ~R } + struct S { f: Box } - let mut x = ~S {f: ~R {g: 3}}; + let mut x = box S {f: box R {g: 3}}; let y = &x.f.g; - x = ~S {f: ~R {g: 4}}; // Error reported here. - x.f = ~R {g: 5}; // Error reported here. + x = box S {f: box R {g: 4}}; // Error reported here. + x.f = box R {g: 5}; // Error reported here. *y } ~~~ diff --git a/src/doc/guide-pointers.md b/src/doc/guide-pointers.md index fa813073cd984..46564e6712896 100644 --- a/src/doc/guide-pointers.md +++ b/src/doc/guide-pointers.md @@ -182,13 +182,14 @@ trait. Therefore, unboxed traits don't make any sense, and aren't allowed. Sometimes, you need a recursive data structure. The simplest is known as a 'cons list': ~~~rust + enum List { Nil, - Cons(T, ~List), + Cons(T, Box>), } fn main() { - let list: List = Cons(1, ~Cons(2, ~Cons(3, ~Nil))); + let list: List = Cons(1, box Cons(2, box Cons(3, box Nil))); println!("{:?}", list); } ~~~ @@ -196,7 +197,7 @@ fn main() { This prints: ~~~ {.notrust} -Cons(1, ~Cons(2, ~Cons(3, ~Nil))) +Cons(1, box Cons(2, box Cons(3, box Nil))) ~~~ The inner lists _must_ be an owned pointer, because we can't know how many @@ -237,7 +238,7 @@ struct Point { } fn main() { - let a = ~Point { x: 10, y: 20 }; + let a = box Point { x: 10, y: 20 }; spawn(proc() { println!("{}", a.x); }); @@ -268,7 +269,7 @@ struct Point { } fn main() { - let a = ~Point { x: 10, y: 20 }; + let a = box Point { x: 10, y: 20 }; let b = a; println!("{}", b.x); println!("{}", a.x); @@ -285,7 +286,7 @@ note: in expansion of format_args! :158:27: 158:81 note: expansion site :157:5: 159:6 note: in expansion of println! test.rs:10:5: 10:25 note: expansion site -test.rs:8:9: 8:10 note: `a` moved here because it has type `~Point`, which is moved by default (use `ref` to override) +test.rs:8:9: 8:10 note: `a` moved here because it has type `Box`, which is moved by default (use `ref` to override) test.rs:8 let b = a; ^ ~~~ @@ -345,8 +346,8 @@ fn compute_distance(p1: &Point, p2: &Point) -> f32 { } fn main() { - let origin = @Point { x: 0.0, y: 0.0 }; - let p1 = ~Point { x: 5.0, y: 3.0 }; + let origin = @Point { x: 0.0, y: 0.0 }; + let p1 = box Point { x: 5.0, y: 3.0 }; println!("{:?}", compute_distance(origin, p1)); } @@ -381,7 +382,7 @@ duration a 'lifetime'. Let's try a more complex example: ~~~rust fn main() { - let mut x = ~5; + let mut x = box 5; if *x < 10 { let y = &x; println!("Oh no: {:?}", y); @@ -398,7 +399,7 @@ mutated, and therefore, lets us pass. This wouldn't work: ~~~rust{.ignore} fn main() { - let mut x = ~5; + let mut x = box 5; if *x < 10 { let y = &x; *x -= 1; @@ -437,12 +438,12 @@ is best. What does that mean? Don't do this: ~~~rust -fn foo(x: ~int) -> ~int { - return ~*x; +fn foo(x: Box) -> Box { + return box *x; } fn main() { - let x = ~5; + let x = box 5; let y = foo(x); } ~~~ @@ -450,13 +451,13 @@ fn main() { Do this: ~~~rust -fn foo(x: ~int) -> int { +fn foo(x: Box) -> int { return *x; } fn main() { - let x = ~5; - let y = ~foo(x); + let x = box 5; + let y = box foo(x); } ~~~ @@ -464,12 +465,12 @@ This gives you flexibility, without sacrificing performance. For example, this w also work: ~~~rust -fn foo(x: ~int) -> int { +fn foo(x: Box) -> int { return *x; } fn main() { - let x = ~5; + let x = box 5; let y = @foo(x); } ~~~ diff --git a/src/doc/guide-unsafe.md b/src/doc/guide-unsafe.md index 300c5bae96482..fc6a12b495e2e 100644 --- a/src/doc/guide-unsafe.md +++ b/src/doc/guide-unsafe.md @@ -258,10 +258,10 @@ impl Drop for Unique { } } -// A comparison between the built-in ~ and this reimplementation +// A comparison between the built-in `Box` and this reimplementation fn main() { { - let mut x = ~5; + let mut x = box 5; *x = 10; } // `x` is freed here diff --git a/src/doc/intro.md b/src/doc/intro.md index 94cbc8e0e0ac3..71356eba6d91e 100644 --- a/src/doc/intro.md +++ b/src/doc/intro.md @@ -127,12 +127,13 @@ That's a great example for stack memory, but what about heap memory? Rust has a second kind of pointer, an 'owned box', -that you can create with a `~`. +that you can create with the `box` operator. Check it out: ``` -fn dangling() -> ~int { - let i = ~1234; + +fn dangling() -> Box { + let i = box 1234; return i; } @@ -143,7 +144,7 @@ fn add_one() -> int { ``` Now instead of a stack allocated `1234`, -we have a heap allocated `~1234`. +we have a heap allocated `box 1234`. Whereas `&` borrows a pointer to existing memory, creating an owned box allocates memory on the heap and places a value in it, giving you the sole pointer to that memory. @@ -151,7 +152,7 @@ You can roughly compare these two lines: ``` // Rust -let i = ~1234; +let i = box 1234; ``` ```notrust diff --git a/src/doc/rust.md b/src/doc/rust.md index 12d2911f5291d..a954a49a9ba3d 100644 --- a/src/doc/rust.md +++ b/src/doc/rust.md @@ -1393,7 +1393,7 @@ to pointers to the trait name, used as a type. # trait Shape { } # impl Shape for int { } # let mycircle = 0; -let myshape: ~Shape = ~mycircle as ~Shape; +let myshape: Box = box mycircle as Box; ~~~~ The resulting value is a managed box containing the value that was cast, @@ -3041,19 +3041,19 @@ stands for a *single* data field, whereas a wildcard `..` stands for *all* the fields of a particular variant. For example: ~~~~ -enum List { Nil, Cons(X, ~List) } +enum List { Nil, Cons(X, Box>) } -let x: List = Cons(10, ~Cons(11, ~Nil)); +let x: List = Cons(10, box Cons(11, box Nil)); match x { - Cons(_, ~Nil) => fail!("singleton list"), - Cons(..) => return, - Nil => fail!("empty list") + Cons(_, box Nil) => fail!("singleton list"), + Cons(..) => return, + Nil => fail!("empty list") } ~~~~ The first pattern matches lists constructed by applying `Cons` to any head -value, and a tail value of `~Nil`. The second pattern matches _any_ list +value, and a tail value of `box Nil`. The second pattern matches _any_ list constructed with `Cons`, ignoring the values of its arguments. The difference between `_` and `..` is that the pattern `C(_)` is only type-correct if `C` has exactly one argument, while the pattern `C(..)` is type-correct for any enum @@ -3103,12 +3103,12 @@ An example of a `match` expression: # fn process_pair(a: int, b: int) { } # fn process_ten() { } -enum List { Nil, Cons(X, ~List) } +enum List { Nil, Cons(X, Box>) } -let x: List = Cons(10, ~Cons(11, ~Nil)); +let x: List = Cons(10, box Cons(11, box Nil)); match x { - Cons(a, ~Cons(b, _)) => { + Cons(a, box Cons(b, _)) => { process_pair(a,b); } Cons(10, _) => { @@ -3135,17 +3135,17 @@ Subpatterns can also be bound to variables by the use of the syntax For example: ~~~~ -enum List { Nil, Cons(uint, ~List) } +enum List { Nil, Cons(uint, Box) } fn is_sorted(list: &List) -> bool { match *list { - Nil | Cons(_, ~Nil) => true, - Cons(x, ref r @ ~Cons(y, _)) => (x <= y) && is_sorted(*r) + Nil | Cons(_, box Nil) => true, + Cons(x, ref r @ box Cons(y, _)) => (x <= y) && is_sorted(*r) } } fn main() { - let a = Cons(6, ~Cons(7, ~Cons(42, ~Nil))); + let a = Cons(6, box Cons(7, box Cons(42, box Nil))); assert!(is_sorted(&a)); } @@ -3411,10 +3411,10 @@ An example of a *recursive* type and its use: ~~~~ enum List { Nil, - Cons(T, ~List) + Cons(T, Box>) } -let a: List = Cons(7, ~Cons(13, ~Nil)); +let a: List = Cons(7, box Cons(13, box Nil)); ~~~~ ### Pointer types @@ -3563,12 +3563,12 @@ impl Printable for int { fn to_string(&self) -> ~str { self.to_str() } } -fn print(a: ~Printable) { +fn print(a: Box) { println!("{}", a.to_string()); } fn main() { - print(~10 as ~Printable); + print(box 10 as Box); } ~~~~ @@ -3755,7 +3755,7 @@ mutable slot by prefixing them with `mut` (similar to regular arguments): ~~~ trait Changer { fn change(mut self) -> Self; - fn modify(mut ~self) -> ~Self; + fn modify(mut ~self) -> Box; } ~~~ @@ -3768,12 +3768,14 @@ initialized; this is enforced by the compiler. ### Owned boxes An _owned box_ is a reference to a heap allocation holding another value, which is constructed -by the prefix *tilde* sigil `~`. +by the prefix operator `box`. When the standard library is in use, the type of an owned box is +`std::owned::Box`. An example of an owned box type and value: ~~~~ -let x: ~int = ~10; + +let x: Box = box 10; ~~~~ Owned box values exist in 1:1 correspondence with their heap allocation @@ -3781,7 +3783,7 @@ copying an owned box value makes a shallow copy of the pointer Rust will consider a shallow copy of an owned box to move ownership of the value. After a value has been moved, the source location cannot be used unless it is reinitialized. ~~~~ -let x: ~int = ~10; +let x: Box = box 10; let y = x; // attempting to use `x` will result in an error here ~~~~ diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index 0635f4111e550..e1e6d5a0e1576 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -911,12 +911,12 @@ Objects are never accessible after their destructor has been called, so no dynamic failures are possible from accessing freed resources. When a task fails, destructors of all objects in the task are called. -The `~` sigil represents a unique handle for a memory allocation on the heap: +The `box` operator performs memory allocation on the heap: ~~~~ { // an integer allocated on the heap - let y = ~10; + let y = box 10; } // the destructor frees the heap memory as soon as `y` goes out of scope ~~~~ @@ -938,17 +938,17 @@ and destroy the contained object when they go out of scope. ~~~~ // the struct owns the objects contained in the `x` and `y` fields -struct Foo { x: int, y: ~int } +struct Foo { x: int, y: Box } { // `a` is the owner of the struct, and thus the owner of the struct's fields - let a = Foo { x: 5, y: ~10 }; + let a = Foo { x: 5, y: box 10 }; } // when `a` goes out of scope, the destructor for the `~int` in the struct's // field is called // `b` is mutable, and the mutability is inherited by the objects it owns -let mut b = Foo { x: 5, y: ~10 }; +let mut b = Foo { x: 5, y: box 10 }; b.x = 10; ~~~~ @@ -1021,13 +1021,15 @@ Our previous attempt at defining the `List` type included an `u32` and a `List` directly inside `Cons`, making it at least as big as the sum of both types. The type was invalid because the size was infinite! -An *owned box* (`~`) uses a dynamic memory allocation to provide the invariant -of always being the size of a pointer, regardless of the contained type. This -can be leveraged to create a valid `List` definition: +An *owned box* (`Box`, located in the `std::owned` module) uses a dynamic memory +allocation to provide the invariant of always being the size of a pointer, +regardless of the contained type. This can be leveraged to create a valid `List` +definition: ~~~ + enum List { - Cons(u32, ~List), + Cons(u32, Box), Nil } ~~~ @@ -1040,10 +1042,10 @@ Consider an instance of our `List` type: ~~~ # enum List { -# Cons(u32, ~List), +# Cons(u32, Box), # Nil # } -let list = Cons(1, ~Cons(2, ~Cons(3, ~Nil))); +let list = Cons(1, box Cons(2, box Cons(3, box Nil))); ~~~ It represents an owned tree of values, inheriting mutability down the tree and @@ -1054,7 +1056,7 @@ box, while the owner holds onto a pointer to it: ~~~ {.notrust} List box List box List box List box +--------------+ +--------------+ +--------------+ +----------+ -list -> | Cons | 1 | ~ | -> | Cons | 2 | ~ | -> | Cons | 3 | ~ | -> | Nil | +list -> | Cons | 1 | | -> | Cons | 2 | | -> | Cons | 3 | | -> | Nil | +--------------+ +--------------+ +--------------+ +----------+ ~~~ @@ -1074,10 +1076,10 @@ the box rather than doing an implicit heap allocation. ~~~ # enum List { -# Cons(u32, ~List), +# Cons(u32, Box), # Nil # } -let xs = Cons(1, ~Cons(2, ~Cons(3, ~Nil))); +let xs = Cons(1, box Cons(2, box Cons(3, box Nil))); let ys = xs; // copies `Cons(u32, pointer)` shallowly ~~~ @@ -1087,7 +1089,7 @@ location cannot be used unless it is reinitialized. ~~~ # enum List { -# Cons(u32, ~List), +# Cons(u32, Box), # Nil # } let mut xs = Nil; @@ -1107,7 +1109,7 @@ as it is only called a single time. Avoiding a move can be done with the library-defined `clone` method: ~~~~ -let x = ~5; +let x = box 5; let y = x.clone(); // `y` is a newly allocated box let z = x; // no new memory allocated, `x` can no longer be used ~~~~ @@ -1118,11 +1120,11 @@ our `List` type. Traits will be explained in detail [later](#traits). ~~~{.ignore} #[deriving(Clone)] enum List { - Cons(u32, ~List), + Cons(u32, Box), Nil } -let x = Cons(5, ~Nil); +let x = Cons(5, box Nil); let y = x.clone(); // `x` can still be used! @@ -1135,7 +1137,7 @@ let z = x; The mutability of a value may be changed by moving it to a new owner: ~~~~ -let r = ~13; +let r = box 13; let mut s = r; // box becomes mutable *s += 1; let t = s; // box becomes immutable @@ -1146,12 +1148,12 @@ advantage of moves: ~~~ enum List { - Cons(u32, ~List), + Cons(u32, Box), Nil } fn prepend(xs: List, value: u32) -> List { - Cons(value, ~xs) + Cons(value, box xs) } let mut xs = Nil; @@ -1186,7 +1188,7 @@ by-value. A recursive definition of equality using references is as follows: ~~~ # enum List { -# Cons(u32, ~List), +# Cons(u32, Box), # Nil # } fn eq(xs: &List, ys: &List) -> bool { @@ -1195,15 +1197,15 @@ fn eq(xs: &List, ys: &List) -> bool { // If we have reached the end of both lists, they are equal. (&Nil, &Nil) => true, // If the current elements of both lists are equal, keep going. - (&Cons(x, ~ref next_xs), &Cons(y, ~ref next_ys)) + (&Cons(x, box ref next_xs), &Cons(y, box ref next_ys)) if x == y => eq(next_xs, next_ys), // If the current elements are not equal, the lists are not equal. _ => false } } -let xs = Cons(5, ~Cons(10, ~Nil)); -let ys = Cons(5, ~Cons(10, ~Nil)); +let xs = Cons(5, box Cons(10, box Nil)); +let ys = Cons(5, box Cons(10, box Nil)); assert!(eq(&xs, &ys)); ~~~ @@ -1223,7 +1225,7 @@ The `u32` in the previous definition can be substituted with a type parameter: ~~~ enum List { - Cons(T, ~List), + Cons(T, Box>), Nil } ~~~ @@ -1233,11 +1235,11 @@ definition has to be updated too: ~~~ # enum List { -# Cons(T, ~List), +# Cons(T, Box>), # Nil # } fn prepend(xs: List, value: T) -> List { - Cons(value, ~xs) + Cons(value, box xs) } ~~~ @@ -1248,11 +1250,11 @@ Using the generic `List` works much like before, thanks to type inference: ~~~ # enum List { -# Cons(T, ~List), +# Cons(T, Box>), # Nil # } # fn prepend(xs: List, value: T) -> List { -# Cons(value, ~xs) +# Cons(value, box xs) # } let mut xs = Nil; // Unknown type! This is a `List`, but `T` can be anything. xs = prepend(xs, 10); // Here the compiler infers `xs`'s type as `List`. @@ -1265,11 +1267,11 @@ equivalent to the following type-annotated code: ~~~ # enum List { -# Cons(T, ~List), +# Cons(T, Box>), # Nil # } # fn prepend(xs: List, value: T) -> List { -# Cons(value, ~xs) +# Cons(value, box xs) # } let mut xs: List = Nil::; xs = prepend::(xs, 10); @@ -1293,7 +1295,7 @@ Two more `ref` annotations need to be added to avoid attempting to move out the ~~~ # enum List { -# Cons(T, ~List), +# Cons(T, Box>), # Nil # } fn eq(xs: &List, ys: &List) -> bool { @@ -1302,15 +1304,15 @@ fn eq(xs: &List, ys: &List) -> bool { // If we have reached the end of both lists, they are equal. (&Nil, &Nil) => true, // If the current elements of both lists are equal, keep going. - (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys)) + (&Cons(ref x, box ref next_xs), &Cons(ref y, box ref next_ys)) if x == y => eq(next_xs, next_ys), // If the current elements are not equal, the lists are not equal. _ => false } } -let xs = Cons('c', ~Cons('a', ~Cons('t', ~Nil))); -let ys = Cons('c', ~Cons('a', ~Cons('t', ~Nil))); +let xs = Cons('c', box Cons('a', box Cons('t', box Nil))); +let ys = Cons('c', box Cons('a', box Cons('t', box Nil))); assert!(eq(&xs, &ys)); ~~~ @@ -1321,7 +1323,7 @@ on. ~~~ # enum List { -# Cons(T, ~List), +# Cons(T, Box>), # Nil # } impl Eq for List { @@ -1331,7 +1333,7 @@ impl Eq for List { // If we have reached the end of both lists, they are equal. (&Nil, &Nil) => true, // If the current elements of both lists are equal, keep going. - (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys)) + (&Cons(ref x, box ref next_xs), &Cons(ref y, box ref next_ys)) if x == y => next_xs == next_ys, // If the current elements are not equal, the lists are not equal. _ => false @@ -1339,8 +1341,8 @@ impl Eq for List { } } -let xs = Cons(5, ~Cons(10, ~Nil)); -let ys = Cons(5, ~Cons(10, ~Nil)); +let xs = Cons(5, box Cons(10, box Nil)); +let ys = Cons(5, box Cons(10, box Nil)); // The methods below are part of the Eq trait, // which we implemented on our linked list. assert!(xs.eq(&ys)); @@ -1373,7 +1375,7 @@ fn foo() -> (u64, u64, u64, u64, u64, u64) { (5, 5, 5, 5, 5, 5) } -let x = ~foo(); // allocates a `~` box, and writes the integers directly to it +let x = box foo(); // allocates a box, and writes the integers directly to it ~~~~ Beyond the properties granted by the size, an owned box behaves as a regular @@ -1384,8 +1386,8 @@ let x = 5; // immutable let mut y = 5; // mutable y += 2; -let x = ~5; // immutable -let mut y = ~5; // mutable +let x = box 5; // immutable +let mut y = box 5; // mutable *y += 2; // the `*` operator is needed to access the contained value ~~~~ @@ -1413,8 +1415,8 @@ contains a point, but allocated in a different location: ~~~ # struct Point { x: f64, y: f64 } -let on_the_stack : Point = Point { x: 3.0, y: 4.0 }; -let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 }; +let on_the_stack : Point = Point { x: 3.0, y: 4.0 }; +let owned_box : Box = box Point { x: 7.0, y: 9.0 }; ~~~ Suppose we want to write a procedure that computes the distance @@ -1438,8 +1440,8 @@ Now we can call `compute_distance()` in various ways: ~~~ # struct Point{ x: f64, y: f64 }; -# let on_the_stack : Point = Point { x: 3.0, y: 4.0 }; -# let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 }; +# let on_the_stack : Point = Point { x: 3.0, y: 4.0 }; +# let owned_box : Box = box Point { x: 7.0, y: 9.0 }; # fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } compute_distance(&on_the_stack, owned_box); ~~~ @@ -1453,7 +1455,7 @@ route to the same data. In the case of `owned_box`, however, no explicit action is necessary. The compiler will automatically convert -a box `~point` to a reference like +a box `box point` to a reference like `&point`. This is another form of borrowing; in this case, the contents of the owned box are being lent out. @@ -1492,7 +1494,7 @@ Rust uses the unary star operator (`*`) to access the contents of a box or pointer, similarly to C. ~~~ -let owned = ~10; +let owned = box 10; let borrowed = &20; let sum = *owned + *borrowed; @@ -1503,7 +1505,7 @@ assignments. Such an assignment modifies the value that the pointer points to. ~~~ -let mut owned = ~10; +let mut owned = box 10; let mut value = 20; let borrowed = &mut value; @@ -1520,8 +1522,8 @@ can sometimes make code awkward and parenthesis-filled. # struct Point { x: f64, y: f64 } # enum Shape { Rectangle(Point, Point) } # impl Shape { fn area(&self) -> int { 0 } } -let start = ~Point { x: 10.0, y: 20.0 }; -let end = ~Point { x: (*start).x + 100.0, y: (*start).y + 100.0 }; +let start = box Point { x: 10.0, y: 20.0 }; +let end = box Point { x: (*start).x + 100.0, y: (*start).y + 100.0 }; let rect = &Rectangle(*start, *end); let area = (*rect).area(); ~~~ @@ -1534,8 +1536,8 @@ dot), so in most cases, explicitly dereferencing the receiver is not necessary. # struct Point { x: f64, y: f64 } # enum Shape { Rectangle(Point, Point) } # impl Shape { fn area(&self) -> int { 0 } } -let start = ~Point { x: 10.0, y: 20.0 }; -let end = ~Point { x: start.x + 100.0, y: start.y + 100.0 }; +let start = box Point { x: 10.0, y: 20.0 }; +let end = box Point { x: start.x + 100.0, y: start.y + 100.0 }; let rect = &Rectangle(*start, *end); let area = rect.area(); ~~~ @@ -1546,7 +1548,7 @@ something silly like ~~~ # struct Point { x: f64, y: f64 } -let point = &~Point { x: 10.0, y: 20.0 }; +let point = &box Point { x: 10.0, y: 20.0 }; println!("{:f}", point.x); ~~~ @@ -1944,7 +1946,7 @@ impl Shape { let s = Circle(Point { x: 1.0, y: 2.0 }, 3.0); (&s).draw_reference(); -(~s).draw_owned(); +(box s).draw_owned(); s.draw_value(); ~~~ @@ -1969,7 +1971,7 @@ to a reference. // As with typical function arguments, owned pointers // are automatically converted to references -(~s).draw_reference(); +(box s).draw_reference(); // Unlike typical function arguments, the self value will // automatically be referenced ... @@ -1979,7 +1981,7 @@ s.draw_reference(); (& &s).draw_reference(); // ... and dereferenced and borrowed -(&~s).draw_reference(); +(&box s).draw_reference(); ~~~ Implementations may also define standalone (sometimes called "static") @@ -2433,7 +2435,7 @@ an _object_. ~~~~ # trait Drawable { fn draw(&self); } -fn draw_all(shapes: &[~Drawable]) { +fn draw_all(shapes: &[Box]) { for shape in shapes.iter() { shape.draw(); } } ~~~~ @@ -2448,14 +2450,14 @@ to an object: # trait Drawable { fn draw(&self); } # fn new_circle() -> Circle { 1 } # fn new_rectangle() -> Rectangle { true } -# fn draw_all(shapes: &[~Drawable]) {} +# fn draw_all(shapes: &[Box]) {} impl Drawable for Circle { fn draw(&self) { /* ... */ } } impl Drawable for Rectangle { fn draw(&self) { /* ... */ } } -let c: ~Circle = ~new_circle(); -let r: ~Rectangle = ~new_rectangle(); -draw_all([c as ~Drawable, r as ~Drawable]); +let c: Box = box new_circle(); +let r: Box = box new_rectangle(); +draw_all([c as Box, r as Box]); ~~~~ We omit the code for `new_circle` and `new_rectangle`; imagine that @@ -2464,7 +2466,7 @@ that, like strings and vectors, objects have dynamic size and may only be referred to via one of the pointer types. Other pointer types work as well. Casts to traits may only be done with compatible pointers so, -for example, an `&Circle` may not be cast to an `~Drawable`. +for example, an `&Circle` may not be cast to a `Box`. ~~~ # type Circle = int; type Rectangle = int; @@ -2473,7 +2475,7 @@ for example, an `&Circle` may not be cast to an `~Drawable`. # fn new_circle() -> int { 1 } # fn new_rectangle() -> int { 2 } // An owned object -let owny: ~Drawable = ~new_circle() as ~Drawable; +let owny: Box = box new_circle() as Box; // A borrowed object let stacky: &Drawable = &new_circle() as &Drawable; ~~~ @@ -2497,7 +2499,7 @@ valid types: trait Foo {} trait Bar {} -fn sendable_foo(f: ~Foo:Send) { /* ... */ } +fn sendable_foo(f: Box) { /* ... */ } fn shareable_bar(b: &Bar: Share) { /* ... */ } ~~~ diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index d80385587dad5..24e7a65e02a0a 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -29,14 +29,14 @@ extern crate collections; use std::cast::{transmute, transmute_mut_lifetime}; use std::cast; use std::cell::{Cell, RefCell}; -use std::mem; -use std::ptr::read; use std::cmp; +use std::intrinsics::{TyDesc, get_tydesc}; +use std::intrinsics; +use std::mem; use std::num; +use std::ptr::read; use std::rc::Rc; use std::rt::global_heap; -use std::intrinsics::{TyDesc, get_tydesc}; -use std::intrinsics; // The way arena uses arrays is really deeply awful. The arrays are // allocated, and have capacities reserved, but the fill for the array @@ -339,12 +339,12 @@ pub struct TypedArena { end: *T, /// A pointer to the first arena segment. - first: Option<~TypedArenaChunk>, + first: Option>>, } struct TypedArenaChunk { /// Pointer to the next arena segment. - next: Option<~TypedArenaChunk>, + next: Option>>, /// The number of elements that this chunk can hold. capacity: uint, @@ -354,7 +354,8 @@ struct TypedArenaChunk { impl TypedArenaChunk { #[inline] - fn new(next: Option<~TypedArenaChunk>, capacity: uint) -> ~TypedArenaChunk { + fn new(next: Option>>, capacity: uint) + -> Box> { let mut size = mem::size_of::>(); size = round_up(size, mem::min_align_of::()); let elem_size = mem::size_of::(); @@ -363,7 +364,7 @@ impl TypedArenaChunk { let mut chunk = unsafe { let chunk = global_heap::exchange_malloc(size); - let mut chunk: ~TypedArenaChunk = cast::transmute(chunk); + let mut chunk: Box> = cast::transmute(chunk); mem::move_val_init(&mut chunk.next, next); chunk }; diff --git a/src/libcollections/btree.rs b/src/libcollections/btree.rs index 30add69564640..245040d791cff 100644 --- a/src/libcollections/btree.rs +++ b/src/libcollections/btree.rs @@ -140,7 +140,8 @@ impl Node { } ///Creates a new branch node given a vector of an elements and a pointer to a rightmost child. - fn new_branch(vec: Vec>, right: ~Node) -> Node { + fn new_branch(vec: Vec>, right: Box>) + -> Node { BranchNode(Branch::new(vec, right)) } @@ -270,7 +271,7 @@ struct Leaf { //Vector of values with children, plus a rightmost child (greater than all) struct Branch { elts: Vec>, - rightmost_child: ~Node + rightmost_child: Box>, } @@ -434,7 +435,8 @@ impl fmt::Show for Leaf { impl Branch { ///Creates a new Branch from a vector of BranchElts and a rightmost child (a node). - fn new(vec: Vec>, right: ~Node) -> Branch { + fn new(vec: Vec>, right: Box>) + -> Branch { Branch { elts: vec, rightmost_child: right @@ -667,7 +669,7 @@ struct LeafElt { //A BranchElt has a left child in insertion to a key-value pair. struct BranchElt { - left: ~Node, + left: Box>, key: K, value: V } @@ -719,7 +721,7 @@ impl fmt::Show for LeafElt { impl BranchElt { ///Creates a new BranchElt from a supplied key, value, and left child. - fn new(k: K, v: V, n: ~Node) -> BranchElt { + fn new(k: K, v: V, n: Box>) -> BranchElt { BranchElt { left: n, key: k, diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 0f82942d7e788..6763b32afd03b 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -15,7 +15,6 @@ //! DList implements the trait Deque. It should be imported with `use //! collections::deque::Deque`. - // DList is constructed like a singly-linked list over the field `next`. // including the last link being None; each Node owns its `next` field. // @@ -23,10 +22,10 @@ // the reverse direction. use std::cast; -use std::mem::{replace, swap}; -use std::ptr; use std::iter::Rev; use std::iter; +use std::mem::{replace, swap}; +use std::ptr; use deque::Deque; @@ -37,7 +36,7 @@ pub struct DList { list_tail: Rawlink>, } -type Link = Option<~Node>; +type Link = Option>>; struct Rawlink { p: *mut T } struct Node { @@ -118,7 +117,8 @@ impl Node { } /// Set the .prev field on `next`, then return `Some(next)` -fn link_with_prev(mut next: ~Node, prev: Rawlink>) -> Link { +fn link_with_prev(mut next: Box>, prev: Rawlink>) + -> Link { next.prev = prev; Some(next) } @@ -150,7 +150,7 @@ impl Mutable for DList { impl DList { /// Add a Node first in the list #[inline] - fn push_front_node(&mut self, mut new_head: ~Node) { + fn push_front_node(&mut self, mut new_head: Box>) { match self.list_head { None => { self.list_tail = Rawlink::some(new_head); @@ -168,7 +168,7 @@ impl DList { /// Remove the first Node and return it, or None if the list is empty #[inline] - fn pop_front_node(&mut self) -> Option<~Node> { + fn pop_front_node(&mut self) -> Option>> { self.list_head.take().map(|mut front_node| { self.length -= 1; match front_node.next.take() { @@ -181,7 +181,7 @@ impl DList { /// Add a Node last in the list #[inline] - fn push_back_node(&mut self, mut new_tail: ~Node) { + fn push_back_node(&mut self, mut new_tail: Box>) { match self.list_tail.resolve() { None => return self.push_front_node(new_tail), Some(tail) => { @@ -194,7 +194,7 @@ impl DList { /// Remove the last Node and return it, or None if the list is empty #[inline] - fn pop_back_node(&mut self) -> Option<~Node> { + fn pop_back_node(&mut self) -> Option>> { self.list_tail.resolve().map_or(None, |tail| { self.length -= 1; self.list_tail = tail.prev; @@ -245,7 +245,7 @@ impl Deque for DList { /// /// O(1) fn pop_front(&mut self) -> Option { - self.pop_front_node().map(|~Node{value, ..}| value) + self.pop_front_node().map(|box Node{value, ..}| value) } /// Add an element last in the list @@ -259,7 +259,7 @@ impl Deque for DList { /// /// O(1) fn pop_back(&mut self) -> Option { - self.pop_back_node().map(|~Node{value, ..}| value) + self.pop_back_node().map(|box Node{value, ..}| value) } } @@ -432,7 +432,7 @@ impl Drop for DList { match tail.resolve() { None => break, Some(prev) => { - prev.next.take(); // release ~Node + prev.next.take(); // release Box> tail = prev.prev; } } @@ -531,7 +531,7 @@ pub trait ListInsertion { // private methods for MutItems impl<'a, A> MutItems<'a, A> { - fn insert_next_node(&mut self, mut ins_node: ~Node) { + fn insert_next_node(&mut self, mut ins_node: Box>) { // Insert before `self.head` so that it is between the // previously yielded element and self.head. // @@ -671,24 +671,24 @@ mod tests { #[test] fn test_basic() { - let mut m: DList<~int> = DList::new(); + let mut m: DList> = DList::new(); assert_eq!(m.pop_front(), None); assert_eq!(m.pop_back(), None); assert_eq!(m.pop_front(), None); m.push_front(box 1); - assert_eq!(m.pop_front(), Some(~1)); + assert_eq!(m.pop_front(), Some(box 1)); m.push_back(box 2); m.push_back(box 3); assert_eq!(m.len(), 2); - assert_eq!(m.pop_front(), Some(~2)); - assert_eq!(m.pop_front(), Some(~3)); + assert_eq!(m.pop_front(), Some(box 2)); + assert_eq!(m.pop_front(), Some(box 3)); assert_eq!(m.len(), 0); assert_eq!(m.pop_front(), None); m.push_back(box 1); m.push_back(box 3); m.push_back(box 5); m.push_back(box 7); - assert_eq!(m.pop_front(), Some(~1)); + assert_eq!(m.pop_front(), Some(box 1)); let mut n = DList::new(); n.push_front(2); diff --git a/src/libcollections/lru_cache.rs b/src/libcollections/lru_cache.rs index 22876bf39752c..13297df902a07 100644 --- a/src/libcollections/lru_cache.rs +++ b/src/libcollections/lru_cache.rs @@ -57,7 +57,7 @@ struct LruEntry { /// An LRU Cache. pub struct LruCache { - map: HashMap, ~LruEntry>, + map: HashMap, Box>>, max_size: uint, head: *mut LruEntry, } @@ -241,9 +241,9 @@ impl Mutable for LruCache { impl Drop for LruCache { fn drop(&mut self) { unsafe { - let node: ~LruEntry = cast::transmute(self.head); + let node: Box> = cast::transmute(self.head); // Prevent compiler from trying to drop the un-initialized field in the sigil node. - let ~LruEntry { key: k, value: v, .. } = node; + let box LruEntry { key: k, value: v, .. } = node; cast::forget(k); cast::forget(v); } diff --git a/src/libcollections/priority_queue.rs b/src/libcollections/priority_queue.rs index e37e2a6f234b7..f9f4945efc789 100644 --- a/src/libcollections/priority_queue.rs +++ b/src/libcollections/priority_queue.rs @@ -270,24 +270,24 @@ mod tests { #[test] fn test_push_unique() { - let mut heap = PriorityQueue::from_vec(vec!(~2, ~4, ~9)); + let mut heap = PriorityQueue::from_vec(vec!(box 2, box 4, box 9)); assert_eq!(heap.len(), 3); - assert!(*heap.top() == ~9); + assert!(*heap.top() == box 9); heap.push(box 11); assert_eq!(heap.len(), 4); - assert!(*heap.top() == ~11); + assert!(*heap.top() == box 11); heap.push(box 5); assert_eq!(heap.len(), 5); - assert!(*heap.top() == ~11); + assert!(*heap.top() == box 11); heap.push(box 27); assert_eq!(heap.len(), 6); - assert!(*heap.top() == ~27); + assert!(*heap.top() == box 27); heap.push(box 3); assert_eq!(heap.len(), 7); - assert!(*heap.top() == ~27); + assert!(*heap.top() == box 27); heap.push(box 103); assert_eq!(heap.len(), 8); - assert!(*heap.top() == ~103); + assert!(*heap.top() == box 103); } #[test] diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index e236e58b08d38..fb02ddd6224c4 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -465,7 +465,7 @@ mod test_map { assert!(!called); called = true; assert_eq!(k, 1); - assert_eq!(v, ~2); + assert_eq!(v, box 2); } assert!(called); m.insert(2, box 1); diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index 3f993fc64a4af..eff20d309068f 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -36,7 +36,7 @@ use std::ptr; #[allow(missing_doc)] #[deriving(Clone)] pub struct TreeMap { - root: Option<~TreeNode>, + root: Option>>, length: uint } @@ -79,7 +79,7 @@ impl Mutable for TreeMap { impl Map for TreeMap { fn find<'a>(&'a self, key: &K) -> Option<&'a V> { - let mut current: &'a Option<~TreeNode> = &self.root; + let mut current: &'a Option>> = &self.root; loop { match *current { Some(ref r) => { @@ -157,7 +157,7 @@ impl TreeMap { let TreeMap { root: root, length: length } = self; let stk = match root { None => vec!(), - Some(~tn) => vec!(tn) + Some(box tn) => vec!(tn) }; MoveEntries { stack: stk, @@ -317,7 +317,7 @@ macro_rules! define_iterator { ($name:ident, $rev_name:ident, - // the function to go from &m Option<~TreeNode> to *m TreeNode + // the function to go from &m Option> to *m TreeNode deref = $deref:ident, // see comment on `addr!`, this is just an optional `mut`, but @@ -441,7 +441,7 @@ define_iterator! { addr_mut = mut } -fn deref<'a, K, V>(node: &'a Option<~TreeNode>) -> *TreeNode { +fn deref<'a, K, V>(node: &'a Option>>) -> *TreeNode { match *node { Some(ref n) => { let n: &TreeNode = *n; @@ -451,7 +451,8 @@ fn deref<'a, K, V>(node: &'a Option<~TreeNode>) -> *TreeNode { } } -fn mut_deref(x: &mut Option<~TreeNode>) -> *mut TreeNode { +fn mut_deref(x: &mut Option>>) + -> *mut TreeNode { match *x { Some(ref mut n) => { let n: &mut TreeNode = *n; @@ -482,7 +483,7 @@ impl Iterator<(K, V)> for MoveEntries { } = self.stack.pop().unwrap(); match left { - Some(~left) => { + Some(box left) => { let n = TreeNode { key: key, value: value, @@ -495,7 +496,7 @@ impl Iterator<(K, V)> for MoveEntries { } None => { match right { - Some(~right) => self.stack.push(right), + Some(box right) => self.stack.push(right), None => () } self.remaining -= 1; @@ -759,8 +760,8 @@ impl<'a, T: TotalOrd> Iterator<&'a T> for UnionItems<'a, T> { struct TreeNode { key: K, value: V, - left: Option<~TreeNode>, - right: Option<~TreeNode>, + left: Option>>, + right: Option>>, level: uint } @@ -773,7 +774,7 @@ impl TreeNode { } // Remove left horizontal link by rotating right -fn skew(node: &mut ~TreeNode) { +fn skew(node: &mut Box>) { if node.left.as_ref().map_or(false, |x| x.level == node.level) { let mut save = node.left.take_unwrap(); swap(&mut node.left, &mut save.right); // save.right now None @@ -784,7 +785,7 @@ fn skew(node: &mut ~TreeNode) { // Remove dual horizontal link by rotating left and increasing level of // the parent -fn split(node: &mut ~TreeNode) { +fn split(node: &mut Box>) { if node.right.as_ref().map_or(false, |x| x.right.as_ref().map_or(false, |y| y.level == node.level)) { let mut save = node.right.take_unwrap(); @@ -795,7 +796,7 @@ fn split(node: &mut ~TreeNode) { } } -fn find_mut<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode>, +fn find_mut<'r, K: TotalOrd, V>(node: &'r mut Option>>, key: &K) -> Option<&'r mut V> { match *node { @@ -810,7 +811,7 @@ fn find_mut<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode>, } } -fn insert(node: &mut Option<~TreeNode>, +fn insert(node: &mut Option>>, key: K, value: V) -> Option { match *node { Some(ref mut save) => { @@ -840,10 +841,10 @@ fn insert(node: &mut Option<~TreeNode>, } } -fn remove(node: &mut Option<~TreeNode>, +fn remove(node: &mut Option>>, key: &K) -> Option { - fn heir_swap(node: &mut ~TreeNode, - child: &mut Option<~TreeNode>) { + fn heir_swap(node: &mut Box>, + child: &mut Option>>) { // *could* be done without recursion, but it won't borrow check for x in child.mut_iter() { if x.right.is_some() { @@ -877,13 +878,13 @@ fn remove(node: &mut Option<~TreeNode>, (remove(&mut save.left, key), true) } else { let new = save.left.take_unwrap(); - let ~TreeNode{value, ..} = replace(save, new); + let box TreeNode{value, ..} = replace(save, new); *save = save.left.take_unwrap(); (Some(value), true) } } else if save.right.is_some() { let new = save.right.take_unwrap(); - let ~TreeNode{value, ..} = replace(save, new); + let box TreeNode{value, ..} = replace(save, new); (Some(value), true) } else { (None, false) @@ -919,7 +920,7 @@ fn remove(node: &mut Option<~TreeNode>, } } return match node.take() { - Some(~TreeNode{value, ..}) => Some(value), None => fail!() + Some(box TreeNode{value, ..}) => Some(value), None => fail!() }; } @@ -959,7 +960,6 @@ impl Extendable for TreeSet { #[cfg(test)] mod test_treemap { - use super::{TreeMap, TreeNode}; use rand::Rng; @@ -1053,8 +1053,8 @@ mod test_treemap { } } - fn check_left(node: &Option<~TreeNode>, - parent: &~TreeNode) { + fn check_left(node: &Option>>, + parent: &Box>) { match *node { Some(ref r) => { assert_eq!(r.key.cmp(&parent.key), Less); @@ -1066,8 +1066,8 @@ mod test_treemap { } } - fn check_right(node: &Option<~TreeNode>, - parent: &~TreeNode, + fn check_right(node: &Option>>, + parent: &Box>, parent_red: bool) { match *node { Some(ref r) => { diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index 1bff058d6f5b8..ce69ba00787cc 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -10,11 +10,11 @@ //! Ordered containers with integer keys, implemented as radix tries (`TrieSet` and `TrieMap` types) -use std::mem; -use std::uint; use std::mem::init; -use std::slice; +use std::mem; use std::slice::{Items, MutItems}; +use std::slice; +use std::uint; // FIXME: #5244: need to manually update the TrieNode constructor static SHIFT: uint = 4; @@ -23,7 +23,7 @@ static MASK: uint = SIZE - 1; static NUM_CHUNKS: uint = uint::BITS / SHIFT; enum Child { - Internal(~TrieNode), + Internal(Box>), External(uint, T), Nothing } diff --git a/src/libfourcc/lib.rs b/src/libfourcc/lib.rs index fe0b6bcfd0f0a..478634c6ddafd 100644 --- a/src/libfourcc/lib.rs +++ b/src/libfourcc/lib.rs @@ -66,14 +66,15 @@ use syntax::parse::token::InternedString; #[macro_registrar] pub fn macro_registrar(register: |Name, SyntaxExtension|) { register(token::intern("fourcc"), - NormalTT(~BasicMacroExpander { + NormalTT(box BasicMacroExpander { expander: expand_syntax_ext, span: None, }, None)); } -pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~base::MacResult { +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) + -> Box { let (expr, endian) = parse_tts(cx, tts); let little = match endian { diff --git a/src/libgraphviz/maybe_owned_vec.rs b/src/libgraphviz/maybe_owned_vec.rs index 649bad702eaef..817f634836139 100644 --- a/src/libgraphviz/maybe_owned_vec.rs +++ b/src/libgraphviz/maybe_owned_vec.rs @@ -18,7 +18,7 @@ use std::slice; // Note 2: Once Dynamically Sized Types (DST) lands, it might be // reasonable to replace this with something like `enum MaybeOwned<'a, -// Sized? U>{ Owned(~U), Borrowed(&'a U) }`; and then `U` could be +// Sized? U>{ Owned(Box), Borrowed(&'a U) }`; and then `U` could be // instantiated with `[T]` or `str`, etc. Of course, that would imply // removing the `Growable` variant, which relates to note 1 above. // Alternatively, we might add `MaybeOwned` for the general case but diff --git a/src/libgreen/basic.rs b/src/libgreen/basic.rs index 4da0214c27cf4..eba15e6e6d5a8 100644 --- a/src/libgreen/basic.rs +++ b/src/libgreen/basic.rs @@ -17,19 +17,19 @@ use std::cast; use std::mem::replace; -use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback, PausableIdleCallback, - Callback}; +use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback}; +use std::rt::rtio::{PausableIdleCallback, Callback}; use std::unstable::sync::Exclusive; /// This is the only exported function from this module. -pub fn event_loop() -> ~EventLoop:Send { - box BasicLoop::new() as ~EventLoop:Send +pub fn event_loop() -> Box { + box BasicLoop::new() as Box } struct BasicLoop { work: Vec, // pending work idle: Option<*mut BasicPausable>, // only one is allowed - remotes: Vec<(uint, ~Callback:Send)>, + remotes: Vec<(uint, Box)>, next_remote: uint, messages: Exclusive>, } @@ -140,23 +140,24 @@ impl EventLoop for BasicLoop { } // FIXME: Seems like a really weird requirement to have an event loop provide. - fn pausable_idle_callback(&mut self, cb: ~Callback:Send) - -> ~PausableIdleCallback:Send - { + fn pausable_idle_callback(&mut self, cb: Box) + -> Box { let callback = box BasicPausable::new(self, cb); rtassert!(self.idle.is_none()); unsafe { let cb_ptr: &*mut BasicPausable = cast::transmute(&callback); self.idle = Some(*cb_ptr); } - callback as ~PausableIdleCallback:Send + callback as Box } - fn remote_callback(&mut self, f: ~Callback:Send) -> ~RemoteCallback:Send { + fn remote_callback(&mut self, f: Box) + -> Box { let id = self.next_remote; self.next_remote += 1; self.remotes.push((id, f)); - box BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback:Send + box BasicRemote::new(self.messages.clone(), id) as + Box } fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory> { None } @@ -197,12 +198,12 @@ impl Drop for BasicRemote { struct BasicPausable { eloop: *mut BasicLoop, - work: ~Callback:Send, + work: Box, active: bool, } impl BasicPausable { - fn new(eloop: &mut BasicLoop, cb: ~Callback:Send) -> BasicPausable { + fn new(eloop: &mut BasicLoop, cb: Box) -> BasicPausable { BasicPausable { active: false, work: cb, diff --git a/src/libgreen/context.rs b/src/libgreen/context.rs index c30a93c23230f..e5dd9c92358f0 100644 --- a/src/libgreen/context.rs +++ b/src/libgreen/context.rs @@ -8,21 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use stack::Stack; use std::uint; use std::cast::{transmute, transmute_mut_unsafe}; -use stack::Stack; use std::rt::stack; use std::raw; // FIXME #7761: Registers is boxed so that it is 16-byte aligned, for storing // SSE regs. It would be marginally better not to do this. In C++ we // use an attribute on a struct. -// FIXME #7761: It would be nice to define regs as `~Option` since -// the registers are sometimes empty, but the discriminant would +// FIXME #7761: It would be nice to define regs as `Box>` +// since the registers are sometimes empty, but the discriminant would // then misalign the regs again. pub struct Context { /// Hold the registers while the task or scheduler is suspended - regs: ~Registers, + regs: Box, /// Lower bound and upper bound for the stack stack_bounds: Option<(uint, uint)>, } @@ -87,10 +87,10 @@ impl Context { pub fn swap(out_context: &mut Context, in_context: &Context) { rtdebug!("swapping contexts"); let out_regs: &mut Registers = match out_context { - &Context { regs: ~ref mut r, .. } => r + &Context { regs: box ref mut r, .. } => r }; let in_regs: &Registers = match in_context { - &Context { regs: ~ref r, .. } => r + &Context { regs: box ref r, .. } => r }; rtdebug!("noting the stack limit and doing raw swap"); @@ -151,7 +151,7 @@ struct Registers { } #[cfg(target_arch = "x86")] -fn new_regs() -> ~Registers { +fn new_regs() -> Box { box Registers { eax: 0, ebx: 0, ecx: 0, edx: 0, ebp: 0, esi: 0, edi: 0, esp: 0, @@ -190,9 +190,9 @@ type Registers = [uint, ..34]; type Registers = [uint, ..22]; #[cfg(windows, target_arch = "x86_64")] -fn new_regs() -> ~Registers { box [0, .. 34] } +fn new_regs() -> Box { box [0, .. 34] } #[cfg(not(windows), target_arch = "x86_64")] -fn new_regs() -> ~Registers { box {let v = [0, .. 22]; v} } +fn new_regs() -> Box { box {let v = [0, .. 22]; v} } #[cfg(target_arch = "x86_64")] fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint, @@ -241,7 +241,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint, type Registers = [uint, ..32]; #[cfg(target_arch = "arm")] -fn new_regs() -> ~Registers { box {[0, .. 32]} } +fn new_regs() -> Box { box {[0, .. 32]} } #[cfg(target_arch = "arm")] fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint, @@ -270,7 +270,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint, type Registers = [uint, ..32]; #[cfg(target_arch = "mips")] -fn new_regs() -> ~Registers { box [0, .. 32] } +fn new_regs() -> Box { box [0, .. 32] } #[cfg(target_arch = "mips")] fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint, diff --git a/src/libgreen/lib.rs b/src/libgreen/lib.rs index f86743d10c706..cd598346fc3e4 100644 --- a/src/libgreen/lib.rs +++ b/src/libgreen/lib.rs @@ -288,7 +288,7 @@ macro_rules! green_start( ($f:ident) => ( /// The return value is used as the process return code. 0 on success, 101 on /// error. pub fn start(argc: int, argv: **u8, - event_loop_factory: fn() -> ~rtio::EventLoop:Send, + event_loop_factory: fn() -> Box, main: proc():Send) -> int { rt::init(argc, argv); let mut main = Some(main); @@ -309,7 +309,7 @@ pub fn start(argc: int, argv: **u8, /// /// This function will not return until all schedulers in the associated pool /// have returned. -pub fn run(event_loop_factory: fn() -> ~rtio::EventLoop:Send, +pub fn run(event_loop_factory: fn() -> Box, main: proc():Send) -> int { // Create a scheduler pool and spawn the main task into this pool. We will // get notified over a channel when the main task exits. @@ -340,7 +340,7 @@ pub struct PoolConfig { pub threads: uint, /// A factory function used to create new event loops. If this is not /// specified then the default event loop factory is used. - pub event_loop_factory: fn() -> ~rtio::EventLoop:Send, + pub event_loop_factory: fn() -> Box, } impl PoolConfig { @@ -360,12 +360,12 @@ pub struct SchedPool { id: uint, threads: Vec>, handles: Vec, - stealers: Vec>, + stealers: Vec>>, next_friend: uint, stack_pool: StackPool, - deque_pool: deque::BufferPool<~task::GreenTask>, + deque_pool: deque::BufferPool>, sleepers: SleeperList, - factory: fn() -> ~rtio::EventLoop:Send, + factory: fn() -> Box, task_state: TaskState, tasks_done: Receiver<()>, } @@ -445,7 +445,7 @@ impl SchedPool { /// This is useful to create a task which can then be sent to a specific /// scheduler created by `spawn_sched` (and possibly pin it to that /// scheduler). - pub fn task(&mut self, opts: TaskOpts, f: proc():Send) -> ~GreenTask { + pub fn task(&mut self, opts: TaskOpts, f: proc():Send) -> Box { GreenTask::configure(&mut self.stack_pool, opts, f) } diff --git a/src/libgreen/sched.rs b/src/libgreen/sched.rs index c323dbb92d742..301198a067640 100644 --- a/src/libgreen/sched.rs +++ b/src/libgreen/sched.rs @@ -46,10 +46,10 @@ pub struct Scheduler { /// inside this pool of schedulers pub task_state: TaskState, /// There are N work queues, one per scheduler. - work_queue: deque::Worker<~GreenTask>, + work_queue: deque::Worker>, /// Work queues for the other schedulers. These are created by /// cloning the core work queues. - work_queues: Vec>, + work_queues: Vec>>, /// The queue of incoming messages from other schedulers. /// These are enqueued by SchedHandles after which a remote callback /// is triggered to handle the message. @@ -71,7 +71,7 @@ pub struct Scheduler { no_sleep: bool, /// The scheduler runs on a special task. When it is not running /// it is stored here instead of the work queue. - sched_task: Option<~GreenTask>, + sched_task: Option>, /// An action performed after a context switch on behalf of the /// code running before the context switch cleanup_job: Option, @@ -83,7 +83,7 @@ pub struct Scheduler { /// A fast XorShift rng for scheduler use rng: XorShiftRng, /// A togglable idle callback - idle_callback: Option<~PausableIdleCallback:Send>, + idle_callback: Option>, /// A countdown that starts at a random value and is decremented /// every time a yield check is performed. When it hits 0 a task /// will yield. @@ -100,7 +100,7 @@ pub struct Scheduler { // destroyed before it's actually destroyed. /// The event loop used to drive the scheduler and perform I/O - pub event_loop: ~EventLoop:Send, + pub event_loop: Box, } /// An indication of how hard to work on a given operation, the difference @@ -123,9 +123,9 @@ impl Scheduler { // * Initialization Functions pub fn new(pool_id: uint, - event_loop: ~EventLoop:Send, - work_queue: deque::Worker<~GreenTask>, - work_queues: Vec>, + event_loop: Box, + work_queue: deque::Worker>, + work_queues: Vec>>, sleeper_list: SleeperList, state: TaskState) -> Scheduler { @@ -136,9 +136,9 @@ impl Scheduler { } pub fn new_special(pool_id: uint, - event_loop: ~EventLoop:Send, - work_queue: deque::Worker<~GreenTask>, - work_queues: Vec>, + event_loop: Box, + work_queue: deque::Worker>, + work_queues: Vec>>, sleeper_list: SleeperList, run_anything: bool, friend: Option, @@ -183,7 +183,7 @@ impl Scheduler { pub fn bootstrap(mut ~self) { // Build an Idle callback. - let cb = box SchedRunner as ~Callback:Send; + let cb = box SchedRunner as Box; self.idle_callback = Some(self.event_loop.pausable_idle_callback(cb)); // Create a task for the scheduler with an empty context. @@ -224,14 +224,14 @@ impl Scheduler { // This does not return a scheduler, as the scheduler is placed // inside the task. - pub fn run(mut ~self, stask: ~GreenTask) -> ~GreenTask { + pub fn run(mut ~self, stask: Box) -> Box { // This is unsafe because we need to place the scheduler, with // the event_loop inside, inside our task. But we still need a // mutable reference to the event_loop to give it the "run" // command. unsafe { - let event_loop: *mut ~EventLoop:Send = &mut self.event_loop; + let event_loop: *mut Box = &mut self.event_loop; // Our scheduler must be in the task before the event loop // is started. stask.put_with_sched(self); @@ -271,7 +271,7 @@ impl Scheduler { // If we try really hard to do some work, but no work is available to be // done, then we fall back to epoll() to block this thread waiting for more // work (instead of busy waiting). - fn run_sched_once(mut ~self, stask: ~GreenTask) { + fn run_sched_once(mut ~self, stask: Box) { // Make sure that we're not lying in that the `stask` argument is indeed // the scheduler task for this scheduler. assert!(self.sched_task.is_none()); @@ -349,9 +349,9 @@ impl Scheduler { // returns the still-available scheduler. At this point all // message-handling will count as a turn of work, and as a result // return None. - fn interpret_message_queue(mut ~self, stask: ~GreenTask, + fn interpret_message_queue(mut ~self, stask: Box, effort: EffortLevel) - -> (~Scheduler, ~GreenTask, bool) + -> (Box, Box, bool) { let msg = if effort == DontTryTooHard { @@ -432,8 +432,8 @@ impl Scheduler { } } - fn do_work(mut ~self, - stask: ~GreenTask) -> (~Scheduler, ~GreenTask, bool) { + fn do_work(mut ~self, stask: Box) + -> (Box, Box, bool) { rtdebug!("scheduler calling do work"); match self.find_work() { Some(task) => { @@ -459,7 +459,7 @@ impl Scheduler { // First step in the process is to find a task. This function does // that by first checking the local queue, and if there is no work // there, trying to steal from the remote work queues. - fn find_work(&mut self) -> Option<~GreenTask> { + fn find_work(&mut self) -> Option> { rtdebug!("scheduler looking for work"); if !self.steal_for_yield { match self.work_queue.pop() { @@ -497,7 +497,7 @@ impl Scheduler { // Try stealing from all queues the scheduler knows about. This // naive implementation can steal from our own queue or from other // special schedulers. - fn try_steals(&mut self) -> Option<~GreenTask> { + fn try_steals(&mut self) -> Option> { let work_queues = &mut self.work_queues; let len = work_queues.len(); let start_index = self.rng.gen_range(0, len); @@ -517,9 +517,11 @@ impl Scheduler { // * Task Routing Functions - Make sure tasks send up in the right // place. - fn process_task(mut ~self, cur: ~GreenTask, - mut next: ~GreenTask, - schedule_fn: SchedulingFn) -> (~Scheduler, ~GreenTask) { + fn process_task(mut ~self, + cur: Box, + mut next: Box, + schedule_fn: SchedulingFn) + -> (Box, Box) { rtdebug!("processing a task"); match next.take_unwrap_home() { @@ -549,7 +551,7 @@ impl Scheduler { } } - fn send_task_home(task: ~GreenTask) { + fn send_task_home(task: Box) { let mut task = task; match task.take_unwrap_home() { HomeSched(mut home_handle) => home_handle.send(PinnedTask(task)), @@ -559,7 +561,7 @@ impl Scheduler { /// Take a non-homed task we aren't allowed to run here and send /// it to the designated friend scheduler to execute. - fn send_to_friend(&mut self, task: ~GreenTask) { + fn send_to_friend(&mut self, task: Box) { rtdebug!("sending a task to friend"); match self.friend_handle { Some(ref mut handle) => { @@ -576,7 +578,7 @@ impl Scheduler { /// Pushes the task onto the work stealing queue and tells the /// event loop to run it later. Always use this instead of pushing /// to the work queue directly. - pub fn enqueue_task(&mut self, task: ~GreenTask) { + pub fn enqueue_task(&mut self, task: Box) { // We push the task onto our local queue clone. assert!(!task.is_sched()); @@ -609,9 +611,10 @@ impl Scheduler { // old task as inputs. pub fn change_task_context(mut ~self, - current_task: ~GreenTask, - mut next_task: ~GreenTask, - f: |&mut Scheduler, ~GreenTask|) -> ~GreenTask { + current_task: Box, + mut next_task: Box, + f: |&mut Scheduler, Box|) + -> Box { let f_opaque = ClosureConverter::from_fn(f); let current_task_dupe = &*current_task as *GreenTask; @@ -655,7 +658,7 @@ impl Scheduler { // When the context swaps back to this task we immediately // run the cleanup job, as expected by the previously called // swap_contexts function. - let mut current_task: ~GreenTask = unsafe { + let mut current_task: Box = unsafe { cast::transmute(current_task_dupe) }; current_task.sched.get_mut_ref().run_cleanup_job(); @@ -688,8 +691,10 @@ impl Scheduler { // * Context Swapping Helpers - Here be ugliness! - pub fn resume_task_immediately(~self, cur: ~GreenTask, - next: ~GreenTask) -> (~Scheduler, ~GreenTask) { + pub fn resume_task_immediately(~self, + cur: Box, + next: Box) + -> (Box, Box) { assert!(cur.is_sched()); let mut cur = self.change_task_context(cur, next, |sched, stask| { assert!(sched.sched_task.is_none()); @@ -698,9 +703,10 @@ impl Scheduler { (cur.sched.take_unwrap(), cur) } - fn resume_task_immediately_cl(sched: ~Scheduler, - cur: ~GreenTask, - next: ~GreenTask) -> (~Scheduler, ~GreenTask) { + fn resume_task_immediately_cl(sched: Box, + cur: Box, + next: Box) + -> (Box, Box) { sched.resume_task_immediately(cur, next) } @@ -726,7 +732,7 @@ impl Scheduler { /// guaranteed that this function will not return before the given closure /// has returned. pub fn deschedule_running_task_and_then(mut ~self, - cur: ~GreenTask, + cur: Box, f: |&mut Scheduler, BlockedTask|) { // Trickier - we need to get the scheduler task out of self // and use it as the destination. @@ -736,8 +742,8 @@ impl Scheduler { } pub fn switch_running_tasks_and_then(~self, - cur: ~GreenTask, - next: ~GreenTask, + cur: Box, + next: Box, f: |&mut Scheduler, BlockedTask|) { // And here comes one of the sad moments in which a lock is used in a // core portion of the rust runtime. As always, this is highly @@ -768,8 +774,10 @@ impl Scheduler { cur.put(); } - fn switch_task(sched: ~Scheduler, cur: ~GreenTask, - next: ~GreenTask) -> (~Scheduler, ~GreenTask) { + fn switch_task(sched: Box, + cur: Box, + next: Box) + -> (Box, Box) { let mut cur = sched.change_task_context(cur, next, |sched, last_task| { if last_task.is_sched() { assert!(sched.sched_task.is_none()); @@ -785,7 +793,7 @@ impl Scheduler { /// Called by a running task to end execution, after which it will /// be recycled by the scheduler for reuse in a new task. - pub fn terminate_current_task(mut ~self, cur: ~GreenTask) -> ! { + pub fn terminate_current_task(mut ~self, cur: Box) -> ! { // Similar to deschedule running task and then, but cannot go through // the task-blocking path. The task is already dying. let stask = self.sched_task.take_unwrap(); @@ -797,13 +805,13 @@ impl Scheduler { fail!("should never return!"); } - pub fn run_task(~self, cur: ~GreenTask, next: ~GreenTask) { + pub fn run_task(~self, cur: Box, next: Box) { let (sched, task) = self.process_task(cur, next, Scheduler::switch_task); task.put_with_sched(sched); } - pub fn run_task_later(mut cur: ~GreenTask, next: ~GreenTask) { + pub fn run_task_later(mut cur: Box, next: Box) { let mut sched = cur.sched.take_unwrap(); sched.enqueue_task(next); cur.put_with_sched(sched); @@ -813,7 +821,7 @@ impl Scheduler { /// to introduce some amount of randomness to the scheduler. Currently the /// randomness is a result of performing a round of work stealing (which /// may end up stealing from the current scheduler). - pub fn yield_now(mut ~self, cur: ~GreenTask) { + pub fn yield_now(mut ~self, cur: Box) { // Async handles trigger the scheduler by calling yield_now on the local // task, which eventually gets us to here. See comments in SchedRunner // for more info on this. @@ -832,7 +840,7 @@ impl Scheduler { } } - pub fn maybe_yield(mut ~self, cur: ~GreenTask) { + pub fn maybe_yield(mut ~self, cur: Box) { // It's possible for sched tasks to possibly call this function, and it // just means that they're likely sending on channels (which // occasionally call this function). Sched tasks follow different paths @@ -881,20 +889,20 @@ impl Scheduler { // Supporting types -type SchedulingFn = fn (~Scheduler, ~GreenTask, ~GreenTask) - -> (~Scheduler, ~GreenTask); +type SchedulingFn = fn(Box, Box, Box) + -> (Box, Box); pub enum SchedMessage { Wake, Shutdown, - NewNeighbor(deque::Stealer<~GreenTask>), - PinnedTask(~GreenTask), - TaskFromFriend(~GreenTask), - RunOnce(~GreenTask), + NewNeighbor(deque::Stealer>), + PinnedTask(Box), + TaskFromFriend(Box), + RunOnce(Box), } pub struct SchedHandle { - remote: ~RemoteCallback:Send, + remote: Box, queue: msgq::Producer, pub sched_id: uint } @@ -920,18 +928,18 @@ impl Callback for SchedRunner { // This function could be converted to `GreenTask::convert` if // absolutely necessary, but for cleanliness it is much better to not // use the conversion function. - let task: ~Task = Local::take(); + let task: Box = Local::take(); task.yield_now(); } } struct CleanupJob { - task: ~GreenTask, + task: Box, f: UnsafeTaskReceiver } impl CleanupJob { - pub fn new(task: ~GreenTask, f: UnsafeTaskReceiver) -> CleanupJob { + pub fn new(task: Box, f: UnsafeTaskReceiver) -> CleanupJob { CleanupJob { task: task, f: f @@ -948,14 +956,14 @@ impl CleanupJob { // complaining type UnsafeTaskReceiver = raw::Closure; trait ClosureConverter { - fn from_fn(|&mut Scheduler, ~GreenTask|) -> Self; - fn to_fn(self) -> |&mut Scheduler, ~GreenTask|; + fn from_fn(|&mut Scheduler, Box|) -> Self; + fn to_fn(self) -> |&mut Scheduler, Box|; } impl ClosureConverter for UnsafeTaskReceiver { - fn from_fn(f: |&mut Scheduler, ~GreenTask|) -> UnsafeTaskReceiver { + fn from_fn(f: |&mut Scheduler, Box|) -> UnsafeTaskReceiver { unsafe { cast::transmute(f) } } - fn to_fn(self) -> |&mut Scheduler, ~GreenTask| { + fn to_fn(self) -> |&mut Scheduler, Box| { unsafe { cast::transmute(self) } } } @@ -1218,7 +1226,7 @@ mod test { // Signal from the special task that we are done. let (tx, rx) = channel::<()>(); - fn run(next: ~GreenTask) { + fn run(next: Box) { let mut task = GreenTask::convert(Local::take()); let sched = task.sched.take_unwrap(); sched.run_task(task, next) diff --git a/src/libgreen/simple.rs b/src/libgreen/simple.rs index 37b0aa4f611a7..007084fa14d78 100644 --- a/src/libgreen/simple.rs +++ b/src/libgreen/simple.rs @@ -28,7 +28,7 @@ struct SimpleTask { impl Runtime for SimpleTask { // Implement the simple tasks of descheduling and rescheduling, but only in // a simple number of cases. - fn deschedule(mut ~self, times: uint, mut cur_task: ~Task, + fn deschedule(mut ~self, times: uint, mut cur_task: Box, f: |BlockedTask| -> Result<(), BlockedTask>) { assert!(times == 1); @@ -55,7 +55,7 @@ impl Runtime for SimpleTask { } Local::put(cur_task); } - fn reawaken(mut ~self, mut to_wake: ~Task) { + fn reawaken(mut ~self, mut to_wake: Box) { let me = &mut *self as *mut SimpleTask; to_wake.put_runtime(self); unsafe { @@ -70,18 +70,21 @@ impl Runtime for SimpleTask { // purpose. A "simple task" is just that, a very simple task that can't // really do a whole lot. The only purpose of the task is to get us off our // feet and running. - fn yield_now(~self, _cur_task: ~Task) { fail!() } - fn maybe_yield(~self, _cur_task: ~Task) { fail!() } - fn spawn_sibling(~self, _cur_task: ~Task, _opts: TaskOpts, _f: proc():Send) { + fn yield_now(~self, _cur_task: Box) { fail!() } + fn maybe_yield(~self, _cur_task: Box) { fail!() } + fn spawn_sibling(~self, + _cur_task: Box, + _opts: TaskOpts, + _f: proc():Send) { fail!() } fn local_io<'a>(&'a mut self) -> Option> { None } fn stack_bounds(&self) -> (uint, uint) { fail!() } fn can_block(&self) -> bool { true } - fn wrap(~self) -> ~Any { fail!() } + fn wrap(~self) -> Box { fail!() } } -pub fn task() -> ~Task { +pub fn task() -> Box { let mut task = box Task::new(); task.put_runtime(box SimpleTask { lock: unsafe {NativeMutex::new()}, diff --git a/src/libgreen/task.rs b/src/libgreen/task.rs index 846fcdb1881d5..bc7752e98ea5e 100644 --- a/src/libgreen/task.rs +++ b/src/libgreen/task.rs @@ -50,12 +50,12 @@ pub struct GreenTask { /// Slot for maintaining ownership of a scheduler. If a task is running, /// this value will be Some(sched) where the task is running on "sched". - pub sched: Option<~Scheduler>, + pub sched: Option>, /// Temporary ownership slot of a std::rt::task::Task object. This is used /// to squirrel that libstd task away while we're performing green task /// operations. - pub task: Option<~Task>, + pub task: Option>, /// Dictates whether this is a sched task or a normal green task pub task_type: TaskType, @@ -85,8 +85,8 @@ pub enum Home { /// for all green tasks. This code is actually called after the initial context /// switch onto a green thread. /// -/// The first argument to this function is the `~GreenTask` pointer, and the -/// next two arguments are the user-provided procedure for running code. +/// The first argument to this function is the `Box` pointer, and +/// the next two arguments are the user-provided procedure for running code. /// /// The goal for having this weird-looking function is to reduce the number of /// allocations done on a green-task startup as much as possible. @@ -96,8 +96,8 @@ extern fn bootstrap_green_task(task: uint, code: *(), env: *()) -> ! { cast::transmute(raw::Procedure { code: code, env: env }) }; - // Acquire ownership of the `~GreenTask` - let mut task: ~GreenTask = unsafe { cast::transmute(task) }; + // Acquire ownership of the `Box` + let mut task: Box = unsafe { cast::transmute(task) }; // First code after swap to this new context. Run our cleanup job task.pool_id = { @@ -129,7 +129,7 @@ impl GreenTask { /// and will not have any contained Task structure. pub fn new(stack_pool: &mut StackPool, stack_size: Option, - start: proc():Send) -> ~GreenTask { + start: proc():Send) -> Box { GreenTask::new_homed(stack_pool, stack_size, AnySched, start) } @@ -137,7 +137,7 @@ impl GreenTask { pub fn new_homed(stack_pool: &mut StackPool, stack_size: Option, home: Home, - start: proc():Send) -> ~GreenTask { + start: proc():Send) -> Box { // Allocate ourselves a GreenTask structure let mut ops = GreenTask::new_typed(None, TypeGreen(Some(home))); @@ -158,7 +158,7 @@ impl GreenTask { /// Creates a new green task with the specified coroutine and type, this is /// useful when creating scheduler tasks. pub fn new_typed(coroutine: Option, - task_type: TaskType) -> ~GreenTask { + task_type: TaskType) -> Box { box GreenTask { pool_id: 0, coroutine: coroutine, @@ -175,7 +175,7 @@ impl GreenTask { /// new stack for this task. pub fn configure(pool: &mut StackPool, opts: TaskOpts, - f: proc():Send) -> ~GreenTask { + f: proc():Send) -> Box { let TaskOpts { notify_chan, name, stack_size, stderr, stdout, @@ -204,7 +204,7 @@ impl GreenTask { /// /// This function will assert that the task is indeed a green task before /// returning (and will kill the entire process if this is wrong). - pub fn convert(mut task: ~Task) -> ~GreenTask { + pub fn convert(mut task: Box) -> Box { match task.maybe_take_runtime::() { Some(mut green) => { green.put_task(task); @@ -270,22 +270,24 @@ impl GreenTask { self as *GreenTask as uint } - pub unsafe fn from_uint(val: uint) -> ~GreenTask { cast::transmute(val) } + pub unsafe fn from_uint(val: uint) -> Box { + cast::transmute(val) + } // Runtime glue functions and helpers - pub fn put_with_sched(mut ~self, sched: ~Scheduler) { + pub fn put_with_sched(mut ~self, sched: Box) { assert!(self.sched.is_none()); self.sched = Some(sched); self.put(); } - pub fn put_task(&mut self, task: ~Task) { + pub fn put_task(&mut self, task: Box) { assert!(self.task.is_none()); self.task = Some(task); } - pub fn swap(mut ~self) -> ~Task { + pub fn swap(mut ~self) -> Box { let mut task = self.task.take_unwrap(); task.put_runtime(self); return task; @@ -331,19 +333,19 @@ impl GreenTask { } impl Runtime for GreenTask { - fn yield_now(mut ~self, cur_task: ~Task) { + fn yield_now(mut ~self, cur_task: Box) { self.put_task(cur_task); let sched = self.sched.take_unwrap(); sched.yield_now(self); } - fn maybe_yield(mut ~self, cur_task: ~Task) { + fn maybe_yield(mut ~self, cur_task: Box) { self.put_task(cur_task); let sched = self.sched.take_unwrap(); sched.maybe_yield(self); } - fn deschedule(mut ~self, times: uint, cur_task: ~Task, + fn deschedule(mut ~self, times: uint, cur_task: Box, f: |BlockedTask| -> Result<(), BlockedTask>) { self.put_task(cur_task); let mut sched = self.sched.take_unwrap(); @@ -392,14 +394,14 @@ impl Runtime for GreenTask { } } - fn reawaken(mut ~self, to_wake: ~Task) { + fn reawaken(mut ~self, to_wake: Box) { self.put_task(to_wake); assert!(self.sched.is_none()); // Optimistically look for a local task, but if one's not available to // inspect (in order to see if it's in the same sched pool as we are), // then just use our remote wakeup routine and carry on! - let mut running_task: ~Task = match Local::try_take() { + let mut running_task: Box = match Local::try_take() { Some(task) => task, None => return self.reawaken_remotely() }; @@ -443,7 +445,10 @@ impl Runtime for GreenTask { } } - fn spawn_sibling(mut ~self, cur_task: ~Task, opts: TaskOpts, f: proc():Send) { + fn spawn_sibling(mut ~self, + cur_task: Box, + opts: TaskOpts, + f: proc():Send) { self.put_task(cur_task); // Spawns a task into the current scheduler. We allocate the new task's @@ -477,7 +482,7 @@ impl Runtime for GreenTask { fn can_block(&self) -> bool { false } - fn wrap(~self) -> ~Any { self as ~Any } + fn wrap(~self) -> Box { self as Box } } #[cfg(test)] @@ -572,7 +577,7 @@ mod tests { let (tx, rx) = channel(); spawn_opts(TaskOpts::new(), proc() { spawn(proc() { - let mut task: ~Task = Local::take(); + let mut task: Box = Local::take(); match task.maybe_take_runtime::() { Some(ops) => { task.put_runtime(ops); diff --git a/src/libhexfloat/lib.rs b/src/libhexfloat/lib.rs index 72528e969170f..aea8a358f7ffb 100644 --- a/src/libhexfloat/lib.rs +++ b/src/libhexfloat/lib.rs @@ -61,7 +61,7 @@ use syntax::parse::token; #[macro_registrar] pub fn macro_registrar(register: |Name, SyntaxExtension|) { register(token::intern("hexfloat"), - NormalTT(~BasicMacroExpander { + NormalTT(box BasicMacroExpander { expander: expand_syntax_ext, span: None, }, @@ -97,7 +97,8 @@ fn hex_float_lit_err(s: &str) -> Option<(uint, ~str)> { } } -pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~base::MacResult { +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) + -> Box { let (expr, ty_lit) = parse_tts(cx, tts); let ty = match ty_lit { diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index a32a42636b698..035a81f414369 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -158,7 +158,7 @@ pub static WARN: u32 = 2; /// Error log level pub static ERROR: u32 = 1; -local_data_key!(local_logger: ~Logger:Send) +local_data_key!(local_logger: Box) /// A trait used to represent an interface to a task-local logger. Each task /// can have its own custom logger which can respond to logging messages @@ -229,7 +229,7 @@ pub fn log(level: u32, loc: &'static LogLocation, args: &fmt::Arguments) { // frob the slot while we're doing the logging. This will destroy any logger // set during logging. let mut logger = local_data::pop(local_logger).unwrap_or_else(|| { - box DefaultLogger { handle: io::stderr() } as ~Logger:Send + box DefaultLogger { handle: io::stderr() } as Box }); logger.log(&LogRecord { level: LogLevel(level), @@ -249,7 +249,7 @@ pub fn log_level() -> u32 { unsafe { LOG_LEVEL } } /// Replaces the task-local logger with the specified logger, returning the old /// logger. -pub fn set_logger(logger: ~Logger:Send) -> Option<~Logger:Send> { +pub fn set_logger(logger: Box) -> Option> { let prev = local_data::pop(local_logger); local_data::set(local_logger, logger); return prev; @@ -351,7 +351,7 @@ fn init() { // Schedule the cleanup for this global for when the runtime exits. rt::at_exit(proc() { assert!(!DIRECTIVES.is_null()); - let _directives: ~Vec = + let _directives: Box> = cast::transmute(DIRECTIVES); DIRECTIVES = 0 as *Vec; }); diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs index 94ca602784112..2727f9a0b095a 100644 --- a/src/libnative/io/file_unix.rs +++ b/src/libnative/io/file_unix.rs @@ -10,12 +10,12 @@ //! Blocking posix-based file I/O +use libc::{c_int, c_void}; +use libc; use std::sync::arc::UnsafeArc; use std::c_str::CString; use std::io::IoError; use std::io; -use libc::{c_int, c_void}; -use libc; use std::mem; use std::rt::rtio; @@ -175,8 +175,8 @@ impl rtio::RtioPipe for FileDesc { fn write(&mut self, buf: &[u8]) -> Result<(), IoError> { self.inner_write(buf) } - fn clone(&self) -> ~rtio::RtioPipe:Send { - box FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send + fn clone(&self) -> Box { + box FileDesc { inner: self.inner.clone() } as Box } } diff --git a/src/libnative/io/file_win32.rs b/src/libnative/io/file_win32.rs index 54bb22013146d..018907303b84e 100644 --- a/src/libnative/io/file_win32.rs +++ b/src/libnative/io/file_win32.rs @@ -207,8 +207,8 @@ impl rtio::RtioPipe for FileDesc { fn write(&mut self, buf: &[u8]) -> Result<(), IoError> { self.inner_write(buf) } - fn clone(&self) -> ~rtio::RtioPipe:Send { - box FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send + fn clone(&self) -> Box { + box FileDesc { inner: self.inner.clone() } as Box } } diff --git a/src/libnative/io/mod.rs b/src/libnative/io/mod.rs index fb92d0d55cf39..58fcd60f13815 100644 --- a/src/libnative/io/mod.rs +++ b/src/libnative/io/mod.rs @@ -21,19 +21,19 @@ //! play. The only dependencies of these modules are the normal system libraries //! that you would find on the respective platform. +use libc::c_int; +use libc; use std::c_str::CString; use std::io; use std::io::IoError; use std::io::net::ip::SocketAddr; use std::io::process::ProcessConfig; use std::io::signal::Signum; -use libc::c_int; -use libc; use std::os; use std::rt::rtio; -use std::rt::rtio::{RtioTcpStream, RtioTcpListener, RtioUdpSocket, - RtioUnixListener, RtioPipe, RtioFileStream, RtioProcess, - RtioSignal, RtioTTY, CloseBehavior, RtioTimer}; +use std::rt::rtio::{RtioTcpStream, RtioTcpListener, RtioUdpSocket}; +use std::rt::rtio::{RtioUnixListener, RtioPipe, RtioFileStream, RtioProcess}; +use std::rt::rtio::{RtioSignal, RtioTTY, CloseBehavior, RtioTimer}; use ai = std::io::net::addrinfo; // Local re-exports @@ -166,21 +166,32 @@ impl IoFactory { impl rtio::IoFactory for IoFactory { // networking fn tcp_connect(&mut self, addr: SocketAddr, - timeout: Option) -> IoResult<~RtioTcpStream:Send> { - net::TcpStream::connect(addr, timeout).map(|s| box s as ~RtioTcpStream:Send) + timeout: Option) -> IoResult> { + net::TcpStream::connect(addr, timeout).map(|s| { + box s as Box + }) } - fn tcp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioTcpListener:Send> { - net::TcpListener::bind(addr).map(|s| box s as ~RtioTcpListener:Send) + fn tcp_bind(&mut self, addr: SocketAddr) + -> IoResult> { + net::TcpListener::bind(addr).map(|s| { + box s as Box + }) } - fn udp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioUdpSocket:Send> { - net::UdpSocket::bind(addr).map(|u| box u as ~RtioUdpSocket:Send) + fn udp_bind(&mut self, addr: SocketAddr) + -> IoResult> { + net::UdpSocket::bind(addr).map(|u| box u as Box) } - fn unix_bind(&mut self, path: &CString) -> IoResult<~RtioUnixListener:Send> { - pipe::UnixListener::bind(path).map(|s| box s as ~RtioUnixListener:Send) + fn unix_bind(&mut self, path: &CString) + -> IoResult> { + pipe::UnixListener::bind(path).map(|s| { + box s as Box + }) } fn unix_connect(&mut self, path: &CString, - timeout: Option) -> IoResult<~RtioPipe:Send> { - pipe::UnixStream::connect(path, timeout).map(|s| box s as ~RtioPipe:Send) + timeout: Option) -> IoResult> { + pipe::UnixStream::connect(path, timeout).map(|s| { + box s as Box + }) } fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>, hint: Option) -> IoResult<~[ai::Info]> { @@ -188,17 +199,17 @@ impl rtio::IoFactory for IoFactory { } // filesystem operations - fn fs_from_raw_fd(&mut self, fd: c_int, - close: CloseBehavior) -> ~RtioFileStream:Send { + fn fs_from_raw_fd(&mut self, fd: c_int, close: CloseBehavior) + -> Box { let close = match close { rtio::CloseSynchronously | rtio::CloseAsynchronously => true, rtio::DontClose => false }; - box file::FileDesc::new(fd, close) as ~RtioFileStream:Send + box file::FileDesc::new(fd, close) as Box } fn fs_open(&mut self, path: &CString, fm: io::FileMode, fa: io::FileAccess) - -> IoResult<~RtioFileStream:Send> { - file::open(path, fm, fa).map(|fd| box fd as ~RtioFileStream:Send) + -> IoResult> { + file::open(path, fm, fa).map(|fd| box fd as Box) } fn fs_unlink(&mut self, path: &CString) -> IoResult<()> { file::unlink(path) @@ -244,27 +255,29 @@ impl rtio::IoFactory for IoFactory { } // misc - fn timer_init(&mut self) -> IoResult<~RtioTimer:Send> { - timer::Timer::new().map(|t| box t as ~RtioTimer:Send) + fn timer_init(&mut self) -> IoResult> { + timer::Timer::new().map(|t| box t as Box) } fn spawn(&mut self, config: ProcessConfig) - -> IoResult<(~RtioProcess:Send, ~[Option<~RtioPipe:Send>])> { + -> IoResult<(Box, + ~[Option>])> { process::Process::spawn(config).map(|(p, io)| { - (box p as ~RtioProcess:Send, - io.move_iter().map(|p| p.map(|p| box p as ~RtioPipe:Send)).collect()) + (box p as Box, + io.move_iter().map(|p| p.map(|p| { + box p as Box + })).collect()) }) } fn kill(&mut self, pid: libc::pid_t, signum: int) -> IoResult<()> { process::Process::kill(pid, signum) } - fn pipe_open(&mut self, fd: c_int) -> IoResult<~RtioPipe:Send> { - Ok(box file::FileDesc::new(fd, true) as ~RtioPipe:Send) + fn pipe_open(&mut self, fd: c_int) -> IoResult> { + Ok(box file::FileDesc::new(fd, true) as Box) } fn tty_open(&mut self, fd: c_int, _readable: bool) - -> IoResult<~RtioTTY:Send> - { + -> IoResult> { if unsafe { libc::isatty(fd) } != 0 { - Ok(box file::FileDesc::new(fd, true) as ~RtioTTY:Send) + Ok(box file::FileDesc::new(fd, true) as Box) } else { Err(IoError { kind: io::MismatchedFileTypeForOperation, @@ -274,7 +287,7 @@ impl rtio::IoFactory for IoFactory { } } fn signal(&mut self, _signal: Signum, _channel: Sender) - -> IoResult<~RtioSignal:Send> { + -> IoResult> { Err(unimpl()) } } diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index c47e549b20acc..880cbaabaf80e 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -351,8 +351,10 @@ impl rtio::RtioTcpStream for TcpStream { self.set_keepalive(None) } - fn clone(&self) -> ~rtio::RtioTcpStream:Send { - box TcpStream { inner: self.inner.clone() } as ~rtio::RtioTcpStream:Send + fn clone(&self) -> Box { + box TcpStream { + inner: self.inner.clone(), + } as Box } fn close_write(&mut self) -> IoResult<()> { super::mkerr_libc(unsafe { @@ -418,8 +420,10 @@ impl TcpListener { } impl rtio::RtioTcpListener for TcpListener { - fn listen(~self) -> IoResult<~rtio::RtioTcpAcceptor:Send> { - self.native_listen(128).map(|a| box a as ~rtio::RtioTcpAcceptor:Send) + fn listen(~self) -> IoResult> { + self.native_listen(128).map(|a| { + box a as Box + }) } } @@ -465,8 +469,8 @@ impl rtio::RtioSocket for TcpAcceptor { } impl rtio::RtioTcpAcceptor for TcpAcceptor { - fn accept(&mut self) -> IoResult<~rtio::RtioTcpStream:Send> { - self.native_accept().map(|s| box s as ~rtio::RtioTcpStream:Send) + fn accept(&mut self) -> IoResult> { + self.native_accept().map(|s| box s as Box) } fn accept_simultaneously(&mut self) -> IoResult<()> { Ok(()) } @@ -637,7 +641,9 @@ impl rtio::RtioUdpSocket for UdpSocket { self.set_broadcast(false) } - fn clone(&self) -> ~rtio::RtioUdpSocket:Send { - box UdpSocket { inner: self.inner.clone() } as ~rtio::RtioUdpSocket:Send + fn clone(&self) -> Box { + box UdpSocket { + inner: self.inner.clone(), + } as Box } } diff --git a/src/libnative/io/pipe_unix.rs b/src/libnative/io/pipe_unix.rs index 178247f3190f8..65e9c7448c2d5 100644 --- a/src/libnative/io/pipe_unix.rs +++ b/src/libnative/io/pipe_unix.rs @@ -144,8 +144,10 @@ impl rtio::RtioPipe for UnixStream { } } - fn clone(&self) -> ~rtio::RtioPipe:Send { - box UnixStream { inner: self.inner.clone() } as ~rtio::RtioPipe:Send + fn clone(&self) -> Box { + box UnixStream { + inner: self.inner.clone(), + } as Box } } @@ -176,8 +178,10 @@ impl UnixListener { } impl rtio::RtioUnixListener for UnixListener { - fn listen(~self) -> IoResult<~rtio::RtioUnixAcceptor:Send> { - self.native_listen(128).map(|a| box a as ~rtio::RtioUnixAcceptor:Send) + fn listen(~self) -> IoResult> { + self.native_listen(128).map(|a| { + box a as Box + }) } } @@ -209,8 +213,8 @@ impl UnixAcceptor { } impl rtio::RtioUnixAcceptor for UnixAcceptor { - fn accept(&mut self) -> IoResult<~rtio::RtioPipe:Send> { - self.native_accept().map(|s| box s as ~rtio::RtioPipe:Send) + fn accept(&mut self) -> IoResult> { + self.native_accept().map(|s| box s as Box) } fn set_timeout(&mut self, timeout: Option) { self.deadline = timeout.map(|a| ::io::timer::now() + a).unwrap_or(0); diff --git a/src/libnative/io/pipe_win32.rs b/src/libnative/io/pipe_win32.rs index bf7f82ef6622c..f1239285434fa 100644 --- a/src/libnative/io/pipe_win32.rs +++ b/src/libnative/io/pipe_win32.rs @@ -353,12 +353,12 @@ impl rtio::RtioPipe for UnixStream { Ok(()) } - fn clone(&self) -> ~rtio::RtioPipe:Send { + fn clone(&self) -> Box { box UnixStream { inner: self.inner.clone(), read: None, write: None, - } as ~rtio::RtioPipe:Send + } as Box } } @@ -402,8 +402,10 @@ impl Drop for UnixListener { } impl rtio::RtioUnixListener for UnixListener { - fn listen(~self) -> IoResult<~rtio::RtioUnixAcceptor:Send> { - self.native_listen().map(|a| box a as ~rtio::RtioUnixAcceptor:Send) + fn listen(~self) -> IoResult> { + self.native_listen().map(|a| { + box a as Box + }) } } @@ -526,8 +528,8 @@ impl UnixAcceptor { } impl rtio::RtioUnixAcceptor for UnixAcceptor { - fn accept(&mut self) -> IoResult<~rtio::RtioPipe:Send> { - self.native_accept().map(|s| box s as ~rtio::RtioPipe:Send) + fn accept(&mut self) -> IoResult> { + self.native_accept().map(|s| box s as Box) } fn set_timeout(&mut self, timeout: Option) { self.deadline = timeout.map(|i| i + ::io::timer::now()).unwrap_or(0); diff --git a/src/libnative/io/timer_helper.rs b/src/libnative/io/timer_helper.rs index 298dd2f368df6..3bf967cb4263c 100644 --- a/src/libnative/io/timer_helper.rs +++ b/src/libnative/io/timer_helper.rs @@ -86,7 +86,7 @@ fn shutdown() { // Clean up after ther helper thread unsafe { imp::close(HELPER_SIGNAL); - let _chan: ~Sender = cast::transmute(HELPER_CHAN); + let _chan: Box> = cast::transmute(HELPER_CHAN); HELPER_CHAN = 0 as *mut Sender; HELPER_SIGNAL = 0 as imp::signal; } diff --git a/src/libnative/io/timer_unix.rs b/src/libnative/io/timer_unix.rs index 8435c05c7716a..e008e6fb9e905 100644 --- a/src/libnative/io/timer_unix.rs +++ b/src/libnative/io/timer_unix.rs @@ -60,7 +60,7 @@ use io::timer_helper; pub struct Timer { id: uint, - inner: Option<~Inner>, + inner: Option>, } struct Inner { @@ -74,11 +74,11 @@ struct Inner { #[allow(visible_private_types)] pub enum Req { // Add a new timer to the helper thread. - NewTimer(~Inner), + NewTimer(Box), // Remove a timer based on its id and then send it back on the channel // provided - RemoveTimer(uint, Sender<~Inner>), + RemoveTimer(uint, Sender>), // Shut down the loop and then ACK this channel once it's shut down Shutdown, @@ -102,11 +102,11 @@ fn helper(input: libc::c_int, messages: Receiver) { // active timers are those which are able to be selected upon (and it's a // sorted list, and dead timers are those which have expired, but ownership // hasn't yet been transferred back to the timer itself. - let mut active: Vec<~Inner> = vec![]; + let mut active: Vec> = vec![]; let mut dead = vec![]; // inserts a timer into an array of timers (sorted by firing time) - fn insert(t: ~Inner, active: &mut Vec<~Inner>) { + fn insert(t: Box, active: &mut Vec>) { match active.iter().position(|tm| tm.target > t.target) { Some(pos) => { active.insert(pos, t); } None => { active.push(t); } @@ -114,7 +114,8 @@ fn helper(input: libc::c_int, messages: Receiver) { } // signals the first requests in the queue, possible re-enqueueing it. - fn signal(active: &mut Vec<~Inner>, dead: &mut Vec<(uint, ~Inner)>) { + fn signal(active: &mut Vec>, + dead: &mut Vec<(uint, Box)>) { let mut timer = match active.shift() { Some(timer) => timer, None => return }; @@ -229,7 +230,7 @@ impl Timer { } } - fn inner(&mut self) -> ~Inner { + fn inner(&mut self) -> Box { match self.inner.take() { Some(i) => i, None => { diff --git a/src/libnative/task.rs b/src/libnative/task.rs index 512080e420480..d5b02dc007b90 100644 --- a/src/libnative/task.rs +++ b/src/libnative/task.rs @@ -31,7 +31,7 @@ use io; use task; /// Creates a new Task which is ready to execute as a 1:1 task. -pub fn new(stack_bounds: (uint, uint)) -> ~Task { +pub fn new(stack_bounds: (uint, uint)) -> Box { let mut task = box Task::new(); let mut ops = ops(); ops.stack_bounds = stack_bounds; @@ -39,7 +39,7 @@ pub fn new(stack_bounds: (uint, uint)) -> ~Task { return task; } -fn ops() -> ~Ops { +fn ops() -> Box { box Ops { lock: unsafe { NativeMutex::new() }, awoken: false, @@ -119,22 +119,22 @@ struct Ops { } impl rt::Runtime for Ops { - fn yield_now(~self, mut cur_task: ~Task) { + fn yield_now(~self, mut cur_task: Box) { // put the task back in TLS and then invoke the OS thread yield cur_task.put_runtime(self); Local::put(cur_task); Thread::yield_now(); } - fn maybe_yield(~self, mut cur_task: ~Task) { + fn maybe_yield(~self, mut cur_task: Box) { // just put the task back in TLS, on OS threads we never need to // opportunistically yield b/c the OS will do that for us (preemption) cur_task.put_runtime(self); Local::put(cur_task); } - fn wrap(~self) -> ~Any { - self as ~Any + fn wrap(~self) -> Box { + self as Box } fn stack_bounds(&self) -> (uint, uint) { self.stack_bounds } @@ -159,8 +159,8 @@ impl rt::Runtime for Ops { // from the wakeup thread back to this thread about the task pointer, and // there's really no need to. In order to get around this, we cast the task // to a `uint` which is then used at the end of this function to cast back - // to a `~Task` object. Naturally, this looks like it violates ownership - // semantics in that there may be two `~Task` objects. + // to a `Box` object. Naturally, this looks like it violates + // ownership semantics in that there may be two `Box` objects. // // The fun part is that the wakeup half of this implementation knows to // "forget" the task on the other end. This means that the awakening half of @@ -180,7 +180,7 @@ impl rt::Runtime for Ops { // `awoken` field which indicates whether we were actually woken up via some // invocation of `reawaken`. This flag is only ever accessed inside the // lock, so there's no need to make it atomic. - fn deschedule(mut ~self, times: uint, mut cur_task: ~Task, + fn deschedule(mut ~self, times: uint, mut cur_task: Box, f: |BlockedTask| -> Result<(), BlockedTask>) { let me = &mut *self as *mut Ops; cur_task.put_runtime(self); @@ -238,7 +238,7 @@ impl rt::Runtime for Ops { // See the comments on `deschedule` for why the task is forgotten here, and // why it's valid to do so. - fn reawaken(mut ~self, mut to_wake: ~Task) { + fn reawaken(mut ~self, mut to_wake: Box) { unsafe { let me = &mut *self as *mut Ops; to_wake.put_runtime(self); @@ -249,7 +249,10 @@ impl rt::Runtime for Ops { } } - fn spawn_sibling(~self, mut cur_task: ~Task, opts: TaskOpts, f: proc():Send) { + fn spawn_sibling(~self, + mut cur_task: Box, + opts: TaskOpts, + f: proc():Send) { cur_task.put_runtime(self); Local::put(cur_task); @@ -342,7 +345,7 @@ mod tests { let (tx, rx) = channel(); spawn(proc() { spawn(proc() { - let mut task: ~Task = Local::take(); + let mut task: Box = Local::take(); match task.maybe_take_runtime::() { Some(ops) => { task.put_runtime(ops); diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 3393abc8b2615..d5a2c163a90d1 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -57,7 +57,7 @@ if rng.gen() { // bool ``` ```rust -let tuple_ptr = rand::random::<~(f64, char)>(); +let tuple_ptr = rand::random::>(); println!("{:?}", tuple_ptr) ``` */ @@ -569,7 +569,7 @@ type TaskRngInner = reseeding::ReseedingRng; /// The task-local RNG. pub struct TaskRng { // This points into TLS (specifically, it points to the endpoint - // of a ~ stored in TLS, to make it robust against TLS moving + // of a Box stored in TLS, to make it robust against TLS moving // things internally) and so this struct cannot be legally // transferred between tasks *and* it's unsafe to deallocate the // RNG other than when a task is finished. @@ -582,7 +582,7 @@ pub struct TaskRng { } // used to make space in TLS for a random number generator -local_data_key!(TASK_RNG_KEY: ~TaskRngInner) +local_data_key!(TASK_RNG_KEY: Box) /// Retrieve the lazily-initialized task-local random number /// generator, seeded by the system. Intended to be used in method @@ -833,7 +833,9 @@ mod test { let _f : f32 = random(); let _o : Option> = random(); let _many : ((), - (~uint, @int, ~Option<~(@u32, ~(@bool,))>), + (Box, + @int, + Box)>>>), (u8, i8, u16, i16, u32, i32, u64, i64), (f32, (f64, (f64,)))) = random(); } diff --git a/src/librand/rand_impls.rs b/src/librand/rand_impls.rs index b4551fcc312df..5846cb5f312ca 100644 --- a/src/librand/rand_impls.rs +++ b/src/librand/rand_impls.rs @@ -214,9 +214,9 @@ impl Rand for Option { } } -impl Rand for ~T { +impl Rand for Box { #[inline] - fn rand(rng: &mut R) -> ~T { box rng.gen() } + fn rand(rng: &mut R) -> Box { box rng.gen() } } impl Rand for @T { diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index 9feceff537555..3a28f0d1ed5c2 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -59,12 +59,12 @@ pub enum Ast { Begin(Flags), End(Flags), WordBoundary(Flags), - Capture(uint, Option<~str>, ~Ast), + Capture(uint, Option<~str>, Box), // Represent concatenation as a flat vector to avoid blowing the // stack in the compiler. Cat(Vec), - Alt(~Ast, ~Ast), - Rep(~Ast, Repeater, Greed), + Alt(Box, Box), + Rep(Box, Repeater, Greed), } #[deriving(Show, Eq, Clone)] @@ -245,7 +245,7 @@ impl<'a> Parser<'a> { // alternate and make it a capture. if cap.is_some() { let ast = try!(self.pop_ast()); - self.push(Capture(cap.unwrap(), cap_name, ~ast)); + self.push(Capture(cap.unwrap(), cap_name, box ast)); } } '|' => { @@ -331,7 +331,7 @@ impl<'a> Parser<'a> { _ => {} } let greed = try!(self.get_next_greedy()); - self.push(Rep(~ast, rep, greed)); + self.push(Rep(box ast, rep, greed)); Ok(()) } @@ -411,13 +411,13 @@ impl<'a> Parser<'a> { let flags = negated | (self.flags & FLAG_NOCASE); let mut ast = Class(combine_ranges(ranges), flags); for alt in alts.move_iter() { - ast = Alt(~alt, ~ast) + ast = Alt(box alt, box ast) } self.push(ast); } else if alts.len() > 0 { let mut ast = alts.pop().unwrap(); for alt in alts.move_iter() { - ast = Alt(~alt, ~ast) + ast = Alt(box alt, box ast) } self.push(ast); } @@ -548,7 +548,7 @@ impl<'a> Parser<'a> { for _ in iter::range(0, min) { self.push(ast.clone()) } - self.push(Rep(~ast, ZeroMore, greed)); + self.push(Rep(box ast, ZeroMore, greed)); } else { // Require N copies of what's on the stack and then repeat it // up to M times optionally. @@ -558,7 +558,7 @@ impl<'a> Parser<'a> { } if max.is_some() { for _ in iter::range(min, max.unwrap()) { - self.push(Rep(~ast.clone(), ZeroOne, greed)) + self.push(Rep(box ast.clone(), ZeroOne, greed)) } } // It's possible that we popped something off the stack but @@ -842,7 +842,7 @@ impl<'a> Parser<'a> { // thrown away). But be careful with overflow---we can't count on the // open paren to be there. if from > 0 { from = from - 1} - let ast = try!(self.build_from(from, |l,r| Alt(~l, ~r))); + let ast = try!(self.build_from(from, |l,r| Alt(box l, box r))); self.push(ast); Ok(()) } diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs index 6706fb16136dc..c2d3872950f0b 100644 --- a/src/libregex_macros/lib.rs +++ b/src/libregex_macros/lib.rs @@ -49,7 +49,7 @@ use regex::native::{ #[macro_registrar] #[doc(hidden)] pub fn macro_registrar(register: |ast::Name, SyntaxExtension|) { - let expander = ~BasicMacroExpander { expander: native, span: None }; + let expander = box BasicMacroExpander { expander: native, span: None }; register(token::intern("regex"), NormalTT(expander, None)) } @@ -76,7 +76,7 @@ pub fn macro_registrar(register: |ast::Name, SyntaxExtension|) { /// first before trying to understand the code generator. The implementation /// strategy is identical and vm.rs has comments and will be easier to follow. fn native(cx: &mut ExtCtxt, sp: codemap::Span, tts: &[ast::TokenTree]) - -> ~MacResult { + -> Box { let regex = match parse(cx, tts) { Some(r) => r, // error is logged in 'parse' with cx.span_err diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 247c41a60699e..fc903db6d041a 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -677,11 +677,11 @@ pub fn pretty_print_input(sess: Session, let mut rdr = MemReader::new(src); let out = match ofile { - None => box io::stdout() as ~Writer, + None => box io::stdout() as Box, Some(p) => { let r = io::File::create(&p); match r { - Ok(w) => box w as ~Writer, + Ok(w) => box w as Box, Err(e) => fail!("print-print failed to open {} due to {}", p.display(), e), } diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 3a196c5ffab5f..900fba831d9c1 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -229,7 +229,12 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) { enc_substs(w, cx, substs); mywrite!(w, "]"); } - ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, bounds }) => { + ty::ty_trait(box ty::TyTrait { + def_id, + ref substs, + store, + bounds + }) => { mywrite!(w, "x[{}|", (cx.ds)(def_id)); enc_substs(w, cx, substs); enc_trait_store(w, cx, store); diff --git a/src/librustc/middle/borrowck/doc.rs b/src/librustc/middle/borrowck/doc.rs index d27d92249fafc..886876f82b308 100644 --- a/src/librustc/middle/borrowck/doc.rs +++ b/src/librustc/middle/borrowck/doc.rs @@ -68,13 +68,13 @@ niceties. This means that if you have a type like: struct S { f: uint } ``` -and a variable `a: ~S`, then the rust expression `a.f` would correspond +and a variable `a: Box`, then the rust expression `a.f` would correspond to an `LV` of `(*a).f`. Here is the formal grammar for the types we'll consider: ```notrust -TY = () | S<'LT...> | ~TY | & 'LT MQ TY | @ MQ TY +TY = () | S<'LT...> | Box | & 'LT MQ TY | @ MQ TY MQ = mut | imm | const ``` @@ -97,7 +97,7 @@ Now, imagine we had a program like this: struct Foo { f: uint, g: uint } ... 'a: { - let mut x: ~Foo = ...; + let mut x: Box = ...; let y = &mut (*x).f; x = ...; } @@ -310,7 +310,7 @@ MUTABILITY(LV.f, MQ) // M-Field MUTABILITY(LV, MQ) MUTABILITY(*LV, MQ) // M-Deref-Unique - TYPE(LV) = ~Ty + TYPE(LV) = Box MUTABILITY(LV, MQ) ``` @@ -420,7 +420,7 @@ The scope of a unique referent is the scope of the pointer, since the pointer itself `LV` goes out of scope: ```notrust - SCOPE(*LV) = SCOPE(LV) if LV has type ~T + SCOPE(*LV) = SCOPE(LV) if LV has type Box ``` The scope of a managed referent is also the scope of the pointer. This @@ -459,7 +459,7 @@ LIFETIME(LV.f, LT, MQ) // L-Field LIFETIME(LV, LT, MQ) LIFETIME(*LV, LT, MQ) // L-Deref-Send - TYPE(LV) = ~Ty + TYPE(LV) = Box LIFETIME(LV, LT, MQ) ``` @@ -595,7 +595,7 @@ on `LV`: ```notrust RESTRICTIONS(*LV, LT, ACTIONS) = RS, (*LV, ACTIONS) // R-Deref-Send-Pointer - TYPE(LV) = ~Ty + TYPE(LV) = Box RESTRICTIONS(LV, LT, ACTIONS|MUTATE|CLAIM) = RS ``` @@ -967,8 +967,8 @@ moves/uninitializations of the variable that is being used. Let's look at a simple example: ``` -fn foo(a: ~int) { - let b: ~int; // Gen bit 0. +fn foo(a: Box) { + let b: Box; // Gen bit 0. if cond { // Bits: 0 use(&*a); diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 4efb0e44e8ec0..96d0d0eaa2ff0 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -533,7 +533,10 @@ impl<'a> BorrowckCtxt<'a> { fn move_suggestion(tcx: &ty::ctxt, ty: ty::t, default_msg: &'static str) -> &'static str { match ty::get(ty).sty { - ty::ty_closure(~ty::ClosureTy { store: ty::RegionTraitStore(..), .. }) => + ty::ty_closure(box ty::ClosureTy { + store: ty::RegionTraitStore(..), + .. + }) => "a non-copyable stack closure (capture it in a new closure, \ e.g. `|x| f(x)`, to override)", _ if ty::type_moves_by_default(tcx, ty) => diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index edbc787fe5cec..169a7d32032bc 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -321,7 +321,7 @@ impl<'a, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, O> { }); } - fn pretty_print_to(&self, wr: ~io::Writer, + fn pretty_print_to(&self, wr: Box, blk: &ast::Block) -> io::IoResult<()> { let mut ps = pprust::rust_printer_annotated(wr, self); try!(ps.cbox(pprust::indent_unit)); diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 0638fd5c4827e..f3a8b9d20d5f7 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -51,7 +51,7 @@ fn should_explore(tcx: &ty::ctxt, def_id: ast::DefId) -> bool { struct MarkSymbolVisitor<'a> { worklist: Vec, tcx: &'a ty::ctxt, - live_symbols: ~HashSet, + live_symbols: Box>, } impl<'a> MarkSymbolVisitor<'a> { @@ -285,7 +285,7 @@ fn find_live(tcx: &ty::ctxt, exported_items: &privacy::ExportedItems, reachable_symbols: &NodeSet, krate: &ast::Crate) - -> ~HashSet { + -> Box> { let worklist = create_and_seed_worklist(tcx, exported_items, reachable_symbols, krate); let mut symbol_visitor = MarkSymbolVisitor::new(tcx, worklist); @@ -312,7 +312,7 @@ fn get_struct_ctor_id(item: &ast::Item) -> Option { struct DeadVisitor<'a> { tcx: &'a ty::ctxt, - live_symbols: ~HashSet, + live_symbols: Box>, } impl<'a> DeadVisitor<'a> { diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 92695d7a1d60f..402fe82266154 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -198,11 +198,11 @@ fn with_appropriate_checker(cx: &Context, let fty = ty::node_id_to_type(cx.tcx, id); match ty::get(fty).sty { - ty::ty_closure(~ty::ClosureTy { + ty::ty_closure(box ty::ClosureTy { store: ty::UniqTraitStore, bounds, .. }) => b(|cx, fv| check_for_uniq(cx, fv, bounds)), - ty::ty_closure(~ty::ClosureTy { + ty::ty_closure(box ty::ClosureTy { store: ty::RegionTraitStore(region, _), bounds, .. }) => b(|cx, fv| check_for_block(cx, fv, bounds, region)), @@ -331,7 +331,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) { fn check_trait_cast(cx: &mut Context, source_ty: ty::t, target_ty: ty::t, span: Span) { check_cast_for_escaping_regions(cx, source_ty, target_ty, span); match ty::get(target_ty).sty { - ty::ty_trait(~ty::TyTrait { bounds, .. }) => { + ty::ty_trait(box ty::TyTrait { bounds, .. }) => { check_trait_cast_bounds(cx, span, source_ty, bounds); } _ => {} diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index ab1670a6686a4..3c8ce77fa873e 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -240,14 +240,14 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[ ("owned_heap_memory", LintSpec { lint: OwnedHeapMemory, - desc: "use of owned (~ type) heap memory", + desc: "use of owned (Box type) heap memory", default: allow }), ("heap_memory", LintSpec { lint: HeapMemory, - desc: "use of any (~ type or @ type) heap memory", + desc: "use of any (Box type or @ type) heap memory", default: allow }), @@ -943,8 +943,13 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) { n_box += 1; } ty::ty_uniq(_) | - ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) | - ty::ty_closure(~ty::ClosureTy { store: ty::UniqTraitStore, .. }) => { + ty::ty_trait(box ty::TyTrait { + store: ty::UniqTraitStore, .. + }) | + ty::ty_closure(box ty::ClosureTy { + store: ty::UniqTraitStore, + .. + }) => { n_uniq += 1; } @@ -955,7 +960,7 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) { if n_uniq > 0 && lint != ManagedHeapMemory { let s = ty_to_str(cx.tcx, ty); - let m = format!("type uses owned (~ type) pointers: {}", s); + let m = format!("type uses owned (Box type) pointers: {}", s); cx.span_lint(lint, span, m); } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index b5f31e8b1cd73..8ff4430a65b6f 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -173,8 +173,8 @@ pub enum deref_kind { pub fn opt_deref_kind(t: ty::t) -> Option { match ty::get(t).sty { ty::ty_uniq(_) | - ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) | - ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => { + ty::ty_trait(box ty::TyTrait { store: ty::UniqTraitStore, .. }) | + ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => { Some(deref_ptr(OwnedPtr)) } @@ -182,12 +182,18 @@ pub fn opt_deref_kind(t: ty::t) -> Option { let kind = ty::BorrowKind::from_mutbl(mt.mutbl); Some(deref_ptr(BorrowedPtr(kind, r))) } - ty::ty_trait(~ty::TyTrait { store: ty::RegionTraitStore(r, mutbl), .. }) => { + ty::ty_trait(box ty::TyTrait { + store: ty::RegionTraitStore(r, mutbl), + .. + }) => { let kind = ty::BorrowKind::from_mutbl(mutbl); Some(deref_ptr(BorrowedPtr(kind, r))) } - ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(r, _), ..}) => { + ty::ty_closure(box ty::ClosureTy { + store: ty::RegionTraitStore(r, _), + .. + }) => { Some(deref_ptr(BorrowedPtr(ty::ImmBorrow, r))) } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 33db3b44d9503..6f42769891ea5 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -650,7 +650,6 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, * | VariantName(..., P&, ...) * | [ ..., P&, ... ] * | ( ..., P&, ... ) - * | ~P& * | box P& */ @@ -704,7 +703,7 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, * | [ ..., E&, ... ] * | ( ..., E&, ... ) * | {...; E&} - * | ~E& + * | box E& * | E& as ... * | ( E& ) */ diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 7206f3f03f5e6..b456ec224fe7e 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1155,7 +1155,7 @@ impl<'a> DynamicFailureHandler<'a> { enum FailureHandler<'a> { Infallible, JumpToBasicBlock(BasicBlockRef), - DynamicFailureHandlerClass(~DynamicFailureHandler<'a>), + DynamicFailureHandlerClass(Box>), } impl<'a> FailureHandler<'a> { diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index ca183e1401227..1c955f52037e6 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -248,9 +248,10 @@ pub fn is_ffi_safe(tcx: &ty::ctxt, def_id: ast::DefId) -> bool { if hint.is_ffi_safe() { return true; } - // Option<~T> and similar are used in FFI. Rather than try to resolve type parameters - // and recognize this case exactly, this overapproximates -- assuming that if a - // non-C-like enum is being used in FFI then the user knows what they're doing. + // Option> and similar are used in FFI. Rather than try to + // resolve type parameters and recognize this case exactly, this + // overapproximates -- assuming that if a non-C-like enum is being + // used in FFI then the user knows what they're doing. if variants.iter().any(|vi| !vi.args.is_empty()) { return true; } diff --git a/src/librustc/middle/trans/cleanup.rs b/src/librustc/middle/trans/cleanup.rs index 97c9dcce5ef64..b9b44b72b10da 100644 --- a/src/librustc/middle/trans/cleanup.rs +++ b/src/librustc/middle/trans/cleanup.rs @@ -26,6 +26,7 @@ use middle::ty; use syntax::ast; use util::ppaux::Repr; + pub struct CleanupScope<'a> { // The id of this cleanup scope. If the id is None, // this is a *temporary scope* that is pushed during trans to @@ -35,7 +36,7 @@ pub struct CleanupScope<'a> { kind: CleanupScopeKind<'a>, // Cleanups to run upon scope exit. - cleanups: Vec<~Cleanup>, + cleanups: Vec>, cached_early_exits: Vec, cached_landing_pad: Option, @@ -248,7 +249,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { self.ccx.tn.val_to_str(val), ty.repr(self.ccx.tcx())); - self.schedule_clean(cleanup_scope, drop as ~Cleanup); + self.schedule_clean(cleanup_scope, drop as Box); } fn schedule_drop_immediate(&self, @@ -272,7 +273,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { self.ccx.tn.val_to_str(val), ty.repr(self.ccx.tcx())); - self.schedule_clean(cleanup_scope, drop as ~Cleanup); + self.schedule_clean(cleanup_scope, drop as Box); } fn schedule_free_value(&self, @@ -291,12 +292,12 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { self.ccx.tn.val_to_str(val), heap); - self.schedule_clean(cleanup_scope, drop as ~Cleanup); + self.schedule_clean(cleanup_scope, drop as Box); } fn schedule_clean(&self, cleanup_scope: ScopeId, - cleanup: ~Cleanup) { + cleanup: Box) { match cleanup_scope { AstScope(id) => self.schedule_clean_in_ast_scope(id, cleanup), CustomScope(id) => self.schedule_clean_in_custom_scope(id, cleanup), @@ -305,7 +306,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { fn schedule_clean_in_ast_scope(&self, cleanup_scope: ast::NodeId, - cleanup: ~Cleanup) { + cleanup: Box) { /*! * Schedules a cleanup to occur upon exit from `cleanup_scope`. * If `cleanup_scope` is not provided, then the cleanup is scheduled @@ -333,7 +334,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { fn schedule_clean_in_custom_scope(&self, custom_scope: CustomScopeIndex, - cleanup: ~Cleanup) { + cleanup: Box) { /*! * Schedules a cleanup to occur in the top-most scope, * which must be a temporary scope. @@ -909,13 +910,13 @@ pub trait CleanupMethods<'a> { heap: Heap); fn schedule_clean(&self, cleanup_scope: ScopeId, - cleanup: ~Cleanup); + cleanup: Box); fn schedule_clean_in_ast_scope(&self, cleanup_scope: ast::NodeId, - cleanup: ~Cleanup); + cleanup: Box); fn schedule_clean_in_custom_scope(&self, custom_scope: CustomScopeIndex, - cleanup: ~Cleanup); + cleanup: Box); fn needs_invoke(&self) -> bool; fn get_landing_pad(&'a self) -> BasicBlockRef; } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index e8654da3457ee..049a6930ab9fc 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -57,7 +57,7 @@ For example, the following simple type for a singly-linked list... ``` struct List { value: int, - tail: Option<~List>, + tail: Option>, } ``` @@ -66,8 +66,8 @@ will generate the following callstack with a naive DFS algorithm: ``` describe(t = List) describe(t = int) - describe(t = Option<~List>) - describe(t = ~List) + describe(t = Option>) + describe(t = Box) describe(t = List) // at the beginning again... ... ``` @@ -211,7 +211,7 @@ pub struct FunctionDebugContext { } enum FunctionDebugContextRepr { - FunctionDebugContext(~FunctionDebugContextData), + FunctionDebugContext(Box), DebugInfoDisabled, FunctionWithoutDebugInfo, } @@ -219,7 +219,7 @@ enum FunctionDebugContextRepr { impl FunctionDebugContext { fn get_ref<'a>(&'a self, cx: &CrateContext, span: Span) -> &'a FunctionDebugContextData { match self.repr { - FunctionDebugContext(~ref data) => data, + FunctionDebugContext(box ref data) => data, DebugInfoDisabled => { cx.sess().span_bug(span, FunctionDebugContext::debuginfo_disabled_message()); } @@ -560,7 +560,7 @@ pub fn set_source_location(fcx: &FunctionContext, set_debug_location(fcx.ccx, UnknownLocation); return; } - FunctionDebugContext(~ref function_debug_context) => { + FunctionDebugContext(box ref function_debug_context) => { let cx = fcx.ccx; debug!("set_source_location: {}", cx.sess().codemap().span_to_str(span)); @@ -596,7 +596,7 @@ pub fn clear_source_location(fcx: &FunctionContext) { /// translated. pub fn start_emitting_source_locations(fcx: &FunctionContext) { match fcx.debug_context.repr { - FunctionDebugContext(~ref data) => { + FunctionDebugContext(box ref data) => { data.source_locations_enabled.set(true) }, _ => { /* safe to ignore */ } @@ -2227,7 +2227,12 @@ fn type_metadata(cx: &CrateContext, ty::ty_closure(ref closurety) => { subroutine_type_metadata(cx, &closurety.sig, usage_site_span) } - ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, ref bounds }) => { + ty::ty_trait(box ty::TyTrait { + def_id, + ref substs, + store, + ref bounds + }) => { trait_metadata(cx, def_id, t, substs, store, bounds) } ty::ty_struct(def_id, ref substs) => { diff --git a/src/librustc/middle/trans/doc.rs b/src/librustc/middle/trans/doc.rs index d6dda75c7c034..56bf25613382c 100644 --- a/src/librustc/middle/trans/doc.rs +++ b/src/librustc/middle/trans/doc.rs @@ -31,7 +31,7 @@ expression functions depending on the kind of expression. We divide up expressions into: - **Datum expressions:** Those that most naturally yield values. - Examples would be `22`, `~x`, or `a + b` (when not overloaded). + Examples would be `22`, `box x`, or `a + b` (when not overloaded). - **DPS expressions:** Those that most naturally write into a location in memory. Examples would be `foo()` or `Point { x: 3, y: 4 }`. - **Statement expressions:** That that do not generate a meaningful @@ -107,7 +107,7 @@ Somewhat surprisingly, not all lvalue expressions yield lvalue datums when trans'd. Ultimately the reason for this is to micro-optimize the resulting LLVM. For example, consider the following code: - fn foo() -> ~int { ... } + fn foo() -> Box { ... } let x = *foo(); The expression `*foo()` is an lvalue, but if you invoke `expr::trans`, @@ -169,7 +169,7 @@ is fully initialized, then the cleanup will run and try to free or drop uninitialized memory. If the initialization itself produces byproducts that need to be freed, then you should use temporary custom scopes to ensure that those byproducts will get freed on unwind. For -example, an expression like `~foo()` will first allocate a box in the +example, an expression like `box foo()` will first allocate a box in the heap and then call `foo()` -- if `foo()` should fail, this box needs to be *shallowly* freed. @@ -219,11 +219,11 @@ unwind, and only up until the point where execution succeeded, at which time the complete value should be stored in an lvalue or some other place where normal cleanup applies. -To spell it out, here is an example. Imagine an expression `~expr`. +To spell it out, here is an example. Imagine an expression `box expr`. We would basically: 1. Push a custom cleanup scope C. -2. Allocate the `~` box. +2. Allocate the box. 3. Schedule a shallow free in the scope C. 4. Trans `expr` into the box. 5. Pop the scope C. diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 2e8c60c5dc5f5..806fb3e125d89 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -397,8 +397,8 @@ fn trans_datum_unadjusted<'a>(bcx: &'a Block<'a>, DatumBlock(bcx, datum) } ast::ExprBox(_, contents) => { - // Special case for `~T`. (The other case, for GC, is handled in - // `trans_rvalue_dps_unadjusted`.) + // Special case for `box T`. (The other case, for GC, is handled + // in `trans_rvalue_dps_unadjusted`.) let box_ty = expr_ty(bcx, expr); let contents_ty = expr_ty(bcx, contents); trans_uniq_expr(bcx, box_ty, contents, contents_ty) @@ -1171,11 +1171,12 @@ fn trans_uniq_expr<'a>(bcx: &'a Block<'a>, let llty = type_of::type_of(bcx.ccx(), contents_ty); let size = llsize_of(bcx.ccx(), llty); // We need to a make a pointer type because box_ty is ty_bot - // if content_ty is, e.g. ~fail!(). + // if content_ty is, e.g. box fail!(). let real_box_ty = ty::mk_uniq(bcx.tcx(), contents_ty); let Result { bcx, val } = malloc_raw_dyn(bcx, real_box_ty, size); - // Unique boxes do not allocate for zero-size types. The standard library may assume - // that `free` is never called on the pointer returned for `~ZeroSizeType`. + // Unique boxes do not allocate for zero-size types. The standard library + // may assume that `free` is never called on the pointer returned for + // `Box`. let bcx = if llsize_of_alloc(bcx.ccx(), llty) == 0 { trans_into(bcx, contents, SaveIn(val)) } else { @@ -1774,8 +1775,8 @@ fn deref_once<'a>(bcx: &'a Block<'a>, * Basically, the idea is to make the deref of an rvalue * result in an rvalue. This helps to avoid intermediate stack * slots in the resulting LLVM. The idea here is that, if the - * `~T` pointer is an rvalue, then we can schedule a *shallow* - * free of the `~T` pointer, and then return a ByRef rvalue + * `Box` pointer is an rvalue, then we can schedule a *shallow* + * free of the `Box` pointer, and then return a ByRef rvalue * into the pointer. Because the free is shallow, it is legit * to return an rvalue, because we know that the contents are * not yet scheduled to be freed. The language rules ensure that the diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 37a387a558fdf..1bde80815c33f 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -89,7 +89,7 @@ fn get_drop_glue_type(ccx: &CrateContext, t: ty::t) -> ty::t { let llty = sizing_type_of(ccx, typ); // Unique boxes do not allocate for zero-size types. The standard // library may assume that `free` is never called on the pointer - // returned for `~ZeroSizeType`. + // returned for `Box`. if llsize_of_alloc(ccx, llty) == 0 { ty::mk_i8() } else { @@ -318,7 +318,7 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<' } } } - ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) => { + ty::ty_trait(box ty::TyTrait { store: ty::UniqTraitStore, .. }) => { let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]); // Only drop the value when it is non-null with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue)), |bcx| { diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index d122edb767857..b13444a4410ae 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -344,7 +344,7 @@ fn trans_trait_callee<'a>(bcx: &'a Block<'a>, -> Callee<'a> { /*! * Create a method callee where the method is coming from a trait - * object (e.g., ~Trait type). In this case, we must pull the fn + * object (e.g., Box type). In this case, we must pull the fn * pointer out of the vtable that is packaged up with the object. * Objects are represented as a pair, so we first evaluate the self * expression and then extract the self data and vtable out of the @@ -401,7 +401,7 @@ pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>, // Load the function from the vtable and cast it to the expected type. debug!("(translating trait callee) loading method"); - // Replace the self type (&Self or ~Self) with an opaque pointer. + // Replace the self type (&Self or Box) with an opaque pointer. let llcallee_ty = match ty::get(callee_ty).sty { ty::ty_bare_fn(ref f) if f.abi == Rust => { type_of_rust_fn(ccx, true, f.sig.inputs.slice_from(1), f.sig.output) @@ -527,8 +527,8 @@ pub fn trans_trait_cast<'a>(bcx: &'a Block<'a>, dest: expr::Dest) -> &'a Block<'a> { /*! - * Generates the code to convert from a pointer (`~T`, `&T`, etc) - * into an object (`~Trait`, `&Trait`, etc). This means creating a + * Generates the code to convert from a pointer (`Box`, `&T`, etc) + * into an object (`Box`, `&Trait`, etc). This means creating a * pair where the first word is the vtable and the second word is * the pointer. */ diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 89d93bb31119e..461d39240e8f7 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -128,7 +128,7 @@ pub struct mt { #[deriving(Clone, Eq, TotalEq, Hash, Encodable, Decodable, Show)] pub enum TraitStore { - /// ~Trait + /// Box UniqTraitStore, /// &Trait and &mut Trait RegionTraitStore(Region, ast::Mutability), @@ -229,7 +229,7 @@ pub enum AutoRef { /// Convert from T to *T AutoUnsafe(ast::Mutability), - /// Convert from ~Trait/&Trait to &Trait + /// Convert from Box/&Trait to &Trait AutoBorrowObj(Region, ast::Mutability), } @@ -239,7 +239,7 @@ pub enum AutoRef { pub struct ctxt { // Specifically use a speedy hash algorithm for this hash map, it's used // quite often. - pub interner: RefCell>, + pub interner: RefCell>>, pub next_id: Cell, pub sess: Session, pub def_map: resolve::DefMap, @@ -735,8 +735,8 @@ pub enum sty { ty_ptr(mt), ty_rptr(Region, mt), ty_bare_fn(BareFnTy), - ty_closure(~ClosureTy), - ty_trait(~TyTrait), + ty_closure(Box), + ty_trait(Box), ty_struct(DefId, substs), ty_tup(Vec), @@ -1195,7 +1195,7 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t { &ty_enum(_, ref substs) | &ty_struct(_, ref substs) => { flags |= sflags(substs); } - &ty_trait(~ty::TyTrait { ref substs, store, .. }) => { + &ty_trait(box ty::TyTrait { ref substs, store, .. }) => { flags |= sflags(substs); match store { RegionTraitStore(r, _) => { @@ -1482,7 +1482,7 @@ pub fn maybe_walk_ty(ty: t, f: |t| -> bool) { maybe_walk_ty(tm.ty, f); } ty_enum(_, ref substs) | ty_struct(_, ref substs) | - ty_trait(~TyTrait { ref substs, .. }) => { + ty_trait(box TyTrait { ref substs, .. }) => { for subty in (*substs).tps.iter() { maybe_walk_ty(*subty, |x| f(x)); } } ty_tup(ref ts) => { for tt in ts.iter() { maybe_walk_ty(*tt, |x| f(x)); } } @@ -1951,7 +1951,7 @@ impl TypeContents { pub fn owned_pointer(&self) -> TypeContents { /*! * Includes only those bits that still apply - * when indirected through a `~` pointer + * when indirected through a `Box` pointer */ TC::OwnsOwned | ( *self & (TC::OwnsAll | TC::ReachesAll)) @@ -2050,7 +2050,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { // private cache for this walk. This is needed in the case of cyclic // types like: // - // struct List { next: ~Option, ... } + // struct List { next: Box>, ... } // // When computing the type contents of such a type, we wind up deeply // recursing as we go. So when we encounter the recursive reference @@ -2100,7 +2100,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { } } - ty_trait(~ty::TyTrait { store, bounds, .. }) => { + ty_trait(box ty::TyTrait { store, bounds, .. }) => { object_contents(cx, store, bounds) } @@ -2965,7 +2965,7 @@ pub fn adjust_ty(cx: &ctxt, fn borrow_obj(cx: &ctxt, span: Span, r: Region, m: ast::Mutability, ty: ty::t) -> ty::t { match get(ty).sty { - ty_trait(~ty::TyTrait {def_id, ref substs, bounds, .. }) => { + ty_trait(box ty::TyTrait {def_id, ref substs, bounds, .. }) => { ty::mk_trait(cx, def_id, substs.clone(), RegionTraitStore(r, m), bounds) } @@ -3164,7 +3164,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { // writing) it's not easy to distinguish casts to traits // from other casts based on the AST. This should be // easier in the future, when casts to traits - // would like @Foo, ~Foo, or &Foo. + // would like @Foo, Box, or &Foo. RvalueDatumExpr } } @@ -3192,7 +3192,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { } ast::ExprBox(place, _) => { - // Special case `~T` for now: + // Special case `Box` for now: let definition = match tcx.def_map.borrow().find(&place.id) { Some(&def) => def, None => fail!("no def for place"), @@ -3264,7 +3264,7 @@ pub fn ty_sort_str(cx: &ctxt, t: t) -> ~str { ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)), ty_box(_) => "@-ptr".to_owned(), - ty_uniq(_) => "~-ptr".to_owned(), + ty_uniq(_) => "box".to_owned(), ty_vec(_, _) => "vector".to_owned(), ty_ptr(_) => "*-ptr".to_owned(), ty_rptr(_, _) => "&-ptr".to_owned(), @@ -3614,7 +3614,9 @@ pub fn try_add_builtin_trait(tcx: &ctxt, pub fn ty_to_def_id(ty: t) -> Option { match get(ty).sty { - ty_trait(~TyTrait { def_id: id, .. }) | ty_struct(id, _) | ty_enum(id, _) => Some(id), + ty_trait(box TyTrait { def_id: id, .. }) | + ty_struct(id, _) | + ty_enum(id, _) => Some(id), _ => None } } @@ -4575,7 +4577,7 @@ pub fn hash_crate_independent(tcx: &ctxt, t: t, svh: &Svh) -> u64 { } } } - ty_trait(~ty::TyTrait { def_id: d, store, bounds, .. }) => { + ty_trait(box ty::TyTrait { def_id: d, store, bounds, .. }) => { byte!(17); did(&mut state, d); match store { diff --git a/src/librustc/middle/ty_fold.rs b/src/librustc/middle/ty_fold.rs index f8f9ca30712d5..4b0153b67fff4 100644 --- a/src/librustc/middle/ty_fold.rs +++ b/src/librustc/middle/ty_fold.rs @@ -149,8 +149,13 @@ pub fn super_fold_sty(this: &mut T, ty::ty_enum(tid, ref substs) => { ty::ty_enum(tid, this.fold_substs(substs)) } - ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, bounds }) => { - ty::ty_trait(box ty::TyTrait{ + ty::ty_trait(box ty::TyTrait { + def_id, + ref substs, + store, + bounds + }) => { + ty::ty_trait(box ty::TyTrait { def_id: def_id, substs: this.fold_substs(substs), store: this.fold_trait_store(store), diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 1c5bea04a878b..e3591af6440f7 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -876,7 +876,8 @@ fn conv_builtin_bounds(tcx: &ty::ctxt, ast_bounds: &Option" or + //! "Box". match (ast_bounds, store) { (&Some(ref bound_vec), _) => { diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 9c8e02b8e2197..e6a6a370b1330 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -691,7 +691,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) { } } -// Helper function to check @, ~ and & patterns +// Helper function to check @, box and & patterns pub fn check_pointer_pat(pcx: &pat_ctxt, pointer_kind: PointerKind, inner: &ast::Pat, @@ -721,7 +721,7 @@ pub fn check_pointer_pat(pcx: &pat_ctxt, e, actual)})}, Some(expected), format!("{} pattern", match pointer_kind { - Send => "a `~`-box", + Send => "a box", Borrowed => "an `&`-pointer" }), None); diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 9234270cf7ebc..17a432d2b5d76 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -30,7 +30,7 @@ itself (note that inherent impls can only be defined in the same module as the type itself). Inherent candidates are not always derived from impls. If you have a -trait instance, such as a value of type `~ToStr`, then the trait +trait instance, such as a value of type `Box`, then the trait methods (`to_str()`, in this case) are inherently associated with it. Another case is type parameters, in which case the methods of their bounds are inherent. @@ -72,9 +72,9 @@ Both the inherent candidate collection and the candidate selection proceed by progressively deref'ing the receiver type, after all. The answer is that two phases are needed to elegantly deal with explicit self. After all, if there is an impl for the type `Foo`, it can -define a method with the type `~self`, which means that it expects a -receiver of type `~Foo`. If we have a receiver of type `~Foo`, but we -waited to search for that impl until we have deref'd the `~` away and +define a method with the type `Box`, which means that it expects a +receiver of type `Box`. If we have a receiver of type `Box`, but we +waited to search for that impl until we have deref'd the `Box` away and obtained the type `Foo`, we would never match this method. */ @@ -243,15 +243,15 @@ fn construct_transformed_self_ty_for_object( * * trait Foo { * fn r_method<'a>(&'a self); - * fn u_method(~self); + * fn u_method(Box); * } * * Now, assuming that `r_method` is being called, we want the * result to be `&'a Foo`. Assuming that `u_method` is being - * called, we want the result to be `~Foo`. Of course, + * called, we want the result to be `Box`. Of course, * this transformation has already been done as part of * `method_ty.fty.sig.inputs[0]`, but there the type - * is expressed in terms of `Self` (i.e., `&'a Self`, `~Self`). + * is expressed in terms of `Self` (i.e., `&'a Self`, `Box`). * Because objects are not standalone types, we can't just substitute * `s/Self/Foo/`, so we must instead perform this kind of hokey * match below. @@ -328,8 +328,8 @@ struct Candidate { /// considered to "match" a given method candidate. Typically the test /// is whether the receiver is of a particular type. However, this /// type is the type of the receiver *after accounting for the -/// method's self type* (e.g., if the method is an `~self` method, we -/// have *already verified* that the receiver is of some type `~T` and +/// method's self type* (e.g., if the method is an `Box` method, we +/// have *already verified* that the receiver is of some type `Box` and /// now we must check that the type `T` is correct). Unfortunately, /// because traits are not types, this is a pain to do. #[deriving(Clone)] @@ -421,14 +421,14 @@ impl<'a> LookupContext<'a> { * `self.inherent_candidates`. See comment at the start of * the file. To find the inherent candidates, we repeatedly * deref the self-ty to find the "base-type". So, for - * example, if the receiver is ~~C where `C` is a struct type, + * example, if the receiver is Box> where `C` is a struct type, * we'll want to find the inherent impls for `C`. */ let span = self.self_expr.map_or(self.span, |e| e.span); check::autoderef(self.fcx, span, self_ty, None, PreferMutLvalue, |self_ty, _| { match get(self_ty).sty { - ty_trait(~TyTrait { def_id, ref substs, .. }) => { + ty_trait(box TyTrait { def_id, ref substs, .. }) => { self.push_inherent_candidates_from_object(def_id, substs); self.push_inherent_impl_candidates_for_type(def_id); } @@ -767,9 +767,9 @@ impl<'a> LookupContext<'a> { * consuming the original pointer. * * You might think that this would be a natural byproduct of - * the auto-deref/auto-ref process. This is true for `~T` - * but not for an `&mut T` receiver. With `~T`, we would - * begin by testing for methods with a self type `~T`, + * the auto-deref/auto-ref process. This is true for `Box` + * but not for an `&mut T` receiver. With `Box`, we would + * begin by testing for methods with a self type `Box`, * then autoderef to `T`, then autoref to `&mut T`. But with * an `&mut T` receiver the process begins with `&mut T`, only * without any autoadjustments. @@ -797,7 +797,7 @@ impl<'a> LookupContext<'a> { autoref: Some(auto)}) } - ty::ty_trait(~ty::TyTrait { + ty::ty_trait(box ty::TyTrait { def_id, ref substs, store: ty::RegionTraitStore(_, mutbl), bounds }) => { let region = @@ -902,8 +902,13 @@ impl<'a> LookupContext<'a> { }, ty_vec(mt, Some(_)) => self.auto_slice_vec(mt, autoderefs), - ty_trait(~ty::TyTrait { def_id: trt_did, substs: trt_substs, bounds: b, .. }) => { - // Coerce ~/&Trait instances to &Trait. + ty_trait(box ty::TyTrait { + def_id: trt_did, + substs: trt_substs, + bounds: b, + .. + }) => { + // Coerce Box/&Trait instances to &Trait. self.search_for_some_kind_of_autorefd_method( AutoBorrowObj, autoderefs, [MutImmutable, MutMutable], @@ -1361,7 +1366,7 @@ impl<'a> LookupContext<'a> { } } - ty::ty_trait(~ty::TyTrait { + ty::ty_trait(box ty::TyTrait { def_id: self_did, store: RegionTraitStore(_, self_m), .. }) => { mutability_matches(self_m, m) && @@ -1382,7 +1387,7 @@ impl<'a> LookupContext<'a> { } } - ty::ty_trait(~ty::TyTrait { + ty::ty_trait(box ty::TyTrait { def_id: self_did, store: UniqTraitStore, .. }) => { rcvr_matches_object(self_did, candidate) diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index f934f0805e6c1..c352ba7e3a5c8 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1912,7 +1912,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, let fn_sig = match *fn_sty { ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, ..}) | - ty::ty_closure(~ty::ClosureTy {sig: ref sig, ..}) => sig, + ty::ty_closure(box ty::ClosureTy {sig: ref sig, ..}) => sig, _ => { fcx.type_error_message(call_expr.span, |actual| { format!("expected function but \ diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 0250cc0a5edd8..4c36a935dee33 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -367,7 +367,7 @@ fn constrain_bindings_in_pat(pat: &ast::Pat, rcx: &mut Rcx) { // accessed. We must be wary of loops like this: // // // from src/test/compile-fail/borrowck-lend-flow.rs - // let mut v = ~3, w = ~4; + // let mut v = box 3, w = box 4; // let mut x = &mut w; // loop { // **x += 1; // (2) @@ -539,7 +539,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) { // explaining how it goes about doing that. let target_ty = rcx.resolve_node_type(expr.id); match ty::get(target_ty).sty { - ty::ty_trait(~ty::TyTrait { + ty::ty_trait(box ty::TyTrait { store: ty::RegionTraitStore(trait_region, _), .. }) => { let source_ty = rcx.resolve_expr_type_adjusted(source); @@ -609,7 +609,7 @@ fn check_expr_fn_block(rcx: &mut Rcx, let tcx = rcx.fcx.tcx(); let function_type = rcx.resolve_node_type(expr.id); match ty::get(function_type).sty { - ty::ty_closure(~ty::ClosureTy { + ty::ty_closure(box ty::ClosureTy { store: ty::RegionTraitStore(region, _), ..}) => { freevars::with_freevars(tcx, expr.id, |freevars| { if freevars.is_empty() { @@ -635,7 +635,10 @@ fn check_expr_fn_block(rcx: &mut Rcx, rcx.set_repeating_scope(repeating_scope); match ty::get(function_type).sty { - ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(..), ..}) => { + ty::ty_closure(box ty::ClosureTy { + store: ty::RegionTraitStore(..), + .. + }) => { freevars::with_freevars(tcx, expr.id, |freevars| { propagate_upupvar_borrow_kind(rcx, expr, freevars); }) diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 8b3794aff723c..192c67eb8d1d9 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -532,7 +532,7 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) { let resolve_object_cast = |src: &ast::Expr, target_ty: ty::t| { match ty::get(target_ty).sty { // Bounds of type's contents are not checked here, but in kind.rs. - ty::ty_trait(~ty::TyTrait { + ty::ty_trait(box ty::TyTrait { def_id: target_def_id, substs: ref target_substs, store, .. }) => { fn mutability_allowed(a_mutbl: ast::Mutability, @@ -543,7 +543,7 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) { // Look up vtables for the type we're casting to, // passing in the source and target type. The source // must be a pointer type suitable to the object sigil, - // e.g.: `&x as &Trait` or `~x as ~Trait` + // e.g.: `&x as &Trait` or `box x as Box` let ty = structurally_resolved_type(fcx, ex.span, fcx.expr_ty(src)); match (&ty::get(ty).sty, store) { @@ -606,8 +606,8 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) { (_, ty::UniqTraitStore) => { fcx.ccx.tcx.sess.span_err( ex.span, - format!("can only cast an ~-pointer \ - to a ~-object, not a {}", + format!("can only cast an boxed pointer \ + to a boxed object, not a {}", ty::ty_sort_str(fcx.tcx(), ty))); } diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 3a50b0681e8b8..c15c30656adcd 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -103,7 +103,7 @@ fn type_is_defined_in_local_crate(original_type: t) -> bool { ty::walk_ty(original_type, |t| { match get(t).sty { ty_enum(def_id, _) | - ty_trait(~ty::TyTrait { def_id, .. }) | + ty_trait(box ty::TyTrait { def_id, .. }) | ty_struct(def_id, _) => { if def_id.krate == ast::LOCAL_CRATE { found_nominal = true; @@ -129,7 +129,7 @@ fn get_base_type_def_id(inference_context: &InferCtxt, match get(base_type).sty { ty_enum(def_id, _) | ty_struct(def_id, _) | - ty_trait(~ty::TyTrait { def_id, .. }) => { + ty_trait(box ty::TyTrait { def_id, .. }) => { return Some(def_id); } _ => { diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/typeck/infer/coercion.rs index aa00b24474f9c..d50e36c31a037 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/typeck/infer/coercion.rs @@ -121,7 +121,10 @@ impl<'f> Coerce<'f> { }; } - ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(..), ..}) => { + ty::ty_closure(box ty::ClosureTy { + store: ty::RegionTraitStore(..), + .. + }) => { return self.unpack_actual_value(a, |sty_a| { self.coerce_borrowed_fn(a, sty_a, b) }); @@ -133,7 +136,7 @@ impl<'f> Coerce<'f> { }); } - ty::ty_trait(~ty::TyTrait { + ty::ty_trait(box ty::TyTrait { def_id, ref substs, store: ty::UniqTraitStore, bounds }) => { let result = self.unpack_actual_value(a, |sty_a| { @@ -152,7 +155,7 @@ impl<'f> Coerce<'f> { } } - ty::ty_trait(~ty::TyTrait { + ty::ty_trait(box ty::TyTrait { def_id, ref substs, store: ty::RegionTraitStore(region, m), bounds }) => { let result = self.unpack_actual_value(a, |sty_a| { @@ -332,7 +335,12 @@ impl<'f> Coerce<'f> { let r_a = self.get_ref().infcx.next_region_var(coercion); let a_borrowed = match *sty_a { - ty::ty_trait(~ty::TyTrait { def_id, ref substs, bounds, .. }) => { + ty::ty_trait(box ty::TyTrait { + def_id, + ref substs, + bounds, + .. + }) => { ty::mk_trait(tcx, def_id, substs.clone(), ty::RegionTraitStore(r_a, b_mutbl), bounds) } diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index 258f286d8f025..20bd47b3022a2 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -683,7 +683,7 @@ impl<'a> InferCtxt<'a> { ty::EmptyBuiltinBounds()); let dummy1 = self.resolve_type_vars_if_possible(dummy0); match ty::get(dummy1).sty { - ty::ty_trait(~ty::TyTrait { ref def_id, ref substs, .. }) => { + ty::ty_trait(box ty::TyTrait { ref def_id, ref substs, .. }) => { ty::TraitRef { def_id: *def_id, substs: (*substs).clone(), diff --git a/src/librustc/middle/typeck/infer/region_inference/doc.rs b/src/librustc/middle/typeck/infer/region_inference/doc.rs index a05d7a33fb4da..1170244fbec7d 100644 --- a/src/librustc/middle/typeck/infer/region_inference/doc.rs +++ b/src/librustc/middle/typeck/infer/region_inference/doc.rs @@ -190,7 +190,7 @@ going on: *p += 1; *p } fn weird() { - let mut x: ~Foo = ~Foo { ... }; + let mut x: Box = box Foo { ... }; 'a: add(&mut (*x).f, 'b: inc(&mut (*x).f)) // (..) } @@ -243,11 +243,11 @@ this similar but unsound example: *p += v; } ... - fn consume(x: ~Foo) -> uint { + fn consume(x: Box) -> uint { x.f + x.g } fn weird() { - let mut x: ~Foo = ~Foo { ... }; + let mut x: Box = box Foo { ... }; 'a: add(&mut (*x).f, consume(x)) // (..) } diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index a4fae2d9aa4f2..df3af87b0f824 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -741,7 +741,7 @@ impl<'a> ConstraintContext<'a> { substs, variance); } - ty::ty_trait(~ty::TyTrait { def_id, ref substs, .. }) => { + ty::ty_trait(box ty::TyTrait { def_id, ref substs, .. }) => { let trait_def = ty::lookup_trait_def(self.tcx(), def_id); self.add_constraints_from_substs(def_id, &trait_def.generics, substs, variance); @@ -768,11 +768,15 @@ impl<'a> ConstraintContext<'a> { } ty::ty_bare_fn(ty::BareFnTy { ref sig, .. }) | - ty::ty_closure(~ty::ClosureTy { ref sig, store: ty::UniqTraitStore, .. }) => { + ty::ty_closure(box ty::ClosureTy { + ref sig, + store: ty::UniqTraitStore, + .. + }) => { self.add_constraints_from_sig(sig, variance); } - ty::ty_closure(~ty::ClosureTy { ref sig, + ty::ty_closure(box ty::ClosureTy { ref sig, store: ty::RegionTraitStore(region, _), .. }) => { let contra = self.contravariant(variance); self.add_constraints_from_region(region, contra); diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 06adce194f167..cf6466faba6f9 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -203,7 +203,7 @@ pub fn mt_to_str(cx: &ctxt, m: &mt) -> ~str { pub fn trait_store_to_str(cx: &ctxt, s: ty::TraitStore) -> ~str { match s { - ty::UniqTraitStore => "~".to_owned(), + ty::UniqTraitStore => "Box ".to_owned(), ty::RegionTraitStore(r, m) => { format!("{}{}", region_ptr_to_str(cx, r), mutability_to_str(m)) } @@ -385,7 +385,7 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str { did, false) } - ty_trait(~ty::TyTrait { + ty_trait(box ty::TyTrait { def_id: did, ref substs, store, ref bounds }) => { let base = ty::item_path_str(cx, did); @@ -500,7 +500,7 @@ impl Repr for @T { } } -impl Repr for ~T { +impl Repr for Box { fn repr(&self, tcx: &ctxt) -> ~str { (&**self).repr(tcx) } diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index 4c65a6c148823..f143b80338a3a 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -684,26 +684,26 @@ pub enum Type { Self(ast::NodeId), /// Primitives are just the fixed-size numeric types (plus int/uint/float), and char. Primitive(ast::PrimTy), - Closure(~ClosureDecl, Option), - Proc(~ClosureDecl), + Closure(Box, Option), + Proc(Box), /// extern "ABI" fn - BareFunction(~BareFunctionDecl), + BareFunction(Box), Tuple(Vec), - Vector(~Type), - FixedVector(~Type, ~str), + Vector(Box), + FixedVector(Box, ~str), String, Bool, /// aka TyNil Unit, /// aka TyBot Bottom, - Unique(~Type), - Managed(~Type), - RawPointer(Mutability, ~Type), + Unique(Box), + Managed(Box), + RawPointer(Mutability, Box), BorrowedRef { pub lifetime: Option, pub mutability: Mutability, - pub type_: ~Type, + pub type_: Box, }, // region, raw, other boxes, mutable } diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 18b6298a3a03a..f452be3277871 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -83,8 +83,8 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, class: Option<& let klass = match next.tok { // If this '&' token is directly adjacent to another token, assume // that it's the address-of operator instead of the and-operator. - // This allows us to give all pointers their own class (~ and @ are - // below). + // This allows us to give all pointers their own class (`Box` and + // `@` are below). t::BINOP(t::AND) if lexer.peek().sp.lo == next.sp.hi => "kw-2", t::AT | t::TILDE => "kw-2", diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 01cbd15be222a..4187a348bde29 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -36,8 +36,11 @@ use html::markdown; use passes; use visit_ast::RustdocVisitor; -pub fn run(input: &str, cfgs: Vec<~str>, - libs: HashSet, mut test_args: Vec<~str>) -> int { +pub fn run(input: &str, + cfgs: Vec<~str>, + libs: HashSet, + mut test_args: Vec<~str>) + -> int { let input_path = Path::new(input); let input = driver::FileInput(input_path.clone()); @@ -126,7 +129,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet, should_fail: bool, let old = io::stdio::set_stderr(box w1); spawn(proc() { let mut p = io::ChanReader::new(rx); - let mut err = old.unwrap_or(box io::stderr() as ~Writer:Send); + let mut err = old.unwrap_or(box io::stderr() as Box); io::util::copy(&mut p, &mut err).unwrap(); }); let emitter = diagnostic::EmitterWriter::new(box w2); diff --git a/src/librustuv/access.rs b/src/librustuv/access.rs index 3ea58a71cfe3c..fbacf1ca314fc 100644 --- a/src/librustuv/access.rs +++ b/src/librustuv/access.rs @@ -15,9 +15,9 @@ /// (the uv event loop). use std::cast; -use std::sync::arc::UnsafeArc; -use std::rt::task::{BlockedTask, Task}; use std::rt::local::Local; +use std::rt::task::{BlockedTask, Task}; +use std::sync::arc::UnsafeArc; use homing::HomingMissile; @@ -52,7 +52,7 @@ impl Access { let inner: &mut Inner = unsafe { cast::transmute(self.inner.get()) }; if inner.held { - let t: ~Task = Local::take(); + let t: Box = Local::take(); t.deschedule(1, |task| { inner.queue.push(task); Ok(()) diff --git a/src/librustuv/async.rs b/src/librustuv/async.rs index 7b19be09bde50..155dee3cfa82c 100644 --- a/src/librustuv/async.rs +++ b/src/librustuv/async.rs @@ -26,12 +26,12 @@ pub struct AsyncWatcher { } struct Payload { - callback: ~Callback:Send, + callback: Box, exit_flag: Exclusive, } impl AsyncWatcher { - pub fn new(loop_: &mut Loop, cb: ~Callback:Send) -> AsyncWatcher { + pub fn new(loop_: &mut Loop, cb: Box) -> AsyncWatcher { let handle = UvHandle::alloc(None::, uvll::UV_ASYNC); assert_eq!(unsafe { uvll::uv_async_init(loop_.handle, handle, async_cb) @@ -93,7 +93,7 @@ extern fn async_cb(handle: *uvll::uv_async_t) { extern fn close_cb(handle: *uvll::uv_handle_t) { // drop the payload - let _payload: ~Payload = unsafe { + let _payload: Box = unsafe { cast::transmute(uvll::get_data_for_uv_handle(handle)) }; // and then free the handle diff --git a/src/librustuv/homing.rs b/src/librustuv/homing.rs index 89b68917c9483..50825bab493b3 100644 --- a/src/librustuv/homing.rs +++ b/src/librustuv/homing.rs @@ -100,7 +100,7 @@ pub trait HomingIO { // to go (remember we have no preemption, so we're guaranteed to stay on // this event loop as long as we avoid the scheduler). if cur_loop_id != destination { - let cur_task: ~Task = Local::take(); + let cur_task: Box = Local::take(); cur_task.deschedule(1, |task| { self.home().send(task); Ok(()) diff --git a/src/librustuv/idle.rs b/src/librustuv/idle.rs index 9fb525bc260b1..ba72e5db27319 100644 --- a/src/librustuv/idle.rs +++ b/src/librustuv/idle.rs @@ -19,11 +19,11 @@ pub struct IdleWatcher { handle: *uvll::uv_idle_t, idle_flag: bool, closed: bool, - callback: ~Callback:Send, + callback: Box, } impl IdleWatcher { - pub fn new(loop_: &mut Loop, cb: ~Callback:Send) -> ~IdleWatcher { + pub fn new(loop_: &mut Loop, cb: Box) -> Box { let handle = UvHandle::alloc(None::, uvll::UV_IDLE); assert_eq!(unsafe { uvll::uv_idle_init(loop_.handle, handle) @@ -49,7 +49,7 @@ impl IdleWatcher { extern fn onetime_cb(handle: *uvll::uv_idle_t) { unsafe { let data = uvll::get_data_for_uv_handle(handle); - let f: ~proc() = cast::transmute(data); + let f: Box = cast::transmute(data); (*f)(); assert_eq!(uvll::uv_idle_stop(handle), 0); uvll::uv_close(handle, close_cb); @@ -126,16 +126,16 @@ mod test { } } - fn mk(v: uint) -> (~IdleWatcher, Chan) { + fn mk(v: uint) -> (Box, Chan) { let rc = Rc::new(RefCell::new((None, 0))); let cb = box MyCallback(rc.clone(), v); - let cb = cb as ~Callback:; + let cb = cb as Box; let cb = unsafe { cast::transmute(cb) }; (IdleWatcher::new(&mut local_loop().loop_, cb), rc) } fn sleep(chan: &Chan) -> uint { - let task: ~Task = Local::take(); + let task: Box = Local::take(); task.deschedule(1, |task| { match *chan.borrow_mut().deref_mut() { (ref mut slot, _) => { diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index f7631f8e41dfa..84d4b6b4702c3 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -47,11 +47,11 @@ via `close` and `delete` methods. #[cfg(test)] extern crate realrustuv = "rustuv"; extern crate libc; +use libc::{c_int, c_void}; use std::cast; use std::fmt; use std::io::IoError; use std::io; -use libc::{c_int, c_void}; use std::ptr::null; use std::ptr; use std::rt::local::Local; @@ -124,8 +124,8 @@ pub mod stream; /// // this code is running inside of a green task powered by libuv /// } /// ``` -pub fn event_loop() -> ~rtio::EventLoop:Send { - box uvio::UvEventLoop::new() as ~rtio::EventLoop:Send +pub fn event_loop() -> Box { + box uvio::UvEventLoop::new() as Box } /// A type that wraps a uv handle @@ -149,9 +149,9 @@ pub trait UvHandle { cast::transmute(uvll::get_data_for_uv_handle(*h)) } - fn install(~self) -> ~Self { + fn install(~self) -> Box { unsafe { - let myptr = cast::transmute::<&~Self, &*u8>(&self); + let myptr = cast::transmute::<&Box, &*u8>(&self); uvll::set_data_for_uv_handle(self.uv_handle(), *myptr); } self @@ -242,7 +242,7 @@ fn wait_until_woken_after(slot: *mut Option, let _f = ForbidUnwind::new("wait_until_woken_after"); unsafe { assert!((*slot).is_none()); - let task: ~Task = Local::take(); + let task: Box = Local::take(); loop_.modify_blockers(1); task.deschedule(1, |task| { *slot = Some(task); diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index e12276e8f5bb0..a2701a57ca917 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use libc::{size_t, ssize_t, c_int, c_void, c_uint}; +use libc; use std::cast; use std::io::{IoError, IoResult}; use std::io::net::ip; -use libc::{size_t, ssize_t, c_int, c_void, c_uint}; -use libc; use std::mem; use std::ptr; use std::rt::rtio; @@ -152,7 +152,7 @@ fn socket_name(sk: SocketNameKind, pub struct ConnectCtx { pub status: c_int, pub task: Option, - pub timer: Option<~TimerWatcher>, + pub timer: Option>, } pub struct AcceptTimeout { @@ -352,12 +352,12 @@ pub struct TcpListener { home: HomeHandle, handle: *uvll::uv_pipe_t, closing_task: Option, - outgoing: Sender>, - incoming: Receiver>, + outgoing: Sender, IoError>>, + incoming: Receiver, IoError>>, } pub struct TcpAcceptor { - listener: ~TcpListener, + listener: Box, timeout: AcceptTimeout, } @@ -455,7 +455,7 @@ impl rtio::RtioTcpStream for TcpWatcher { }) } - fn clone(&self) -> ~rtio::RtioTcpStream:Send { + fn clone(&self) -> Box { box TcpWatcher { handle: self.handle, stream: StreamWatcher::new(self.handle), @@ -463,7 +463,7 @@ impl rtio::RtioTcpStream for TcpWatcher { refcount: self.refcount.clone(), write_access: self.write_access.clone(), read_access: self.read_access.clone(), - } as ~rtio::RtioTcpStream:Send + } as Box } fn close_write(&mut self) -> Result<(), IoError> { @@ -516,7 +516,7 @@ impl Drop for TcpWatcher { impl TcpListener { pub fn bind(io: &mut UvIoFactory, address: ip::SocketAddr) - -> Result<~TcpListener, UvError> { + -> Result, UvError> { let handle = unsafe { uvll::malloc_handle(uvll::UV_TCP) }; assert_eq!(unsafe { uvll::uv_tcp_init(io.uv_loop(), handle) @@ -557,7 +557,7 @@ impl rtio::RtioSocket for TcpListener { } impl rtio::RtioTcpListener for TcpListener { - fn listen(~self) -> Result<~rtio::RtioTcpAcceptor:Send, IoError> { + fn listen(~self) -> Result, IoError> { // create the acceptor object from ourselves let mut acceptor = box TcpAcceptor { listener: self, @@ -567,7 +567,7 @@ impl rtio::RtioTcpListener for TcpListener { let _m = acceptor.fire_homing_missile(); // FIXME: the 128 backlog should be configurable match unsafe { uvll::uv_listen(acceptor.listener.handle, 128, listen_cb) } { - 0 => Ok(acceptor as ~rtio::RtioTcpAcceptor:Send), + 0 => Ok(acceptor as Box), n => Err(uv_error_to_io_error(UvError(n))), } } @@ -583,7 +583,7 @@ extern fn listen_cb(server: *uvll::uv_stream_t, status: c_int) { }); let client = TcpWatcher::new_home(&loop_, tcp.home().clone()); assert_eq!(unsafe { uvll::uv_accept(server, client.handle) }, 0); - Ok(box client as ~rtio::RtioTcpStream:Send) + Ok(box client as Box) } n => Err(uv_error_to_io_error(UvError(n))) }; @@ -611,7 +611,7 @@ impl rtio::RtioSocket for TcpAcceptor { } impl rtio::RtioTcpAcceptor for TcpAcceptor { - fn accept(&mut self) -> Result<~rtio::RtioTcpStream:Send, IoError> { + fn accept(&mut self) -> Result, IoError> { self.timeout.accept(&self.listener.incoming) } @@ -879,14 +879,14 @@ impl rtio::RtioUdpSocket for UdpWatcher { }) } - fn clone(&self) -> ~rtio::RtioUdpSocket:Send { + fn clone(&self) -> Box { box UdpWatcher { handle: self.handle, home: self.home.clone(), refcount: self.refcount.clone(), write_access: self.write_access.clone(), read_access: self.read_access.clone(), - } as ~rtio::RtioUdpSocket:Send + } as Box } } diff --git a/src/librustuv/pipe.rs b/src/librustuv/pipe.rs index 99551e8f35ba1..0edc13afcf538 100644 --- a/src/librustuv/pipe.rs +++ b/src/librustuv/pipe.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use libc; use std::c_str::CString; use std::io::IoError; -use libc; use std::rt::rtio::{RtioPipe, RtioUnixListener, RtioUnixAcceptor}; use access::Access; @@ -36,12 +36,12 @@ pub struct PipeWatcher { pub struct PipeListener { home: HomeHandle, pipe: *uvll::uv_pipe_t, - outgoing: Sender>, - incoming: Receiver>, + outgoing: Sender, IoError>>, + incoming: Receiver, IoError>>, } pub struct PipeAcceptor { - listener: ~PipeListener, + listener: Box, timeout: net::AcceptTimeout, } @@ -121,7 +121,7 @@ impl RtioPipe for PipeWatcher { self.stream.write(buf).map_err(uv_error_to_io_error) } - fn clone(&self) -> ~RtioPipe:Send { + fn clone(&self) -> Box { box PipeWatcher { stream: StreamWatcher::new(self.stream.handle), defused: false, @@ -129,7 +129,7 @@ impl RtioPipe for PipeWatcher { refcount: self.refcount.clone(), read_access: self.read_access.clone(), write_access: self.write_access.clone(), - } as ~RtioPipe:Send + } as Box } } @@ -154,7 +154,7 @@ impl Drop for PipeWatcher { impl PipeListener { pub fn bind(io: &mut UvIoFactory, name: &CString) - -> Result<~PipeListener, UvError> + -> Result, UvError> { let pipe = PipeWatcher::new(io, false); match unsafe { @@ -179,7 +179,7 @@ impl PipeListener { } impl RtioUnixListener for PipeListener { - fn listen(~self) -> Result<~RtioUnixAcceptor:Send, IoError> { + fn listen(~self) -> Result, IoError> { // create the acceptor object from ourselves let mut acceptor = box PipeAcceptor { listener: self, @@ -189,7 +189,7 @@ impl RtioUnixListener for PipeListener { let _m = acceptor.fire_homing_missile(); // FIXME: the 128 backlog should be configurable match unsafe { uvll::uv_listen(acceptor.listener.pipe, 128, listen_cb) } { - 0 => Ok(acceptor as ~RtioUnixAcceptor:Send), + 0 => Ok(acceptor as Box), n => Err(uv_error_to_io_error(UvError(n))), } } @@ -214,7 +214,7 @@ extern fn listen_cb(server: *uvll::uv_stream_t, status: libc::c_int) { }); let client = PipeWatcher::new_home(&loop_, pipe.home().clone(), false); assert_eq!(unsafe { uvll::uv_accept(server, client.handle()) }, 0); - Ok(box client as ~RtioPipe:Send) + Ok(box client as Box) } n => Err(uv_error_to_io_error(UvError(n))) }; @@ -231,7 +231,7 @@ impl Drop for PipeListener { // PipeAcceptor implementation and traits impl RtioUnixAcceptor for PipeAcceptor { - fn accept(&mut self) -> Result<~RtioPipe:Send, IoError> { + fn accept(&mut self) -> Result, IoError> { self.timeout.accept(&self.listener.incoming) } diff --git a/src/librustuv/process.rs b/src/librustuv/process.rs index d6d1f754b2329..d744607050fc6 100644 --- a/src/librustuv/process.rs +++ b/src/librustuv/process.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::io::IoError; -use std::io::process; use libc::c_int; use libc; +use std::io::IoError; +use std::io::process; use std::ptr; use std::rt::rtio::RtioProcess; use std::rt::task::BlockedTask; @@ -40,8 +40,7 @@ impl Process { /// Returns either the corresponding process object or an error which /// occurred. pub fn spawn(io_loop: &mut UvIoFactory, config: process::ProcessConfig) - -> Result<(~Process, ~[Option]), UvError> - { + -> Result<(Box, ~[Option]), UvError> { let cwd = config.cwd.map(|s| s.to_c_str()); let mut io = vec![config.stdin, config.stdout, config.stderr]; for slot in config.extra_io.iter() { diff --git a/src/librustuv/queue.rs b/src/librustuv/queue.rs index 58761045b97fe..561c1f6f95f5c 100644 --- a/src/librustuv/queue.rs +++ b/src/librustuv/queue.rs @@ -20,8 +20,8 @@ #![allow(dead_code)] -use std::cast; use libc::c_void; +use std::cast; use std::rt::task::BlockedTask; use std::unstable::mutex::NativeMutex; use std::sync::arc::UnsafeArc; @@ -107,7 +107,7 @@ extern fn async_cb(handle: *uvll::uv_async_t) { } impl QueuePool { - pub fn new(loop_: &mut Loop) -> ~QueuePool { + pub fn new(loop_: &mut Loop) -> Box { let handle = UvHandle::alloc(None::, uvll::UV_ASYNC); let state = UnsafeArc::new(State { handle: handle, diff --git a/src/librustuv/signal.rs b/src/librustuv/signal.rs index 3f56d3ad6863b..b2e1c7520128b 100644 --- a/src/librustuv/signal.rs +++ b/src/librustuv/signal.rs @@ -26,8 +26,8 @@ pub struct SignalWatcher { } impl SignalWatcher { - pub fn new(io: &mut UvIoFactory, signum: Signum, - channel: Sender) -> Result<~SignalWatcher, UvError> { + pub fn new(io: &mut UvIoFactory, signum: Signum, channel: Sender) + -> Result, UvError> { let s = box SignalWatcher { handle: UvHandle::alloc(None::, uvll::UV_SIGNAL), home: io.make_handle(), diff --git a/src/librustuv/timer.rs b/src/librustuv/timer.rs index 66c1a9039100a..216eb6001305e 100644 --- a/src/librustuv/timer.rs +++ b/src/librustuv/timer.rs @@ -32,7 +32,7 @@ pub enum NextAction { } impl TimerWatcher { - pub fn new(io: &mut UvIoFactory) -> ~TimerWatcher { + pub fn new(io: &mut UvIoFactory) -> Box { let handle = io.make_handle(); let me = box TimerWatcher::new_home(&io.loop_, handle); me.install() diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs index 999c5ec4e33f2..17a64fdb51760 100644 --- a/src/librustuv/uvio.rs +++ b/src/librustuv/uvio.rs @@ -93,17 +93,16 @@ impl EventLoop for UvEventLoop { IdleWatcher::onetime(&mut self.uvio.loop_, f); } - fn pausable_idle_callback(&mut self, cb: ~rtio::Callback:Send) - -> ~rtio::PausableIdleCallback:Send - { - IdleWatcher::new(&mut self.uvio.loop_, - cb) as ~rtio::PausableIdleCallback:Send + fn pausable_idle_callback(&mut self, cb: Box) + -> Box { + IdleWatcher::new(&mut self.uvio.loop_, cb) + as Box } - fn remote_callback(&mut self, f: ~rtio::Callback:Send) - -> ~rtio::RemoteCallback:Send - { - box AsyncWatcher::new(&mut self.uvio.loop_, f) as ~rtio::RemoteCallback:Send + fn remote_callback(&mut self, f: Box) + -> Box { + box AsyncWatcher::new(&mut self.uvio.loop_, f) as + Box } fn io<'a>(&'a mut self) -> Option<&'a mut rtio::IoFactory> { @@ -132,7 +131,7 @@ fn test_callback_run_once() { pub struct UvIoFactory { pub loop_: Loop, - handle_pool: Option<~QueuePool>, + handle_pool: Option>, } impl UvIoFactory { @@ -151,30 +150,31 @@ impl IoFactory for UvIoFactory { // NB: This blocks the task waiting on the connection. // It would probably be better to return a future fn tcp_connect(&mut self, addr: SocketAddr, timeout: Option) - -> Result<~rtio::RtioTcpStream:Send, IoError> - { + -> Result, IoError> { match TcpWatcher::connect(self, addr, timeout) { - Ok(t) => Ok(box t as ~rtio::RtioTcpStream:Send), + Ok(t) => Ok(box t as Box), Err(e) => Err(uv_error_to_io_error(e)), } } - fn tcp_bind(&mut self, addr: SocketAddr) -> Result<~rtio::RtioTcpListener:Send, IoError> { + fn tcp_bind(&mut self, addr: SocketAddr) + -> Result, IoError> { match TcpListener::bind(self, addr) { - Ok(t) => Ok(t as ~rtio::RtioTcpListener:Send), + Ok(t) => Ok(t as Box), Err(e) => Err(uv_error_to_io_error(e)), } } - fn udp_bind(&mut self, addr: SocketAddr) -> Result<~rtio::RtioUdpSocket:Send, IoError> { + fn udp_bind(&mut self, addr: SocketAddr) + -> Result, IoError> { match UdpWatcher::bind(self, addr) { - Ok(u) => Ok(box u as ~rtio::RtioUdpSocket:Send), + Ok(u) => Ok(box u as Box), Err(e) => Err(uv_error_to_io_error(e)), } } - fn timer_init(&mut self) -> Result<~rtio::RtioTimer:Send, IoError> { - Ok(TimerWatcher::new(self) as ~rtio::RtioTimer:Send) + fn timer_init(&mut self) -> Result, IoError> { + Ok(TimerWatcher::new(self) as Box) } fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>, @@ -183,13 +183,14 @@ impl IoFactory for UvIoFactory { r.map_err(uv_error_to_io_error) } - fn fs_from_raw_fd(&mut self, fd: c_int, - close: rtio::CloseBehavior) -> ~rtio::RtioFileStream:Send { - box FileWatcher::new(self, fd, close) as ~rtio::RtioFileStream:Send + fn fs_from_raw_fd(&mut self, fd: c_int, close: rtio::CloseBehavior) + -> Box { + box FileWatcher::new(self, fd, close) as + Box } fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess) - -> Result<~rtio::RtioFileStream:Send, IoError> { + -> Result, IoError> { let flags = match fm { io::Open => 0, io::Append => libc::O_APPEND, @@ -205,7 +206,7 @@ impl IoFactory for UvIoFactory { }; match FsRequest::open(self, path, flags as int, mode as int) { - Ok(fs) => Ok(box fs as ~rtio::RtioFileStream:Send), + Ok(fs) => Ok(box fs as Box), Err(e) => Err(uv_error_to_io_error(e)) } } @@ -270,12 +271,16 @@ impl IoFactory for UvIoFactory { } fn spawn(&mut self, config: ProcessConfig) - -> Result<(~rtio::RtioProcess:Send, ~[Option<~rtio::RtioPipe:Send>]), IoError> + -> Result<(Box, + ~[Option>]), + IoError> { match Process::spawn(self, config) { Ok((p, io)) => { - Ok((p as ~rtio::RtioProcess:Send, - io.move_iter().map(|i| i.map(|p| box p as ~rtio::RtioPipe:Send)).collect())) + Ok((p as Box, + io.move_iter().map(|i| i.map(|p| { + box p as Box + })).collect())) } Err(e) => Err(uv_error_to_io_error(e)), } @@ -285,41 +290,42 @@ impl IoFactory for UvIoFactory { Process::kill(pid, signum).map_err(uv_error_to_io_error) } - fn unix_bind(&mut self, path: &CString) -> Result<~rtio::RtioUnixListener:Send, IoError> - { + fn unix_bind(&mut self, path: &CString) + -> Result, IoError> { match PipeListener::bind(self, path) { - Ok(p) => Ok(p as ~rtio::RtioUnixListener:Send), + Ok(p) => Ok(p as Box), Err(e) => Err(uv_error_to_io_error(e)), } } - fn unix_connect(&mut self, path: &CString, - timeout: Option) -> Result<~rtio::RtioPipe:Send, IoError> { + fn unix_connect(&mut self, path: &CString, timeout: Option) + -> Result, IoError> { match PipeWatcher::connect(self, path, timeout) { - Ok(p) => Ok(box p as ~rtio::RtioPipe:Send), + Ok(p) => Ok(box p as Box), Err(e) => Err(uv_error_to_io_error(e)), } } fn tty_open(&mut self, fd: c_int, readable: bool) - -> Result<~rtio::RtioTTY:Send, IoError> { + -> Result, IoError> { match TtyWatcher::new(self, fd, readable) { - Ok(tty) => Ok(box tty as ~rtio::RtioTTY:Send), + Ok(tty) => Ok(box tty as Box), Err(e) => Err(uv_error_to_io_error(e)) } } - fn pipe_open(&mut self, fd: c_int) -> Result<~rtio::RtioPipe:Send, IoError> { + fn pipe_open(&mut self, fd: c_int) + -> Result, IoError> { match PipeWatcher::open(self, fd) { - Ok(s) => Ok(box s as ~rtio::RtioPipe:Send), + Ok(s) => Ok(box s as Box), Err(e) => Err(uv_error_to_io_error(e)) } } fn signal(&mut self, signum: Signum, channel: Sender) - -> Result<~rtio::RtioSignal:Send, IoError> { + -> Result, IoError> { match SignalWatcher::new(self, signum, channel) { - Ok(s) => Ok(s as ~rtio::RtioSignal:Send), + Ok(s) => Ok(s as Box), Err(e) => Err(uv_error_to_io_error(e)), } } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 5c86566b2af78..d1fe04bccf8f0 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -113,7 +113,7 @@ pub struct MyStruct { impl ToJson for MyStruct { fn to_json( &self ) -> json::Json { - let mut d = ~TreeMap::new(); + let mut d = box TreeMap::new(); d.insert("attr1".to_owned(), self.attr1.to_json()); d.insert("attr2".to_owned(), self.attr2.to_json()); json::Object(d) @@ -206,7 +206,7 @@ pub struct TestStruct1 { impl ToJson for TestStruct1 { fn to_json( &self ) -> json::Json { - let mut d = ~TreeMap::new(); + let mut d = box TreeMap::new(); d.insert("data_int".to_owned(), self.data_int.to_json()); d.insert("data_str".to_owned(), self.data_str.to_json()); d.insert("data_vector".to_owned(), self.data_vector.to_json()); @@ -232,21 +232,20 @@ fn main() { */ -use collections::HashMap; use std::char; use std::f64; +use std::fmt; use std::io::MemWriter; use std::io; +use std::mem::swap; use std::num; -use std::str; use std::str::ScalarValue; +use std::str; use std::strbuf::StrBuf; -use std::fmt; use std::vec::Vec; -use std::mem::swap; use Encodable; -use collections::TreeMap; +use collections::{HashMap, TreeMap}; /// Represents a json value #[deriving(Clone, Eq)] @@ -255,7 +254,7 @@ pub enum Json { String(~str), Boolean(bool), List(List), - Object(~Object), + Object(Box), Null, } diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index 65f1016515fbe..9d68705fca73f 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -391,14 +391,14 @@ impl<'a, E, S:Encoder,T:Encodable> Encodable for &'a T { } } -impl,T:Encodable> Encodable for ~T { +impl,T:Encodable> Encodable for Box { fn encode(&self, s: &mut S) -> Result<(), E> { (**self).encode(s) } } -impl,T:Decodable> Decodable for ~T { - fn decode(d: &mut D) -> Result<~T, E> { +impl,T:Decodable> Decodable for Box { + fn decode(d: &mut D) -> Result, E> { Ok(box try!(Decodable::decode(d))) } } diff --git a/src/libstd/any.rs b/src/libstd/any.rs index e448b7b8e2422..2c1ce9fa779a1 100644 --- a/src/libstd/any.rs +++ b/src/libstd/any.rs @@ -17,12 +17,13 @@ //! As `&Any` (a borrowed trait object), it has the `is` and `as_ref` methods, to test if the //! contained value is of a given type, and to get a reference to the inner value as a type. As //! `&mut Any`, there is also the `as_mut` method, for getting a mutable reference to the inner -//! value. `~Any` adds the `move` method, which will unwrap a `~T` from the object. See the -//! extension traits (`*Ext`) for the full details. +//! value. `Box` adds the `move` method, which will unwrap a `Box` from the object. See +//! the extension traits (`*Ext`) for the full details. use cast::{transmute, transmute_copy}; use fmt; use option::{Option, Some, None}; +use owned::Box; use raw::TraitObject; use result::{Result, Ok, Err}; use intrinsics::TypeId; @@ -121,12 +122,12 @@ impl<'a> AnyMutRefExt<'a> for &'a mut Any { pub trait AnyOwnExt { /// Returns the boxed value if it is of type `T`, or /// `Err(Self)` if it isn't. - fn move(self) -> Result<~T, Self>; + fn move(self) -> Result, Self>; } -impl AnyOwnExt for ~Any { +impl AnyOwnExt for Box { #[inline] - fn move(self) -> Result<~T, ~Any> { + fn move(self) -> Result, Box> { if self.is::() { unsafe { // Get the raw representation of the trait object @@ -148,9 +149,9 @@ impl AnyOwnExt for ~Any { // Trait implementations /////////////////////////////////////////////////////////////////////////////// -impl fmt::Show for ~Any { +impl fmt::Show for Box { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.pad("~Any") + f.pad("Box") } } @@ -164,6 +165,7 @@ impl<'a> fmt::Show for &'a Any { mod tests { use prelude::*; use super::*; + use owned::Box; use str::StrSlice; #[deriving(Eq, Show)] @@ -190,7 +192,7 @@ mod tests { #[test] fn any_owning() { - let (a, b, c) = (box 5u as ~Any, box TEST as ~Any, box Test as ~Any); + let (a, b, c) = (box 5u as Box, box TEST as Box, box Test as Box); assert!(a.is::()); assert!(!b.is::()); @@ -268,8 +270,8 @@ mod tests { #[test] fn any_move() { - let a = box 8u as ~Any; - let b = box Test as ~Any; + let a = box 8u as Box; + let b = box Test as Box; match a.move::() { Ok(a) => { assert_eq!(a, box 8u); } @@ -280,19 +282,19 @@ mod tests { Err(..) => fail!() } - let a = box 8u as ~Any; - let b = box Test as ~Any; + let a = box 8u as Box; + let b = box Test as Box; - assert!(a.move::<~Test>().is_err()); - assert!(b.move::<~uint>().is_err()); + assert!(a.move::>().is_err()); + assert!(b.move::>().is_err()); } #[test] fn test_show() { - let a = box 8u as ~Any; - let b = box Test as ~Any; - assert_eq!(format!("{}", a), "~Any".to_owned()); - assert_eq!(format!("{}", b), "~Any".to_owned()); + let a = box 8u as Box; + let b = box Test as Box; + assert_eq!(format!("{}", a), "Box".to_owned()); + assert_eq!(format!("{}", b), "Box".to_owned()); let a = &8u as &Any; let b = &Test as &Any; diff --git a/src/libstd/clone.rs b/src/libstd/clone.rs index e25f9c5ad4f7a..36d1cd9ba943b 100644 --- a/src/libstd/clone.rs +++ b/src/libstd/clone.rs @@ -21,6 +21,8 @@ the `clone` method. */ +use owned::Box; + /// A common trait for cloning an object. pub trait Clone { /// Returns a copy of the value. The contents of owned pointers @@ -39,14 +41,14 @@ pub trait Clone { } } -impl Clone for ~T { +impl Clone for Box { /// Return a copy of the owned box. #[inline] - fn clone(&self) -> ~T { box {(**self).clone()} } + fn clone(&self) -> Box { box {(**self).clone()} } /// Perform copy-assignment from `source` by reusing the existing allocation. #[inline] - fn clone_from(&mut self, source: &~T) { + fn clone_from(&mut self, source: &Box) { (**self).clone_from(&(**source)); } } @@ -127,7 +129,7 @@ extern_fn_clone!(A, B, C, D, E, F, G, H) #[test] fn test_owned_clone() { let a = box 5i; - let b: ~int = a.clone(); + let b: Box = a.clone(); assert_eq!(a, b); } diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index c78498924656c..bd1def518f0a9 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -279,6 +279,7 @@ use kinds::marker; use mem; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use result::{Ok, Err, Result}; use rt::local::Local; use rt::task::{Task, BlockedTask}; @@ -297,6 +298,7 @@ macro_rules! test ( use prelude::*; use super::*; use super::super::*; + use owned::Box; use task; fn f() $b @@ -549,7 +551,7 @@ impl Sender { let cnt = self.sends.get() + 1; self.sends.set(cnt); if cnt % (RESCHED_FREQ as uint) == 0 { - let task: Option<~Task> = Local::try_take(); + let task: Option> = Local::try_take(); task.map(|t| t.maybe_yield()); } @@ -773,7 +775,7 @@ impl Receiver { let cnt = self.receives.get() + 1; self.receives.set(cnt); if cnt % (RESCHED_FREQ as uint) == 0 { - let task: Option<~Task> = Local::try_take(); + let task: Option> = Local::try_take(); task.map(|t| t.maybe_yield()); } @@ -979,6 +981,7 @@ mod test { use native; use os; + use owned::Box; use super::*; pub fn stress_factor() -> uint { @@ -1197,7 +1200,7 @@ mod test { test!(fn oneshot_single_thread_send_port_close() { // Testing that the sender cleans up the payload if receiver is closed - let (tx, rx) = channel::<~int>(); + let (tx, rx) = channel::>(); drop(rx); tx.send(box 0); } #[should_fail]) @@ -1214,7 +1217,7 @@ mod test { }) test!(fn oneshot_single_thread_send_then_recv() { - let (tx, rx) = channel::<~int>(); + let (tx, rx) = channel::>(); tx.send(box 10); assert!(rx.recv() == box 10); }) @@ -1263,7 +1266,7 @@ mod test { }) test!(fn oneshot_multi_task_recv_then_send() { - let (tx, rx) = channel::<~int>(); + let (tx, rx) = channel::>(); spawn(proc() { assert!(rx.recv() == box 10); }); @@ -1272,7 +1275,7 @@ mod test { }) test!(fn oneshot_multi_task_recv_then_close() { - let (tx, rx) = channel::<~int>(); + let (tx, rx) = channel::>(); spawn(proc() { drop(tx); }); @@ -1340,7 +1343,7 @@ mod test { send(tx, 0); recv(rx, 0); - fn send(tx: Sender<~int>, i: int) { + fn send(tx: Sender>, i: int) { if i == 10 { return } spawn(proc() { @@ -1349,7 +1352,7 @@ mod test { }); } - fn recv(rx: Receiver<~int>, i: int) { + fn recv(rx: Receiver>, i: int) { if i == 10 { return } spawn(proc() { @@ -1513,6 +1516,7 @@ mod test { mod sync_tests { use prelude::*; use os; + use owned::Box; pub fn stress_factor() -> uint { match os::getenv("RUST_TEST_STRESS") { @@ -1657,7 +1661,7 @@ mod sync_tests { test!(fn oneshot_single_thread_send_port_close() { // Testing that the sender cleans up the payload if receiver is closed - let (tx, rx) = sync_channel::<~int>(0); + let (tx, rx) = sync_channel::>(0); drop(rx); tx.send(box 0); } #[should_fail]) @@ -1674,7 +1678,7 @@ mod sync_tests { }) test!(fn oneshot_single_thread_send_then_recv() { - let (tx, rx) = sync_channel::<~int>(1); + let (tx, rx) = sync_channel::>(1); tx.send(box 10); assert!(rx.recv() == box 10); }) @@ -1728,7 +1732,7 @@ mod sync_tests { }) test!(fn oneshot_multi_task_recv_then_send() { - let (tx, rx) = sync_channel::<~int>(0); + let (tx, rx) = sync_channel::>(0); spawn(proc() { assert!(rx.recv() == box 10); }); @@ -1737,7 +1741,7 @@ mod sync_tests { }) test!(fn oneshot_multi_task_recv_then_close() { - let (tx, rx) = sync_channel::<~int>(0); + let (tx, rx) = sync_channel::>(0); spawn(proc() { drop(tx); }); @@ -1805,7 +1809,7 @@ mod sync_tests { send(tx, 0); recv(rx, 0); - fn send(tx: SyncSender<~int>, i: int) { + fn send(tx: SyncSender>, i: int) { if i == 10 { return } spawn(proc() { @@ -1814,7 +1818,7 @@ mod sync_tests { }); } - fn recv(rx: Receiver<~int>, i: int) { + fn recv(rx: Receiver>, i: int) { if i == 10 { return } spawn(proc() { diff --git a/src/libstd/comm/oneshot.rs b/src/libstd/comm/oneshot.rs index e92b5cb272a80..a7124e50b663e 100644 --- a/src/libstd/comm/oneshot.rs +++ b/src/libstd/comm/oneshot.rs @@ -37,6 +37,7 @@ use kinds::Send; use mem; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use result::{Result, Ok, Err}; use rt::local::Local; use rt::task::{Task, BlockedTask}; @@ -137,7 +138,7 @@ impl Packet { // Attempt to not block the task (it's a little expensive). If it looks // like we're not empty, then immediately go through to `try_recv`. if self.state.load(atomics::SeqCst) == EMPTY { - let t: ~Task = Local::take(); + let t: Box = Local::take(); t.deschedule(1, |task| { let n = unsafe { task.cast_to_uint() }; match self.state.compare_and_swap(EMPTY, n, atomics::SeqCst) { diff --git a/src/libstd/comm/select.rs b/src/libstd/comm/select.rs index c286fd8484934..cebfeb5399e9d 100644 --- a/src/libstd/comm/select.rs +++ b/src/libstd/comm/select.rs @@ -52,6 +52,7 @@ use kinds::marker; use kinds::Send; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use ptr::RawPtr; use result::{Ok, Err, Result}; use rt::local::Local; @@ -176,7 +177,7 @@ impl Select { // Acquire a number of blocking contexts, and block on each one // sequentially until one fails. If one fails, then abort // immediately so we can go unblock on all the other receivers. - let task: ~Task = Local::take(); + let task: Box = Local::take(); task.deschedule(amt, |task| { // Prepare for the block let (i, handle) = iter.next().unwrap(); diff --git a/src/libstd/comm/shared.rs b/src/libstd/comm/shared.rs index c0f1aeae26b13..8aef2ec80a81c 100644 --- a/src/libstd/comm/shared.rs +++ b/src/libstd/comm/shared.rs @@ -24,6 +24,7 @@ use iter::Iterator; use kinds::Send; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use result::{Ok, Err, Result}; use rt::local::Local; use rt::task::{Task, BlockedTask}; @@ -223,7 +224,7 @@ impl Packet { data => return data, } - let task: ~Task = Local::take(); + let task: Box = Local::take(); task.deschedule(1, |task| { self.decrement(task) }); diff --git a/src/libstd/comm/stream.rs b/src/libstd/comm/stream.rs index 44070dc446020..9fb22ef450830 100644 --- a/src/libstd/comm/stream.rs +++ b/src/libstd/comm/stream.rs @@ -24,6 +24,7 @@ use iter::Iterator; use kinds::Send; use ops::Drop; use option::{Some, None}; +use owned::Box; use result::{Ok, Err, Result}; use rt::local::Local; use rt::task::{Task, BlockedTask}; @@ -181,7 +182,7 @@ impl Packet { // Welp, our channel has no data. Deschedule the current task and // initiate the blocking protocol. - let task: ~Task = Local::take(); + let task: Box = Local::take(); task.deschedule(1, |task| { self.decrement(task) }); diff --git a/src/libstd/comm/sync.rs b/src/libstd/comm/sync.rs index 6228c4c682b06..db3f90cad5a04 100644 --- a/src/libstd/comm/sync.rs +++ b/src/libstd/comm/sync.rs @@ -40,6 +40,7 @@ use kinds::Send; use mem; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use ptr::RawPtr; use result::{Result, Ok, Err}; use rt::local::Local; @@ -111,7 +112,7 @@ pub enum Failure { /// in the meantime. This re-locks the mutex upon returning. fn wait(slot: &mut Blocker, f: fn(BlockedTask) -> Blocker, lock: &NativeMutex) { - let me: ~Task = Local::take(); + let me: Box = Local::take(); me.deschedule(1, |task| { match mem::replace(slot, f(task)) { NoneBlocked => {} @@ -445,7 +446,7 @@ impl Buffer { impl Queue { fn enqueue(&mut self, lock: &NativeMutex) { - let task: ~Task = Local::take(); + let task: Box = Local::take(); let mut node = Node { task: None, next: 0 as *mut Node, diff --git a/src/libstd/default.rs b/src/libstd/default.rs index 8dcce3fd146ee..9cf3a76364887 100644 --- a/src/libstd/default.rs +++ b/src/libstd/default.rs @@ -10,6 +10,8 @@ //! The `Default` trait for types which may have meaningful default values +use owned::Box; + /// A trait that types which have a useful default value should implement. pub trait Default { /// Return the "default value" for a type. @@ -20,6 +22,6 @@ impl Default for @T { fn default() -> @T { @Default::default() } } -impl Default for ~T { - fn default() -> ~T { box Default::default() } +impl Default for Box { + fn default() -> Box { box Default::default() } } diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index e225dc42e0570..38456e195e36a 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -492,6 +492,7 @@ use io; use iter::{Iterator, range}; use num::Signed; use option::{Option,Some,None}; +use owned::Box; use repr; use result::{Ok, Err}; use str::StrSlice; @@ -1113,7 +1114,7 @@ pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> { impl Show for @T { fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) } } -impl Show for ~T { +impl Show for Box { fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) } } impl<'a, T: Show> Show for &'a T { diff --git a/src/libstd/fmt/parse.rs b/src/libstd/fmt/parse.rs index 0ba8cff742b41..ba126e00153bc 100644 --- a/src/libstd/fmt/parse.rs +++ b/src/libstd/fmt/parse.rs @@ -17,6 +17,7 @@ use prelude::*; use char; +use owned::Box; use str; /// A piece is a portion of the format string which represents the next part @@ -41,7 +42,7 @@ pub struct Argument<'a> { /// How to format the argument pub format: FormatSpec<'a>, /// If not `None`, what method to invoke on the argument - pub method: Option<~Method<'a>> + pub method: Option>> } /// Specification for the formatting of an argument in the format string. @@ -435,7 +436,7 @@ impl<'a> Parser<'a> { /// Parses a method to be applied to the previously specified argument and /// its format. The two current supported methods are 'plural' and 'select' - fn method(&mut self) -> Option<~Method<'a>> { + fn method(&mut self) -> Option>> { if !self.wsconsume(',') { return None; } @@ -461,7 +462,7 @@ impl<'a> Parser<'a> { } /// Parses a 'select' statement (after the initial 'select' word) - fn select(&mut self) -> ~Method<'a> { + fn select(&mut self) -> Box> { let mut other = None; let mut arms = vec!(); // Consume arms one at a time @@ -503,7 +504,7 @@ impl<'a> Parser<'a> { } /// Parses a 'plural' statement (after the initial 'plural' word) - fn plural(&mut self) -> ~Method<'a> { + fn plural(&mut self) -> Box> { let mut offset = None; let mut other = None; let mut arms = vec!(); diff --git a/src/libstd/hash/mod.rs b/src/libstd/hash/mod.rs index e8ca4037f57f1..748cf0eeed917 100644 --- a/src/libstd/hash/mod.rs +++ b/src/libstd/hash/mod.rs @@ -67,6 +67,7 @@ use container::Container; use io::Writer; use iter::Iterator; use option::{Option, Some, None}; +use owned::Box; use rc::Rc; use str::{Str, StrSlice}; use slice::{Vector, ImmutableVector}; @@ -229,7 +230,7 @@ impl<'a, S: Writer, T: Hash> Hash for &'a mut T { } } -impl> Hash for ~T { +impl> Hash for Box { #[inline] fn hash(&self, state: &mut S) { (**self).hash(state); diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 6d48b9eee3517..3f66ecd5db343 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -55,11 +55,12 @@ use container::Container; use iter::Iterator; use kinds::Send; use super::{Reader, Writer, Seek}; -use super::{SeekStyle, Read, Write, Open, IoError, Truncate, - FileMode, FileAccess, FileStat, IoResult, FilePermission}; +use super::{SeekStyle, Read, Write, Open, IoError, Truncate}; +use super::{FileMode, FileAccess, FileStat, IoResult, FilePermission}; use rt::rtio::{RtioFileStream, IoFactory, LocalIo}; use io; use option::{Some, None, Option}; +use owned::Box; use result::{Ok, Err}; use path; use path::{Path, GenericPath}; @@ -78,7 +79,7 @@ use vec::Vec; /// configured at creation time, via the `FileAccess` parameter to /// `File::open_mode()`. pub struct File { - fd: ~RtioFileStream:Send, + fd: Box, path: Path, last_nread: int, } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index ff276d0202818..59a8c6f3439d6 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -227,6 +227,7 @@ use libc; use ops::{BitOr, BitAnd, Sub}; use os; use option::{Option, Some, None}; +use owned::Box; use path::Path; use result::{Ok, Err, Result}; use str::StrSlice; @@ -811,7 +812,7 @@ pub trait Reader { } } -impl Reader for ~Reader { +impl Reader for Box { fn read(&mut self, buf: &mut [u8]) -> IoResult { self.read(buf) } } @@ -1052,7 +1053,7 @@ pub trait Writer { } } -impl Writer for ~Writer { +impl Writer for Box { fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.write(buf) } fn flush(&mut self) -> IoResult<()> { self.flush() } } diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 0619c89aac1c4..69ccd2d28c931 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -23,6 +23,7 @@ use io::net::ip::SocketAddr; use io::{Reader, Writer, Listener, Acceptor}; use kinds::Send; use option::{None, Some, Option}; +use owned::Box; use rt::rtio::{IoFactory, LocalIo, RtioSocket, RtioTcpListener}; use rt::rtio::{RtioTcpAcceptor, RtioTcpStream}; @@ -45,11 +46,11 @@ use rt::rtio::{RtioTcpAcceptor, RtioTcpStream}; /// drop(stream); // close the connection /// ``` pub struct TcpStream { - obj: ~RtioTcpStream:Send + obj: Box, } impl TcpStream { - fn new(s: ~RtioTcpStream:Send) -> TcpStream { + fn new(s: Box) -> TcpStream { TcpStream { obj: s } } @@ -148,7 +149,7 @@ impl Writer for TcpStream { /// # } /// ``` pub struct TcpListener { - obj: ~RtioTcpListener:Send + obj: Box, } impl TcpListener { @@ -181,7 +182,7 @@ impl Listener for TcpListener { /// a `TcpListener`'s `listen` method, and this object can be used to accept new /// `TcpStream` instances. pub struct TcpAcceptor { - obj: ~RtioTcpAcceptor:Send + obj: Box, } impl TcpAcceptor { diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 184069bab33d3..2cc0f853e3592 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -19,6 +19,7 @@ use clone::Clone; use io::net::ip::SocketAddr; use io::{Reader, Writer, IoResult}; use kinds::Send; +use owned::Box; use result::{Ok, Err}; use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, LocalIo}; @@ -54,7 +55,7 @@ use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, LocalIo}; /// drop(socket); // close the socket /// ``` pub struct UdpSocket { - obj: ~RtioUdpSocket:Send + obj: Box, } impl UdpSocket { diff --git a/src/libstd/io/net/unix.rs b/src/libstd/io/net/unix.rs index b75b797e9744f..f6e985dc27806 100644 --- a/src/libstd/io/net/unix.rs +++ b/src/libstd/io/net/unix.rs @@ -31,6 +31,7 @@ use clone::Clone; use io::pipe::PipeStream; use io::{Listener, Acceptor, Reader, Writer, IoResult}; use kinds::Send; +use owned::Box; use rt::rtio::{IoFactory, LocalIo, RtioUnixListener}; use rt::rtio::{RtioUnixAcceptor, RtioPipe}; @@ -40,7 +41,7 @@ pub struct UnixStream { } impl UnixStream { - fn new(obj: ~RtioPipe:Send) -> UnixStream { + fn new(obj: Box) -> UnixStream { UnixStream { obj: PipeStream::new(obj) } } @@ -107,7 +108,7 @@ impl Writer for UnixStream { /// A value that can listen for incoming named pipe connection requests. pub struct UnixListener { /// The internal, opaque runtime Unix listener. - obj: ~RtioUnixListener:Send, + obj: Box, } impl UnixListener { @@ -149,7 +150,7 @@ impl Listener for UnixListener { /// A value that can accept named pipe connections, returned from `listen()`. pub struct UnixAcceptor { /// The internal, opaque runtime Unix acceptor. - obj: ~RtioUnixAcceptor:Send, + obj: Box, } impl UnixAcceptor { diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs index 77a97f4e2590b..fbb0d5bc8d8ed 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/io/pipe.rs @@ -18,12 +18,13 @@ use prelude::*; use io::IoResult; use libc; +use owned::Box; use rt::rtio::{RtioPipe, LocalIo}; /// A synchronous, in-memory pipe. pub struct PipeStream { /// The internal, opaque runtime pipe object. - obj: ~RtioPipe:Send, + obj: Box, } impl PipeStream { @@ -54,7 +55,7 @@ impl PipeStream { } #[doc(hidden)] - pub fn new(inner: ~RtioPipe:Send) -> PipeStream { + pub fn new(inner: Box) -> PipeStream { PipeStream { obj: inner } } } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index b89e3ec3c77bc..1471a049bf317 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -17,6 +17,7 @@ use io::IoResult; use io; use libc; use mem; +use owned::Box; use rt::rtio::{RtioProcess, IoFactory, LocalIo}; /// Signal a process to exit, without forcibly killing it. Corresponds to @@ -52,7 +53,7 @@ use rt::rtio::{RtioProcess, IoFactory, LocalIo}; /// assert!(child.wait().success()); /// ``` pub struct Process { - handle: ~RtioProcess:Send, + handle: Box, /// Handle to the child's stdin, if the `stdin` field of this process's /// `ProcessConfig` was `CreatePipe`. By default, this handle is `Some`. diff --git a/src/libstd/io/signal.rs b/src/libstd/io/signal.rs index e7dae59acb881..4d294e84070fc 100644 --- a/src/libstd/io/signal.rs +++ b/src/libstd/io/signal.rs @@ -26,6 +26,7 @@ use iter::Iterator; use kinds::Send; use mem::drop; use option::{Some, None}; +use owned::Box; use result::{Ok, Err}; use rt::rtio::{IoFactory, LocalIo, RtioSignal}; use slice::ImmutableVector; @@ -81,7 +82,7 @@ pub enum Signum { /// ``` pub struct Listener { /// A map from signums to handles to keep the handles in memory - handles: Vec<(Signum, ~RtioSignal:Send)>, + handles: Vec<(Signum, Box)>, /// This is where all the handles send signums, which are received by /// the clients from the receiver. tx: Sender, diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 7cb58e1ea486c..613e9f027a4d0 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -34,6 +34,7 @@ use libc; use kinds::Send; use mem::replace; use option::{Option, Some, None}; +use owned::Box; use prelude::drop; use result::{Ok, Err}; use rt; @@ -71,8 +72,8 @@ use str::StrSlice; // tl;dr; TTY works on everything but when windows stdout is redirected, in that // case pipe also doesn't work, but magically file does! enum StdSource { - TTY(~RtioTTY:Send), - File(~RtioFileStream:Send), + TTY(Box), + File(Box), } fn src(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T { @@ -153,10 +154,9 @@ pub fn stderr_raw() -> StdWriter { src(libc::STDERR_FILENO, false, |src| StdWriter { inner: src }) } -fn reset_helper(w: ~Writer:Send, - f: |&mut Task, ~Writer:Send| -> Option<~Writer:Send>) - -> Option<~Writer:Send> -{ +fn reset_helper(w: Box, + f: |&mut Task, Box| -> Option>) + -> Option> { let mut t = Local::borrow(None::); // Be sure to flush any pending output from the writer match f(&mut *t, w) { @@ -178,7 +178,7 @@ fn reset_helper(w: ~Writer:Send, /// /// Note that this does not need to be called for all new tasks; the default /// output handle is to the process's stdout stream. -pub fn set_stdout(stdout: ~Writer:Send) -> Option<~Writer:Send> { +pub fn set_stdout(stdout: Box) -> Option> { reset_helper(stdout, |t, w| replace(&mut t.stdout, Some(w))) } @@ -190,7 +190,7 @@ pub fn set_stdout(stdout: ~Writer:Send) -> Option<~Writer:Send> { /// /// Note that this does not need to be called for all new tasks; the default /// output handle is to the process's stderr stream. -pub fn set_stderr(stderr: ~Writer:Send) -> Option<~Writer:Send> { +pub fn set_stderr(stderr: Box) -> Option> { reset_helper(stderr, |t, w| replace(&mut t.stderr, Some(w))) } @@ -205,7 +205,7 @@ pub fn set_stderr(stderr: ~Writer:Send) -> Option<~Writer:Send> { // }) // }) fn with_task_stdout(f: |&mut Writer| -> IoResult<()> ) { - let task: Option<~Task> = Local::try_take(); + let task: Option> = Local::try_take(); let result = match task { Some(mut task) => { // Printing may run arbitrary code, so ensure that the task is in @@ -216,7 +216,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()> ) { Local::put(task); if my_stdout.is_none() { - my_stdout = Some(box stdout() as ~Writer:Send); + my_stdout = Some(box stdout() as Box); } let ret = f(*my_stdout.get_mut_ref()); diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index 1ca36df968cce..96c4083e7eded 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -20,6 +20,7 @@ and create receivers which will receive notifications after a period of time. use comm::Receiver; use io::IoResult; use kinds::Send; +use owned::Box; use rt::rtio::{IoFactory, LocalIo, RtioTimer}; /// A synchronous timer object @@ -63,7 +64,7 @@ use rt::rtio::{IoFactory, LocalIo, RtioTimer}; /// # } /// ``` pub struct Timer { - obj: ~RtioTimer:Send, + obj: Box, } /// Sleep the current task for `msecs` milliseconds. diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 5cae79d371fdf..b2e6b27caabfe 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -13,6 +13,7 @@ use prelude::*; use cmp; use io; +use owned::Box; use slice::bytes::MutableByteVector; /// Wraps a `Reader`, limiting the number of bytes that can be read from it. @@ -85,12 +86,12 @@ impl Reader for NullReader { /// A `Writer` which multiplexes writes to a set of `Writers`. pub struct MultiWriter { - writers: Vec<~Writer> + writers: Vec> } impl MultiWriter { /// Creates a new `MultiWriter` - pub fn new(writers: Vec<~Writer>) -> MultiWriter { + pub fn new(writers: Vec>) -> MultiWriter { MultiWriter { writers: writers } } } @@ -199,6 +200,7 @@ pub fn copy(r: &mut R, w: &mut W) -> io::IoResult<()> { mod test { use io; use io::{MemReader, MemWriter}; + use owned::Box; use super::*; use prelude::*; @@ -273,8 +275,8 @@ mod test { } } - let mut multi = MultiWriter::new(vec!(box TestWriter as ~Writer, - box TestWriter as ~Writer)); + let mut multi = MultiWriter::new(vec!(box TestWriter as Box, + box TestWriter as Box)); multi.write([1, 2, 3]).unwrap(); assert_eq!(2, unsafe { writes }); assert_eq!(0, unsafe { flushes }); diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index daeba2365e6ec..291507c1aaf3e 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -2333,6 +2333,7 @@ mod tests { use prelude::*; use cmp; + use owned::Box; use uint; use num; @@ -2634,7 +2635,7 @@ mod tests { #[test] fn test_all() { - let v: ~&[int] = box &[1, 2, 3, 4, 5]; + let v: Box<&[int]> = box &[1, 2, 3, 4, 5]; assert!(v.iter().all(|&x| x < 10)); assert!(!v.iter().all(|&x| x % 2 == 0)); assert!(!v.iter().all(|&x| x > 100)); @@ -2643,7 +2644,7 @@ mod tests { #[test] fn test_any() { - let v: ~&[int] = box &[1, 2, 3, 4, 5]; + let v: Box<&[int]> = box &[1, 2, 3, 4, 5]; assert!(v.iter().any(|&x| x < 10)); assert!(v.iter().any(|&x| x % 2 == 0)); assert!(!v.iter().any(|&x| x > 100)); diff --git a/src/libstd/kinds.rs b/src/libstd/kinds.rs index f9827d7fa59a7..6ef71d3360a75 100644 --- a/src/libstd/kinds.rs +++ b/src/libstd/kinds.rs @@ -48,7 +48,7 @@ pub trait Copy { /// `Share`, and so are simple aggregate types containing them (like /// tuples, structs and enums). More instances of basic `Share` types /// include "immutable" types like `&T` and those with simple -/// inherited mutability, such as `~T`, `Vec` and most other +/// inherited mutability, such as `Box`, `Vec` and most other /// collection types. (Generic parameters need to be `Share` for their /// container to be `Share`.) /// diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index c34ebfdf7c20b..bf24bf405a043 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -131,6 +131,7 @@ extern crate libc; #[cfg(test)] pub use ops = realstd::ops; #[cfg(test)] pub use cmp = realstd::cmp; #[cfg(test)] pub use ty = realstd::ty; +#[cfg(test)] pub use owned = realstd::owned; // Run tests with libgreen instead of libnative. // @@ -188,7 +189,6 @@ pub mod strbuf; pub mod ascii; pub mod ptr; -pub mod owned; mod managed; mod reference; pub mod rc; @@ -201,6 +201,7 @@ pub mod gc; #[cfg(not(test))] pub mod ops; #[cfg(not(test))] pub mod cmp; #[cfg(not(test))] pub mod ty; +#[cfg(not(test))] pub mod owned; /* Common traits */ diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index e5c7ba4aa54bc..8855dabe353f6 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -45,6 +45,7 @@ use iter::{Iterator}; use kinds::Send; use mem::replace; use option::{None, Option, Some}; +use owned::Box; use rt::task::{Task, LocalStorage}; use slice::{ImmutableVector, MutableVector}; use vec::Vec; @@ -91,7 +92,7 @@ impl LocalData for T {} // a proper map. #[doc(hidden)] pub type Map = Vec>; -type TLSValue = ~LocalData:Send; +type TLSValue = Box; // Gets the map from the runtime. Lazily initialises if not done so already. unsafe fn get_local_map() -> &mut Map { @@ -161,7 +162,7 @@ pub fn pop(key: Key) -> Option { // Move `data` into transmute to get out the memory that it // owns, we must free it manually later. - let (_vtable, alloc): (uint, ~T) = unsafe { + let (_vtable, alloc): (uint, Box) = unsafe { cast::transmute(data) }; @@ -252,11 +253,12 @@ fn get_with`, so we + // extract pointer part of the trait, (as Box), and + // then use compiler coercions to achieve a '&' pointer. unsafe { - match *cast::transmute::<&TLSValue, &(uint, ~T)>(data){ + match *cast::transmute::<&TLSValue, + &(uint, Box)>(data){ (_vtable, ref alloc) => { let value: &T = *alloc; ret = f(Some(value)); @@ -297,12 +299,12 @@ pub fn set(key: Key, data: T) { let keyval = key_to_key_value(key); // When the task-local map is destroyed, all the data needs to be cleaned - // up. For this reason we can't do some clever tricks to store '~T' as a - // '*c_void' or something like that. To solve the problem, we cast + // up. For this reason we can't do some clever tricks to store 'Box' as + // a '*c_void' or something like that. To solve the problem, we cast // everything to a trait (LocalData) which is then stored inside the map. // Upon destruction of the map, all the objects will be destroyed and the // traits have enough information about them to destroy themselves. - let data = box data as ~LocalData:; + let data = box data as Box; fn insertion_position(map: &mut Map, key: *u8) -> Option { @@ -330,7 +332,7 @@ pub fn set(key: Key, data: T) { // transmute here to add the Send bound back on. This doesn't actually // matter because TLS will always own the data (until its moved out) and // we're not actually sending it to other schedulers or anything. - let data: ~LocalData:Send = unsafe { cast::transmute(data) }; + let data: Box = unsafe { cast::transmute(data) }; match insertion_position(map, keyval) { Some(i) => { *map.get_mut(i) = Some((keyval, data, NoLoan)); } None => { map.push(Some((keyval, data, NoLoan))); } @@ -353,6 +355,7 @@ pub fn modify(key: Key, f: |Option| -> Option) { mod tests { use prelude::*; use super::*; + use owned::Box; use task; use str::StrSlice; @@ -485,7 +488,7 @@ mod tests { #[test] fn test_owned() { - static key: Key<~int> = &Key; + static key: Key> = &Key; set(key, box 1); get(key, |v| { diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index b04ca63e55e4d..4ae3d453f0360 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -19,9 +19,9 @@ /// The entry point for failure of rust tasks. /// /// This macro is used to inject failure into a rust task, causing the task to -/// unwind and fail entirely. Each task's failure can be reaped as the `~Any` -/// type, and the single-argument form of the `fail!` macro will be the value -/// which is transmitted. +/// unwind and fail entirely. Each task's failure can be reaped as the +/// `Box` type, and the single-argument form of the `fail!` macro will be +/// the value which is transmitted. /// /// The multi-argument form of this macro fails with a string and has the /// `format!` syntax for building a string. diff --git a/src/libstd/option.rs b/src/libstd/option.rs index eabaf4f2f9a14..fa7b5c9485713 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -54,7 +54,7 @@ //! //! Rust's pointer types must always point to a valid location; there are //! no "null" pointers. Instead, Rust has *optional* pointers, like -//! the optional owned box, `Option<~T>`. +//! the optional owned box, `Option>`. //! //! The following example uses `Option` to create an optional box of //! `int`. Notice that in order to use the inner `int` value first the @@ -63,13 +63,13 @@ //! not (`None`). //! //! ``` -//! let optional: Option<~int> = None; +//! let optional: Option> = None; //! check_optional(&optional); //! -//! let optional: Option<~int> = Some(~9000); +//! let optional: Option> = Some(box 9000); //! check_optional(&optional); //! -//! fn check_optional(optional: &Option<~int>) { +//! fn check_optional(optional: &Option>) { //! match *optional { //! Some(ref p) => println!("have value {}", p), //! None => println!("have no value") @@ -79,7 +79,7 @@ //! //! This usage of `Option` to create safe nullable pointers is so //! common that Rust does special optimizations to make the -//! representation of `Option<~T>` a single pointer. Optional pointers +//! representation of `Option>` a single pointer. Optional pointers //! in Rust are stored as efficiently as any other pointer type. //! //! # Examples diff --git a/src/libstd/owned.rs b/src/libstd/owned.rs index 826ada8f2521f..48b80e0ca8e44 100644 --- a/src/libstd/owned.rs +++ b/src/libstd/owned.rs @@ -35,30 +35,30 @@ pub struct Box(*T); pub struct Box(*T); #[cfg(not(test))] -impl Eq for ~T { +impl Eq for Box { #[inline] - fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) } + fn eq(&self, other: &Box) -> bool { *(*self) == *(*other) } #[inline] - fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) } + fn ne(&self, other: &Box) -> bool { *(*self) != *(*other) } } #[cfg(not(test))] -impl Ord for ~T { +impl Ord for Box { #[inline] - fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) } + fn lt(&self, other: &Box) -> bool { *(*self) < *(*other) } #[inline] - fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) } + fn le(&self, other: &Box) -> bool { *(*self) <= *(*other) } #[inline] - fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) } + fn ge(&self, other: &Box) -> bool { *(*self) >= *(*other) } #[inline] - fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) } + fn gt(&self, other: &Box) -> bool { *(*self) > *(*other) } } #[cfg(not(test))] -impl TotalOrd for ~T { +impl TotalOrd for Box { #[inline] - fn cmp(&self, other: &~T) -> Ordering { (**self).cmp(*other) } + fn cmp(&self, other: &Box) -> Ordering { (**self).cmp(*other) } } #[cfg(not(test))] -impl TotalEq for ~T {} +impl TotalEq for Box {} diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 32df386953402..ee1d5d4a35ba4 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -65,6 +65,7 @@ pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize}; pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul}; pub use num::{Signed, Unsigned}; pub use num::{Primitive, Int, Float, ToPrimitive, FromPrimitive}; +pub use owned::Box; pub use path::{GenericPath, Path, PosixPath, WindowsPath}; pub use ptr::RawPtr; pub use io::{Buffer, Writer, Reader, Seek}; diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index b4b5185c2216a..dac727c2aa476 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -41,11 +41,11 @@ //! and requires no resource management later, //! but you must not use the pointer after its lifetime. //! -//! ## 2. Transmute an owned box (`~T`). +//! ## 2. Transmute an owned box (`Box`). //! //! The `transmute` function takes, by value, whatever it's given //! and returns it as whatever type is requested, as long as the -//! types are the same size. Because `~T` and `*T` have the same +//! types are the same size. Because `Box` and `*T` have the same //! representation they can be trivially, //! though unsafely, transformed from one type to the other. //! @@ -53,15 +53,15 @@ //! use std::cast; //! //! unsafe { -//! let my_num: ~int = ~10; +//! let my_num: Box = box 10; //! let my_num: *int = cast::transmute(my_num); -//! let my_speed: ~int = ~88; +//! let my_speed: Box = box 88; //! let my_speed: *mut int = cast::transmute(my_speed); //! -//! // By taking ownership of the original `~T` though +//! // By taking ownership of the original `Box` though //! // we are obligated to transmute it back later to be destroyed. -//! drop(cast::transmute::<_, ~int>(my_speed)); -//! drop(cast::transmute::<_, ~int>(my_num)); +//! drop(cast::transmute::<_, Box>(my_speed)); +//! drop(cast::transmute::<_, Box>(my_num)); //! } //! ``` //! diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index ddfc5b5853251..ec7b6cfa35545 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -18,6 +18,7 @@ Runtime type reflection use intrinsics::{Disr, Opaque, TyDesc, TyVisitor}; use mem; +use owned::Box; /** * Trait for visitor that wishes to reflect on data. To use this, create a @@ -225,9 +226,9 @@ impl TyVisitor for MovePtrAdaptor { } fn visit_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<~u8>(); + self.align_to::>(); if ! self.inner.visit_uniq(mtbl, inner) { return false; } - self.bump_past::<~u8>(); + self.bump_past::>(); true } @@ -417,9 +418,9 @@ impl TyVisitor for MovePtrAdaptor { } fn visit_trait(&mut self, name: &str) -> bool { - self.align_to::<~TyVisitor>(); + self.align_to::>(); if ! self.inner.visit_trait(name) { return false; } - self.bump_past::<~TyVisitor>(); + self.bump_past::>(); true } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index cdcd7c2321514..79b927c8d7771 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -320,7 +320,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { } fn visit_uniq(&mut self, _mtbl: uint, inner: *TyDesc) -> bool { - try!(self, self.writer.write(['~' as u8])); + try!(self, self.writer.write("box ".as_bytes())); self.get::<*u8>(|this, b| { this.visit_ptr_inner(*b, inner) }) @@ -353,7 +353,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool { self.get::<&raw::Vec<()>>(|this, b| { - try!(this, this.writer.write(['~' as u8])); + try!(this, this.writer.write("box ".as_bytes())); this.write_unboxed_vec_repr(mtbl, *b, inner) }) } @@ -624,6 +624,7 @@ fn test_repr() { use io::stdio::println; use char::is_alphabetic; use mem::swap; + use owned::Box; fn exact_test(t: &T, e:&str) { let mut m = io::MemWriter::new(); @@ -641,7 +642,7 @@ fn test_repr() { exact_test(&("he\u10f3llo".to_owned()), "~\"he\\u10f3llo\""); exact_test(&(@10), "@10"); - exact_test(&(box 10), "~10"); + exact_test(&(box 10), "box 10"); exact_test(&(&10), "&10"); let mut x = 10; exact_test(&(&mut x), "&mut 10"); @@ -650,8 +651,6 @@ fn test_repr() { exact_test(&(0 as *mut ()), "(0x0 as *mut ())"); exact_test(&(1,), "(1,)"); - exact_test(&(box ["hi", "there"]), - "~[\"hi\", \"there\"]"); exact_test(&(&["hi", "there"]), "&[\"hi\", \"there\"]"); exact_test(&(P{a:10, b:1.234}), @@ -659,7 +658,7 @@ fn test_repr() { exact_test(&(@P{a:10, b:1.234}), "@repr::P{a: 10, b: 1.234f64}"); exact_test(&(box P{a:10, b:1.234}), - "~repr::P{a: 10, b: 1.234f64}"); + "box repr::P{a: 10, b: 1.234f64}"); exact_test(&(10u8, "hello".to_owned()), "(10u8, ~\"hello\")"); exact_test(&(10u16, "hello".to_owned()), @@ -680,10 +679,6 @@ fn test_repr() { exact_test(&println, "fn(&str)"); exact_test(&swap::, "fn(&mut int, &mut int)"); exact_test(&is_alphabetic, "fn(char) -> bool"); - exact_test(&(box 5 as ~ToStr), "~to_str::ToStr"); - - struct Foo; - exact_test(&(box [Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::Foo]"); struct Bar(int, int); exact_test(&(Bar(2, 2)), "repr::test_repr::Bar(2, 2)"); diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 092efcad83154..17e6f6b769806 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -67,6 +67,7 @@ mod imp { use clone::Clone; use option::{Option, Some, None}; use iter::Iterator; + use owned::Box; use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; use mem; #[cfg(not(test))] use str::StrSlice; @@ -91,7 +92,7 @@ mod imp { with_lock(|| unsafe { let ptr = get_global_ptr(); let val = mem::replace(&mut *ptr, None); - val.as_ref().map(|s: &~~[~[u8]]| (**s).clone()) + val.as_ref().map(|s: &Box<~[~[u8]]>| (**s).clone()) }) } @@ -106,7 +107,7 @@ mod imp { pub fn clone() -> Option<~[~[u8]]> { with_lock(|| unsafe { let ptr = get_global_ptr(); - (*ptr).as_ref().map(|s: &~~[~[u8]]| (**s).clone()) + (*ptr).as_ref().map(|s: &Box<~[~[u8]]>| (**s).clone()) }) } @@ -117,7 +118,7 @@ mod imp { } } - fn get_global_ptr() -> *mut Option<~~[~[u8]]> { + fn get_global_ptr() -> *mut Option> { unsafe { cast::transmute(&global_args_ptr) } } diff --git a/src/libstd/rt/at_exit_imp.rs b/src/libstd/rt/at_exit_imp.rs index 2c8e159aeb962..051bc494adc7f 100644 --- a/src/libstd/rt/at_exit_imp.rs +++ b/src/libstd/rt/at_exit_imp.rs @@ -17,6 +17,7 @@ use iter::Iterator; use kinds::Send; use mem; use option::{Some, None}; +use owned::Box; use ptr::RawPtr; use unstable::sync::Exclusive; use slice::OwnedVector; @@ -36,7 +37,7 @@ pub fn init() { unsafe { rtassert!(!RUNNING); rtassert!(QUEUE.is_null()); - let state: ~Queue = box Exclusive::new(vec!()); + let state: Box = box Exclusive::new(vec!()); QUEUE = cast::transmute(state); } } @@ -58,7 +59,7 @@ pub fn run() { rtassert!(!RUNNING); rtassert!(!QUEUE.is_null()); RUNNING = true; - let state: ~Queue = cast::transmute(QUEUE); + let state: Box = cast::transmute(QUEUE); QUEUE = 0 as *mut Queue; let mut vec = None; state.with(|arr| { diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 26494f1acd9ee..ee8041f68802c 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -129,7 +129,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> { // see src/librustc/back/link.rs for these mappings demangle! ( "$SP$" => "@", - "$UP$" => "~", + "$UP$" => "Box", "$RP$" => "*", "$BP$" => "&", "$LT$" => "<", @@ -858,15 +858,15 @@ mod test { #[test] fn demangle_dollars() { - t!("_ZN4$UP$E", "~"); - t!("_ZN8$UP$testE", "~test"); - t!("_ZN8$UP$test4foobE", "~test::foob"); + t!("_ZN4$UP$E", "Box"); + t!("_ZN8$UP$testE", "Boxtest"); + t!("_ZN8$UP$test4foobE", "Boxtest::foob"); t!("_ZN8$x20test4foobE", " test::foob"); } #[test] fn demangle_many_dollars() { t!("_ZN12test$x20test4foobE", "test test::foob"); - t!("_ZN12test$UP$test4foobE", "test~test::foob"); + t!("_ZN12test$UP$test4foobE", "testBoxtest::foob"); } } diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 094bbd13889a0..7d54c3faf4241 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -72,9 +72,10 @@ pub unsafe fn realloc_raw(ptr: *mut u8, size: uint) -> *mut u8 { #[lang="exchange_malloc"] #[inline] pub unsafe fn exchange_malloc(size: uint) -> *mut u8 { - // The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size - // allocations can point to this `static`. It would be incorrect to use a null - // pointer, due to enums assuming types like unique pointers are never null. + // The compiler never calls `exchange_free` on Box, so + // zero-size allocations can point to this `static`. It would be incorrect + // to use a null pointer, due to enums assuming types like unique pointers + // are never null. static EMPTY: () = (); if size == 0 { diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index 828bbc118c10a..05d1f1764b59f 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -9,17 +9,18 @@ // except according to those terms. use option::Option; +use owned::Box; use rt::task::Task; use rt::local_ptr; /// Encapsulates some task-local data. pub trait Local { - fn put(value: ~Self); - fn take() -> ~Self; - fn try_take() -> Option<~Self>; + fn put(value: Box); + fn take() -> Box; + fn try_take() -> Option>; fn exists(unused_value: Option) -> bool; fn borrow(unused_value: Option) -> Borrowed; - unsafe fn unsafe_take() -> ~Self; + unsafe fn unsafe_take() -> Box; unsafe fn unsafe_borrow() -> *mut Self; unsafe fn try_unsafe_borrow() -> Option<*mut Self>; } @@ -27,11 +28,11 @@ pub trait Local { #[allow(visible_private_types)] impl Local> for Task { #[inline] - fn put(value: ~Task) { unsafe { local_ptr::put(value) } } + fn put(value: Box) { unsafe { local_ptr::put(value) } } #[inline] - fn take() -> ~Task { unsafe { local_ptr::take() } } + fn take() -> Box { unsafe { local_ptr::take() } } #[inline] - fn try_take() -> Option<~Task> { unsafe { local_ptr::try_take() } } + fn try_take() -> Option> { unsafe { local_ptr::try_take() } } fn exists(_: Option) -> bool { local_ptr::exists() } #[inline] fn borrow(_: Option) -> local_ptr::Borrowed { @@ -40,7 +41,7 @@ impl Local> for Task { } } #[inline] - unsafe fn unsafe_take() -> ~Task { local_ptr::unsafe_take() } + unsafe fn unsafe_take() -> Box { local_ptr::unsafe_take() } #[inline] unsafe fn unsafe_borrow() -> *mut Task { local_ptr::unsafe_borrow() } #[inline] @@ -54,6 +55,7 @@ mod test { use option::{None, Option}; use unstable::run_in_bare_thread; use super::*; + use owned::Box; use rt::task::Task; #[test] @@ -61,7 +63,7 @@ mod test { run_in_bare_thread(proc() { let task = box Task::new(); Local::put(task); - let task: ~Task = Local::take(); + let task: Box = Local::take(); cleanup_task(task); }); } @@ -71,11 +73,11 @@ mod test { run_in_bare_thread(proc() { let task = box Task::new(); Local::put(task); - let task: ~Task = Local::take(); + let task: Box = Local::take(); cleanup_task(task); let task = box Task::new(); Local::put(task); - let task: ~Task = Local::take(); + let task: Box = Local::take(); cleanup_task(task); }); } @@ -89,7 +91,7 @@ mod test { unsafe { let _task: *mut Task = Local::unsafe_borrow(); } - let task: ~Task = Local::take(); + let task: Box = Local::take(); cleanup_task(task); }); } @@ -104,7 +106,7 @@ mod test { let _ = Local::borrow(None::); } - let task: ~Task = Local::take(); + let task: Box = Local::take(); cleanup_task(task); }); } @@ -115,15 +117,15 @@ mod test { let task = box Task::new(); Local::put(task); - let t: ~Task = Local::try_take().unwrap(); - let u: Option<~Task> = Local::try_take(); + let t: Box = Local::try_take().unwrap(); + let u: Option> = Local::try_take(); assert!(u.is_none()); cleanup_task(t); }); } - fn cleanup_task(mut t: ~Task) { + fn cleanup_task(mut t: Box) { t.destroyed = true; } diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index f60cfa23e81f9..39c0d9a548207 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -10,7 +10,7 @@ //! Access to a single thread-local pointer. //! -//! The runtime will use this for storing ~Task. +//! The runtime will use this for storing Box. //! //! FIXME: Add runtime checks for usage of inconsistent pointer types. //! and for overwriting an existing pointer. @@ -19,6 +19,7 @@ use cast; use ops::{Drop, Deref, DerefMut}; +use owned::Box; use ptr::RawPtr; #[cfg(windows)] // mingw-w32 doesn't like thread_local things @@ -43,7 +44,7 @@ impl Drop for Borrowed { if self.val.is_null() { rtabort!("Aiee, returning null borrowed object!"); } - let val: ~T = cast::transmute(self.val); + let val: Box = cast::transmute(self.val); put::(val); rtassert!(exists()); } @@ -84,6 +85,7 @@ pub unsafe fn borrow() -> Borrowed { pub mod compiled { use cast; use option::{Option, Some, None}; + use owned::Box; use ptr::RawPtr; #[cfg(test)] @@ -154,7 +156,7 @@ pub mod compiled { /// /// Does not validate the pointer type. #[inline(never)] // see comments above - pub unsafe fn put(sched: ~T) { + pub unsafe fn put(sched: Box) { RT_TLS_PTR = cast::transmute(sched) } @@ -164,10 +166,10 @@ pub mod compiled { /// /// Does not validate the pointer type. #[inline(never)] // see comments above - pub unsafe fn take() -> ~T { + pub unsafe fn take() -> Box { let ptr = RT_TLS_PTR; rtassert!(!ptr.is_null()); - let ptr: ~T = cast::transmute(ptr); + let ptr: Box = cast::transmute(ptr); // can't use `as`, due to type not matching with `cfg(test)` RT_TLS_PTR = cast::transmute(0); ptr @@ -179,12 +181,12 @@ pub mod compiled { /// /// Does not validate the pointer type. #[inline(never)] // see comments above - pub unsafe fn try_take() -> Option<~T> { + pub unsafe fn try_take() -> Option> { let ptr = RT_TLS_PTR; if ptr.is_null() { None } else { - let ptr: ~T = cast::transmute(ptr); + let ptr: Box = cast::transmute(ptr); // can't use `as`, due to type not matching with `cfg(test)` RT_TLS_PTR = cast::transmute(0); Some(ptr) @@ -198,7 +200,7 @@ pub mod compiled { /// Does not validate the pointer type. /// Leaves the old pointer in TLS for speed. #[inline(never)] // see comments above - pub unsafe fn unsafe_take() -> ~T { + pub unsafe fn unsafe_take() -> Box { cast::transmute(RT_TLS_PTR) } @@ -234,6 +236,7 @@ pub mod compiled { pub mod native { use cast; use option::{Option, Some, None}; + use owned::Box; use ptr; use ptr::RawPtr; use tls = rt::thread_local_storage; @@ -259,7 +262,7 @@ pub mod native { /// /// Does not validate the pointer type. #[inline] - pub unsafe fn put(sched: ~T) { + pub unsafe fn put(sched: Box) { let key = tls_key(); let void_ptr: *mut u8 = cast::transmute(sched); tls::set(key, void_ptr); @@ -271,13 +274,13 @@ pub mod native { /// /// Does not validate the pointer type. #[inline] - pub unsafe fn take() -> ~T { + pub unsafe fn take() -> Box { let key = tls_key(); let void_ptr: *mut u8 = tls::get(key); if void_ptr.is_null() { rtabort!("thread-local pointer is null. bogus!"); } - let ptr: ~T = cast::transmute(void_ptr); + let ptr: Box = cast::transmute(void_ptr); tls::set(key, ptr::mut_null()); return ptr; } @@ -288,14 +291,14 @@ pub mod native { /// /// Does not validate the pointer type. #[inline] - pub unsafe fn try_take() -> Option<~T> { + pub unsafe fn try_take() -> Option> { match maybe_tls_key() { Some(key) => { let void_ptr: *mut u8 = tls::get(key); if void_ptr.is_null() { None } else { - let ptr: ~T = cast::transmute(void_ptr); + let ptr: Box = cast::transmute(void_ptr); tls::set(key, ptr::mut_null()); Some(ptr) } @@ -311,13 +314,13 @@ pub mod native { /// Does not validate the pointer type. /// Leaves the old pointer in TLS for speed. #[inline] - pub unsafe fn unsafe_take() -> ~T { + pub unsafe fn unsafe_take() -> Box { let key = tls_key(); let void_ptr: *mut u8 = tls::get(key); if void_ptr.is_null() { rtabort!("thread-local pointer is null. bogus!"); } - let ptr: ~T = cast::transmute(void_ptr); + let ptr: Box = cast::transmute(void_ptr); return ptr; } diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index b407bf8897ca4..e79e305683892 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -57,6 +57,7 @@ Several modules in `core` are clients of `rt`: use any::Any; use kinds::Send; use option::Option; +use owned::Box; use result::Result; use task::TaskOpts; @@ -151,22 +152,25 @@ pub static DEFAULT_ERROR_CODE: int = 101; pub trait Runtime { // Necessary scheduling functions, used for channels and blocking I/O // (sometimes). - fn yield_now(~self, cur_task: ~Task); - fn maybe_yield(~self, cur_task: ~Task); - fn deschedule(~self, times: uint, cur_task: ~Task, + fn yield_now(~self, cur_task: Box); + fn maybe_yield(~self, cur_task: Box); + fn deschedule(~self, times: uint, cur_task: Box, f: |BlockedTask| -> Result<(), BlockedTask>); - fn reawaken(~self, to_wake: ~Task); + fn reawaken(~self, to_wake: Box); // Miscellaneous calls which are very different depending on what context // you're in. - fn spawn_sibling(~self, cur_task: ~Task, opts: TaskOpts, f: proc():Send); + fn spawn_sibling(~self, + cur_task: Box, + opts: TaskOpts, + f: proc():Send); fn local_io<'a>(&'a mut self) -> Option>; /// The (low, high) edges of the current stack. fn stack_bounds(&self) -> (uint, uint); // (lo, hi) fn can_block(&self) -> bool; // FIXME: This is a serious code smell and this should not exist at all. - fn wrap(~self) -> ~Any; + fn wrap(~self) -> Box; } /// One-time runtime initialization. diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index fc8c79549af23..fe9f4932a2a20 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -18,6 +18,7 @@ use libc; use kinds::Send; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use path::Path; use result::Err; use rt::local::Local; @@ -40,9 +41,10 @@ pub trait Callback { pub trait EventLoop { fn run(&mut self); fn callback(&mut self, arg: proc():Send); - fn pausable_idle_callback(&mut self, - ~Callback:Send) -> ~PausableIdleCallback:Send; - fn remote_callback(&mut self, ~Callback:Send) -> ~RemoteCallback:Send; + fn pausable_idle_callback(&mut self, Box) + -> Box; + fn remote_callback(&mut self, Box) + -> Box; /// The asynchronous I/O services. Not all event loops may provide one. fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory>; @@ -114,7 +116,7 @@ impl<'a> LocalIo<'a> { // // In order to get around this, we just transmute a copy out of the task // in order to have what is likely a static lifetime (bad). - let mut t: ~Task = Local::take(); + let mut t: Box = Local::take(); let ret = t.local_io().map(|t| { unsafe { cast::transmute_copy(&t) } }); @@ -149,21 +151,23 @@ impl<'a> LocalIo<'a> { pub trait IoFactory { // networking fn tcp_connect(&mut self, addr: SocketAddr, - timeout: Option) -> IoResult<~RtioTcpStream:Send>; - fn tcp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioTcpListener:Send>; - fn udp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioUdpSocket:Send>; + timeout: Option) -> IoResult>; + fn tcp_bind(&mut self, addr: SocketAddr) + -> IoResult>; + fn udp_bind(&mut self, addr: SocketAddr) + -> IoResult>; fn unix_bind(&mut self, path: &CString) - -> IoResult<~RtioUnixListener:Send>; + -> IoResult>; fn unix_connect(&mut self, path: &CString, - timeout: Option) -> IoResult<~RtioPipe:Send>; + timeout: Option) -> IoResult>; fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>, hint: Option) -> IoResult<~[ai::Info]>; // filesystem operations fn fs_from_raw_fd(&mut self, fd: c_int, close: CloseBehavior) - -> ~RtioFileStream:Send; + -> Box; fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess) - -> IoResult<~RtioFileStream:Send>; + -> IoResult>; fn fs_unlink(&mut self, path: &CString) -> IoResult<()>; fn fs_stat(&mut self, path: &CString) -> IoResult; fn fs_mkdir(&mut self, path: &CString, @@ -184,23 +188,24 @@ pub trait IoFactory { IoResult<()>; // misc - fn timer_init(&mut self) -> IoResult<~RtioTimer:Send>; + fn timer_init(&mut self) -> IoResult>; fn spawn(&mut self, config: ProcessConfig) - -> IoResult<(~RtioProcess:Send, ~[Option<~RtioPipe:Send>])>; + -> IoResult<(Box, + ~[Option>])>; fn kill(&mut self, pid: libc::pid_t, signal: int) -> IoResult<()>; - fn pipe_open(&mut self, fd: c_int) -> IoResult<~RtioPipe:Send>; + fn pipe_open(&mut self, fd: c_int) -> IoResult>; fn tty_open(&mut self, fd: c_int, readable: bool) - -> IoResult<~RtioTTY:Send>; + -> IoResult>; fn signal(&mut self, signal: Signum, channel: Sender) - -> IoResult<~RtioSignal:Send>; + -> IoResult>; } pub trait RtioTcpListener : RtioSocket { - fn listen(~self) -> IoResult<~RtioTcpAcceptor:Send>; + fn listen(~self) -> IoResult>; } pub trait RtioTcpAcceptor : RtioSocket { - fn accept(&mut self) -> IoResult<~RtioTcpStream:Send>; + fn accept(&mut self) -> IoResult>; fn accept_simultaneously(&mut self) -> IoResult<()>; fn dont_accept_simultaneously(&mut self) -> IoResult<()>; fn set_timeout(&mut self, timeout: Option); @@ -214,7 +219,7 @@ pub trait RtioTcpStream : RtioSocket { fn nodelay(&mut self) -> IoResult<()>; fn keepalive(&mut self, delay_in_seconds: uint) -> IoResult<()>; fn letdie(&mut self) -> IoResult<()>; - fn clone(&self) -> ~RtioTcpStream:Send; + fn clone(&self) -> Box; fn close_write(&mut self) -> IoResult<()>; } @@ -238,7 +243,7 @@ pub trait RtioUdpSocket : RtioSocket { fn hear_broadcasts(&mut self) -> IoResult<()>; fn ignore_broadcasts(&mut self) -> IoResult<()>; - fn clone(&self) -> ~RtioUdpSocket:Send; + fn clone(&self) -> Box; } pub trait RtioTimer { @@ -268,15 +273,15 @@ pub trait RtioProcess { pub trait RtioPipe { fn read(&mut self, buf: &mut [u8]) -> IoResult; fn write(&mut self, buf: &[u8]) -> IoResult<()>; - fn clone(&self) -> ~RtioPipe:Send; + fn clone(&self) -> Box; } pub trait RtioUnixListener { - fn listen(~self) -> IoResult<~RtioUnixAcceptor:Send>; + fn listen(~self) -> IoResult>; } pub trait RtioUnixAcceptor { - fn accept(&mut self) -> IoResult<~RtioPipe:Send>; + fn accept(&mut self) -> IoResult>; fn set_timeout(&mut self, timeout: Option); } diff --git a/src/libstd/rt/stack.rs b/src/libstd/rt/stack.rs index 963ff000c4ad1..b9bcd1de8fc25 100644 --- a/src/libstd/rt/stack.rs +++ b/src/libstd/rt/stack.rs @@ -37,6 +37,7 @@ pub static RED_ZONE: uint = 20 * 1024; #[cfg(not(test))] // in testing, use the original libstd's version pub extern "C" fn rust_stack_exhausted() { use option::{Option, None, Some}; + use owned::Box; use rt::local::Local; use rt::task::Task; use str::Str; @@ -85,7 +86,7 @@ pub extern "C" fn rust_stack_exhausted() { // #9854 - unwinding on windows through __morestack has never worked // #2361 - possible implementation of not using landing pads - let task: Option<~Task> = Local::try_take(); + let task: Option> = Local::try_take(); let name = match task { Some(ref task) => { task.name.as_ref().map(|n| n.as_slice()) diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index ae5786604c7a1..5b29de5a8c1d3 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -24,6 +24,7 @@ use kinds::Send; use local_data; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use prelude::drop; use result::{Result, Ok, Err}; use rt::Runtime; @@ -51,19 +52,20 @@ pub struct Task { pub destroyed: bool, pub name: Option, - pub stdout: Option<~Writer:Send>, - pub stderr: Option<~Writer:Send>, + pub stdout: Option>, + pub stderr: Option>, - imp: Option<~Runtime:Send>, + imp: Option>, } pub struct GarbageCollector; pub struct LocalStorage(pub Option); -/// A handle to a blocked task. Usually this means having the ~Task pointer by -/// ownership, but if the task is killable, a killer can steal it at any time. +/// A handle to a blocked task. Usually this means having the Box +/// pointer by ownership, but if the task is killable, a killer can steal it +/// at any time. pub enum BlockedTask { - Owned(~Task), + Owned(Box), Shared(UnsafeArc), } @@ -109,12 +111,12 @@ impl Task { /// This function is *not* meant to be abused as a "try/catch" block. This /// is meant to be used at the absolute boundaries of a task's lifetime, and /// only for that purpose. - pub fn run(~self, mut f: ||) -> ~Task { + pub fn run(~self, mut f: ||) -> Box { // Need to put ourselves into TLS, but also need access to the unwinder. // Unsafely get a handle to the task so we can continue to use it after // putting it in tls (so we can invoke the unwinder). let handle: *mut Task = unsafe { - *cast::transmute::<&~Task, &*mut Task>(&self) + *cast::transmute::<&Box, &*mut Task>(&self) }; Local::put(self); @@ -187,7 +189,7 @@ impl Task { let me: *mut Task = Local::unsafe_borrow(); (*me).death.collect_failure((*me).unwinder.result()); } - let mut me: ~Task = Local::take(); + let mut me: Box = Local::take(); me.destroyed = true; return me; } @@ -195,7 +197,7 @@ impl Task { /// Inserts a runtime object into this task, transferring ownership to the /// task. It is illegal to replace a previous runtime object in this task /// with this argument. - pub fn put_runtime(&mut self, ops: ~Runtime:Send) { + pub fn put_runtime(&mut self, ops: Box) { assert!(self.imp.is_none()); self.imp = Some(ops); } @@ -207,12 +209,12 @@ impl Task { /// /// It is recommended to only use this method when *absolutely necessary*. /// This function may not be available in the future. - pub fn maybe_take_runtime(&mut self) -> Option<~T> { + pub fn maybe_take_runtime(&mut self) -> Option> { // This is a terrible, terrible function. The general idea here is to - // take the runtime, cast it to ~Any, check if it has the right type, - // and then re-cast it back if necessary. The method of doing this is - // pretty sketchy and involves shuffling vtables of trait objects - // around, but it gets the job done. + // take the runtime, cast it to Box, check if it has the right + // type, and then re-cast it back if necessary. The method of doing + // this is pretty sketchy and involves shuffling vtables of trait + // objects around, but it gets the job done. // // FIXME: This function is a serious code smell and should be avoided at // all costs. I have yet to think of a method to avoid this @@ -225,7 +227,8 @@ impl Task { Ok(t) => Some(t), Err(t) => { let (_, obj): (uint, uint) = cast::transmute(t); - let obj: ~Runtime:Send = cast::transmute((vtable, obj)); + let obj: Box = + cast::transmute((vtable, obj)); self.put_runtime(obj); None } @@ -308,7 +311,7 @@ impl Iterator for BlockedTasks { impl BlockedTask { /// Returns Some if the task was successfully woken; None if already killed. - pub fn wake(self) -> Option<~Task> { + pub fn wake(self) -> Option> { match self { Owned(task) => Some(task), Shared(arc) => unsafe { @@ -326,7 +329,7 @@ impl BlockedTask { #[cfg(test)] pub fn trash(self) { assert!(self.wake().is_none()); } /// Create a blocked task, unless the task was already killed. - pub fn block(task: ~Task) -> BlockedTask { + pub fn block(task: Box) -> BlockedTask { Owned(task) } @@ -367,7 +370,7 @@ impl BlockedTask { if blocked_task_ptr & 0x1 == 0 { Owned(cast::transmute(blocked_task_ptr)) } else { - let ptr: ~UnsafeArc = + let ptr: Box> = cast::transmute(blocked_task_ptr & !1); Shared(*ptr) } diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index a836958279b8e..bc9a0b3460ac6 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -22,6 +22,7 @@ use kinds::Send; use libc; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use uint; type StartFn = extern "C" fn(*libc::c_void) -> imp::rust_thread_return; @@ -31,7 +32,7 @@ type StartFn = extern "C" fn(*libc::c_void) -> imp::rust_thread_return; pub struct Thread { native: imp::rust_thread, joined: bool, - packet: ~Option, + packet: Box>, } static DEFAULT_STACK_SIZE: uint = 1024 * 1024; @@ -45,7 +46,7 @@ extern fn thread_start(main: *libc::c_void) -> imp::rust_thread_return { use rt::stack; unsafe { stack::record_stack_bounds(0, uint::MAX); - let f: ~proc() = cast::transmute(main); + let f: Box = cast::transmute(main); (*f)(); cast::transmute(0 as imp::rust_thread_return) } @@ -78,11 +79,11 @@ impl Thread<()> { pub fn start_stack(stack: uint, main: proc():Send -> T) -> Thread { // We need the address of the packet to fill in to be stable so when - // `main` fills it in it's still valid, so allocate an extra ~ box to do + // `main` fills it in it's still valid, so allocate an extra box to do // so. let packet = box None; let packet2: *mut Option = unsafe { - *cast::transmute::<&~Option, **mut Option>(&packet) + *cast::transmute::<&Box>, **mut Option>(&packet) }; let main = proc() unsafe { *packet2 = Some(main()); }; let native = unsafe { imp::create(stack, box main) }; @@ -152,13 +153,14 @@ mod imp { use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, SIZE_T, BOOL, LPVOID, DWORD, LPDWORD, HANDLE}; use os; + use owned::Box; use ptr; use rt::stack::RED_ZONE; pub type rust_thread = HANDLE; pub type rust_thread_return = DWORD; - pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { + pub unsafe fn create(stack: uint, p: Box) -> rust_thread { let arg: *mut libc::c_void = cast::transmute(p); // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least @@ -175,7 +177,7 @@ mod imp { if ret as uint == 0 { // be sure to not leak the closure - let _p: ~proc():Send = cast::transmute(arg); + let _p: Box = cast::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } return ret; @@ -218,13 +220,14 @@ mod imp { use libc; use mem; use os; + use owned::Box; use ptr; use rt::stack::RED_ZONE; pub type rust_thread = libc::pthread_t; pub type rust_thread_return = *u8; - pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { + pub unsafe fn create(stack: uint, p: Box) -> rust_thread { let mut native: libc::pthread_t = mem::uninit(); let mut attr: libc::pthread_attr_t = mem::uninit(); assert_eq!(pthread_attr_init(&mut attr), 0); @@ -257,7 +260,7 @@ mod imp { if ret != 0 { // be sure to not leak the closure - let _p: ~proc():Send = cast::transmute(arg); + let _p: Box = cast::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } native diff --git a/src/libstd/rt/thread_local_storage.rs b/src/libstd/rt/thread_local_storage.rs index fceff80e792aa..7706206863617 100644 --- a/src/libstd/rt/thread_local_storage.rs +++ b/src/libstd/rt/thread_local_storage.rs @@ -10,6 +10,8 @@ #![allow(dead_code)] +#[cfg(test)] +use owned::Box; #[cfg(unix)] use libc::c_int; #[cfg(unix)] @@ -99,11 +101,11 @@ fn tls_smoke_test() { let value = box 20; create(&mut key); set(key, transmute(value)); - let value: ~int = transmute(get(key)); + let value: Box = transmute(get(key)); assert_eq!(value, box 20); let value = box 30; set(key, transmute(value)); - let value: ~int = transmute(get(key)); + let value: Box = transmute(get(key)); assert_eq!(value, box 30); } } diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 98623c35b7899..3ba97f381ab08 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -64,6 +64,7 @@ use fmt; use kinds::Send; use mem; use option::{Some, None, Option}; +use owned::Box; use prelude::drop; use ptr::RawPtr; use result::{Err, Ok}; @@ -78,7 +79,7 @@ use uw = rt::libunwind; pub struct Unwinder { unwinding: bool, - cause: Option<~Any:Send> + cause: Option> } impl Unwinder { @@ -128,7 +129,7 @@ impl Unwinder { } } - pub fn begin_unwind(&mut self, cause: ~Any:Send) -> ! { + pub fn begin_unwind(&mut self, cause: Box) -> ! { rtdebug!("begin_unwind()"); self.unwinding = true; @@ -154,7 +155,8 @@ impl Unwinder { exception: *uw::_Unwind_Exception) { rtdebug!("exception_cleanup()"); unsafe { - let _: ~uw::_Unwind_Exception = cast::transmute(exception); + let _: Box = + cast::transmute(exception); } } } @@ -374,14 +376,16 @@ pub fn begin_unwind(msg: M, file: &'static str, line: uint) -> ! /// Do this split took the LLVM IR line counts of `fn main() { fail!() /// }` from ~1900/3700 (-O/no opts) to 180/590. #[inline(never)] #[cold] // this is the slow path, please never inline this -fn begin_unwind_inner(msg: ~Any:Send, file: &'static str, line: uint) -> ! { +fn begin_unwind_inner(msg: Box, + file: &'static str, + line: uint) -> ! { let mut task; { let msg_s = match msg.as_ref::<&'static str>() { Some(s) => *s, None => match msg.as_ref::<~str>() { Some(s) => s.as_slice(), - None => "~Any", + None => "Box", } }; @@ -392,7 +396,7 @@ fn begin_unwind_inner(msg: ~Any:Send, file: &'static str, line: uint) -> ! { // order to get some better diagnostics, we print on failure and // immediately abort the whole process if there is no local task // available. - let opt_task: Option<~Task> = Local::try_take(); + let opt_task: Option> = Local::try_take(); task = match opt_task { Some(t) => t, None => { diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs index d8c866ef44a39..2ea6dc1afe613 100644 --- a/src/libstd/slice.rs +++ b/src/libstd/slice.rs @@ -2352,10 +2352,11 @@ impl FromIterator for ~[A] { #[cfg(test)] mod tests { use prelude::*; - use mem; - use slice::*; use cmp::*; + use mem; + use owned::Box; use rand::{Rng, task_rng}; + use slice::*; fn square(n: uint) -> uint { n * n } @@ -2738,8 +2739,8 @@ mod tests { let mut v2 = vec![box 1, box 2, box 3, box 3]; v2.dedup(); /* - * If the ~pointers were leaked or otherwise misused, valgrind and/or - * rustrt should raise errors. + * If the boxed pointers were leaked or otherwise misused, valgrind + * and/or rustrt should raise errors. */ } @@ -3117,7 +3118,7 @@ mod tests { struct S { f: Cell, - boxes: (~int, Rc) + boxes: (Box, Rc) } impl Clone for S { @@ -3566,13 +3567,7 @@ mod tests { } assert_eq!(cnt, 11); - let xs = vec![Foo, Foo, Foo]; - assert_eq!(format!("{:?}", xs.slice(0, 2).to_owned()), - "~[slice::tests::Foo, slice::tests::Foo]".to_owned()); - let xs: [Foo, ..3] = [Foo, Foo, Foo]; - assert_eq!(format!("{:?}", xs.slice(0, 2).to_owned()), - "~[slice::tests::Foo, slice::tests::Foo]".to_owned()); cnt = 0; for f in xs.iter() { assert!(*f == Foo); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 430f63263271c..2a51de7ce5cea 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -20,9 +20,9 @@ Rust. Each string must also be decorated with its ownership. This means that there are two common kinds of strings in Rust: * `~str` - This is an owned string. This type obeys all of the normal semantics - of the `~T` types, meaning that it has one, and only one, owner. This - type cannot be implicitly copied, and is moved out of when passed to - other functions. + of the `Box` types, meaning that it has one, and only one, + owner. This type cannot be implicitly copied, and is moved out of + when passed to other functions. * `&str` - This is the borrowed string type. This type of string can only be created from the other kind of string. As the name "borrowed" diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs index 0cf975a4c1c96..d277c514e444f 100644 --- a/src/libstd/sync/arc.rs +++ b/src/libstd/sync/arc.rs @@ -26,6 +26,7 @@ use clone::Clone; use iter::Iterator; use kinds::Send; use ops::Drop; +use owned::Box; use ptr::RawPtr; use sync::atomics::{fence, AtomicUint, Relaxed, Acquire, Release}; use ty::Unsafe; @@ -157,7 +158,7 @@ impl Drop for UnsafeArc{ // happened before), and an "acquire" operation before deleting the object. // [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html) fence(Acquire); - let _: ~ArcData = cast::transmute(self.data); + let _: Box> = cast::transmute(self.data); } } } diff --git a/src/libstd/sync/atomics.rs b/src/libstd/sync/atomics.rs index a3c1c33f77c53..2fba59c3233e2 100644 --- a/src/libstd/sync/atomics.rs +++ b/src/libstd/sync/atomics.rs @@ -88,7 +88,7 @@ //! } //! }); //! -//! shared_big_object.swap(~BigObject, SeqCst); +//! shared_big_object.swap(box BigObject, SeqCst); //! } //! ``` //! @@ -112,6 +112,7 @@ use cast; use std::kinds::marker; use option::{Option,Some,None}; use ops::Drop; +use owned::Box; use ty::Unsafe; /// An atomic boolean type. @@ -663,7 +664,7 @@ impl AtomicPtr { impl AtomicOption { /// Create a new `AtomicOption` - pub fn new(p: ~T) -> AtomicOption { + pub fn new(p: Box) -> AtomicOption { unsafe { AtomicOption { p: Unsafe::new(cast::transmute(p)) } } } @@ -672,7 +673,7 @@ impl AtomicOption { /// Store a value, returning the old value #[inline] - pub fn swap(&self, val: ~T, order: Ordering) -> Option<~T> { + pub fn swap(&self, val: Box, order: Ordering) -> Option> { unsafe { let val = cast::transmute(val); @@ -687,7 +688,7 @@ impl AtomicOption { /// Remove the value, leaving the `AtomicOption` empty. #[inline] - pub fn take(&self, order: Ordering) -> Option<~T> { + pub fn take(&self, order: Ordering) -> Option> { unsafe { self.swap(cast::transmute(0), order) } } @@ -697,7 +698,7 @@ impl AtomicOption { /// the option was already `Some`, returns `Some` of the rejected /// value. #[inline] - pub fn fill(&self, val: ~T, order: Ordering) -> Option<~T> { + pub fn fill(&self, val: Box, order: Ordering) -> Option> { unsafe { let val = cast::transmute(val); let expected = cast::transmute(0); diff --git a/src/libstd/sync/deque.rs b/src/libstd/sync/deque.rs index 22ed66b708b7e..d06062f02ac8a 100644 --- a/src/libstd/sync/deque.rs +++ b/src/libstd/sync/deque.rs @@ -56,6 +56,7 @@ use libc; use mem; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use ptr; use ptr::RawPtr; use sync::arc::UnsafeArc; @@ -117,7 +118,7 @@ pub enum Stolen { /// will only use this structure when allocating a new buffer or deallocating a /// previous one. pub struct BufferPool { - pool: Exclusive>>, + pool: Exclusive>>>, } /// An internal buffer used by the chase-lev deque. This structure is actually @@ -154,7 +155,7 @@ impl BufferPool { (Worker { deque: a }, Stealer { deque: b }) } - fn alloc(&mut self, bits: int) -> ~Buffer { + fn alloc(&mut self, bits: int) -> Box> { unsafe { self.pool.with(|pool| { match pool.iter().position(|x| x.size() >= (1 << bits)) { @@ -165,7 +166,7 @@ impl BufferPool { } } - fn free(&mut self, buf: ~Buffer) { + fn free(&mut self, buf: Box>) { unsafe { let mut buf = Some(buf); self.pool.with(|pool| { @@ -400,6 +401,7 @@ mod tests { use super::{Data, BufferPool, Abort, Empty, Worker, Stealer}; use cast; + use owned::Box; use rt::thread::Thread; use rand; use rand::Rng; @@ -471,7 +473,7 @@ mod tests { t.join(); } - fn stampede(mut w: Worker<~int>, s: Stealer<~int>, + fn stampede(mut w: Worker>, s: Stealer>, nthreads: int, amt: uint) { for _ in range(0, amt) { w.push(box 20); @@ -486,7 +488,7 @@ mod tests { let mut s = s; while (*unsafe_remaining).load(SeqCst) > 0 { match s.steal() { - Data(~20) => { + Data(box 20) => { (*unsafe_remaining).fetch_sub(1, SeqCst); } Data(..) => fail!(), @@ -499,7 +501,7 @@ mod tests { while remaining.load(SeqCst) > 0 { match w.pop() { - Some(~20) => { remaining.fetch_sub(1, SeqCst); } + Some(box 20) => { remaining.fetch_sub(1, SeqCst); } Some(..) => fail!(), None => {} } @@ -512,7 +514,7 @@ mod tests { #[test] fn run_stampede() { - let mut pool = BufferPool::<~int>::new(); + let mut pool = BufferPool::>::new(); let (w, s) = pool.deque(); stampede(w, s, 8, 10000); } @@ -520,7 +522,7 @@ mod tests { #[test] fn many_stampede() { static AMT: uint = 4; - let mut pool = BufferPool::<~int>::new(); + let mut pool = BufferPool::>::new(); let threads = range(0, AMT).map(|_| { let (w, s) = pool.deque(); Thread::start(proc() { @@ -605,7 +607,8 @@ mod tests { let s = s.clone(); let unique_box = box AtomicUint::new(0); let thread_box = unsafe { - *cast::transmute::<&~AtomicUint,**mut AtomicUint>(&unique_box) + *cast::transmute::<&Box, + **mut AtomicUint>(&unique_box) }; (Thread::start(proc() { unsafe { diff --git a/src/libstd/sync/mpsc_queue.rs b/src/libstd/sync/mpsc_queue.rs index 315e412446d6b..e05959e25918b 100644 --- a/src/libstd/sync/mpsc_queue.rs +++ b/src/libstd/sync/mpsc_queue.rs @@ -42,6 +42,7 @@ use cast; use kinds::Send; use ops::Drop; use option::{Option, None, Some}; +use owned::Box; use ptr::RawPtr; use sync::atomics::{AtomicPtr, Release, Acquire, AcqRel, Relaxed}; @@ -120,7 +121,7 @@ impl Queue { assert!((*tail).value.is_none()); assert!((*next).value.is_some()); let ret = (*next).value.take_unwrap(); - let _: ~Node = cast::transmute(tail); + let _: Box> = cast::transmute(tail); return Data(ret); } @@ -145,7 +146,7 @@ impl Drop for Queue { let mut cur = self.tail; while !cur.is_null() { let next = (*cur).next.load(Relaxed); - let _: ~Node = cast::transmute(cur); + let _: Box> = cast::transmute(cur); cur = next; } } diff --git a/src/libstd/sync/spsc_queue.rs b/src/libstd/sync/spsc_queue.rs index f155bdca44646..7854a0e168ebd 100644 --- a/src/libstd/sync/spsc_queue.rs +++ b/src/libstd/sync/spsc_queue.rs @@ -37,6 +37,7 @@ use cast; use kinds::Send; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use ptr::RawPtr; use sync::atomics::{AtomicPtr, Relaxed, AtomicUint, Acquire, Release}; @@ -187,7 +188,7 @@ impl Queue { (*self.tail_prev.load(Relaxed)).next.store(next, Relaxed); // We have successfully erased all references to 'tail', so // now we can safely drop it. - let _: ~Node = cast::transmute(tail); + let _: Box> = cast::transmute(tail); } } return ret; @@ -215,7 +216,7 @@ impl Drop for Queue { let mut cur = self.first; while !cur.is_null() { let next = (*cur).next.load(Relaxed); - let _n: ~Node = cast::transmute(cur); + let _n: Box> = cast::transmute(cur); cur = next; } } diff --git a/src/libstd/task.rs b/src/libstd/task.rs index e9b01063f94c1..7c5e984ad3675 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -41,6 +41,7 @@ use comm::{Sender, Receiver, channel}; use io::Writer; use kinds::{Send, marker}; use option::{None, Some, Option}; +use owned::Box; use result::{Result, Ok, Err}; use rt::local::Local; use rt::task::Task; @@ -56,7 +57,7 @@ use str::{Str, SendStr, IntoMaybeOwned}; /// /// If you wish for this result's delivery to block until all /// children tasks complete, recommend using a result future. -pub type TaskResult = Result<(), ~Any:Send>; +pub type TaskResult = Result<(), Box>; /// Task configuration options pub struct TaskOpts { @@ -67,9 +68,9 @@ pub struct TaskOpts { /// The size of the stack for the spawned task pub stack_size: Option, /// Task-local stdout - pub stdout: Option<~Writer:Send>, + pub stdout: Option>, /// Task-local stderr - pub stderr: Option<~Writer:Send>, + pub stderr: Option>, } /** @@ -173,7 +174,7 @@ impl TaskBuilder { Some(gen) => gen(f), None => f }; - let t: ~Task = Local::take(); + let t: Box = Local::take(); t.spawn_sibling(self.opts, f); } @@ -190,7 +191,8 @@ impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - pub fn try(mut self, f: proc():Send -> T) -> Result { + pub fn try(mut self, f: proc():Send -> T) + -> Result> { let (tx, rx) = channel(); let result = self.future_result(); @@ -240,7 +242,7 @@ pub fn spawn(f: proc():Send) { /// the function or an error if the task failed /// /// This is equivalent to TaskBuilder::new().try -pub fn try(f: proc():Send -> T) -> Result { +pub fn try(f: proc():Send -> T) -> Result> { TaskBuilder::new().try(f) } @@ -264,7 +266,7 @@ pub fn deschedule() { use rt::local::Local; // FIXME(#7544): Optimize this, since we know we won't block. - let task: ~Task = Local::take(); + let task: Box = Local::take(); task.yield_now(); } @@ -507,10 +509,10 @@ fn test_try_fail_message_owned_str() { #[test] fn test_try_fail_message_any() { match try(proc() { - fail!(box 413u16 as ~Any:Send); + fail!(box 413u16 as Box); }) { Err(e) => { - type T = ~Any:Send; + type T = Box; assert!(e.is::()); let any = e.move::().unwrap(); assert!(any.is::()); diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index e264615578e42..f0f126bcf16c2 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -971,9 +971,9 @@ impl Vec { /// # Example /// /// ```rust - /// let mut vec = vec!(~1); - /// vec.push_all_move(vec!(~2, ~3, ~4)); - /// assert_eq!(vec, vec!(~1, ~2, ~3, ~4)); + /// let mut vec = vec!(box 1); + /// vec.push_all_move(vec!(box 2, box 3, box 4)); + /// assert_eq!(vec, vec!(box 1, box 2, box 3, box 4)); /// ``` pub fn push_all_move(&mut self, other: Vec) { self.extend(other.move_iter()); diff --git a/src/libsync/mutex.rs b/src/libsync/mutex.rs index e41484c46bd75..54c3a9c77f816 100644 --- a/src/libsync/mutex.rs +++ b/src/libsync/mutex.rs @@ -208,7 +208,7 @@ impl StaticMutex { // After we've failed the fast path, then we delegate to the differnet // locking protocols for green/native tasks. This will select two tasks // to continue further (one native, one green). - let t: ~Task = Local::take(); + let t: Box = Local::take(); let can_block = t.can_block(); let native_bit; if can_block { @@ -244,7 +244,7 @@ impl StaticMutex { // regularly in native/green contention. Due to try_lock and the header // of lock stealing the lock, it's also possible for native/native // contention to hit this location, but as less common. - let t: ~Task = Local::take(); + let t: Box = Local::take(); t.deschedule(1, |task| { let task = unsafe { task.cast_to_uint() }; @@ -308,7 +308,7 @@ impl StaticMutex { // Tasks which can block are super easy. These tasks just call the blocking // `lock()` function on an OS mutex - fn native_lock(&self, t: ~Task) { + fn native_lock(&self, t: Box) { Local::put(t); unsafe { self.lock.lock_noguard(); } } @@ -317,7 +317,7 @@ impl StaticMutex { unsafe { self.lock.unlock_noguard(); } } - fn green_lock(&self, t: ~Task) { + fn green_lock(&self, t: Box) { // Green threads flag their presence with an atomic counter, and if they // fail to be the first to the mutex, they enqueue themselves on a // concurrent internal queue with a stack-allocated node. diff --git a/src/libsync/raw.rs b/src/libsync/raw.rs index 6ab833a19efbd..313720fa932dc 100644 --- a/src/libsync/raw.rs +++ b/src/libsync/raw.rs @@ -167,7 +167,9 @@ impl Sem { #[unsafe_destructor] impl Drop for Sem { fn drop(&mut self) { - let _waiters: ~SemInner = unsafe { cast::transmute(self.inner) }; + let _waiters: Box> = unsafe { + cast::transmute(self.inner) + }; self.inner = 0 as *(); } } @@ -835,7 +837,7 @@ mod tests { let m = Arc::new(Mutex::new()); let m2 = m.clone(); - let result: result::Result<(), ~Any:Send> = task::try(proc() { + let result: result::Result<(), Box> = task::try(proc() { let _lock = m2.lock(); fail!(); }); @@ -1075,7 +1077,7 @@ mod tests { let x = Arc::new(RWLock::new()); let x2 = x.clone(); - let result: result::Result<(), ~Any:Send> = task::try(proc() { + let result: result::Result<(), Box> = task::try(proc() { lock_rwlock_in_mode(&x2, mode1, || { fail!(); }) diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 46bbc8768c9bf..ee61ce24c30f8 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -121,7 +121,7 @@ pub fn is_shift_binop(b: BinOp) -> bool { pub fn unop_to_str(op: UnOp) -> &'static str { match op { UnBox => "@", - UnUniq => "~", + UnUniq => "box() ", UnDeref => "*", UnNot => "!", UnNeg => "-", diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index f09072e0bc605..ee03046b6d689 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -111,7 +111,7 @@ impl SpanHandler { // others log errors for later reporting. pub struct Handler { err_count: Cell, - emit: RefCell<~Emitter:Send>, + emit: RefCell>, } impl Handler { @@ -180,7 +180,7 @@ pub fn default_handler() -> Handler { mk_handler(box EmitterWriter::stderr()) } -pub fn mk_handler(e: ~Emitter:Send) -> Handler { +pub fn mk_handler(e: Box) -> Handler { Handler { err_count: Cell::new(0), emit: RefCell::new(e), @@ -253,7 +253,7 @@ pub struct EmitterWriter { enum Destination { Terminal(term::Terminal), - Raw(~Writer:Send), + Raw(Box), } impl EmitterWriter { @@ -270,7 +270,7 @@ impl EmitterWriter { } } - pub fn new(dst: ~Writer:Send) -> EmitterWriter { + pub fn new(dst: Box) -> EmitterWriter { EmitterWriter { dst: Raw(dst) } } } diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 9b362f8d9425c..b9c8be290caac 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -20,6 +20,7 @@ use parse; use parse::token::InternedString; use parse::token; + enum State { Asm, Outputs, @@ -45,7 +46,7 @@ impl State { static OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"]; pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { let mut p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.iter() diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index cee6216b23fdd..01ec4c84b683e 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -50,19 +50,19 @@ pub trait MacroExpander { ecx: &mut ExtCtxt, span: Span, token_tree: &[ast::TokenTree]) - -> ~MacResult; + -> Box; } pub type MacroExpanderFn = fn(ecx: &mut ExtCtxt, span: codemap::Span, token_tree: &[ast::TokenTree]) - -> ~MacResult; + -> Box; impl MacroExpander for BasicMacroExpander { fn expand(&self, ecx: &mut ExtCtxt, span: Span, token_tree: &[ast::TokenTree]) - -> ~MacResult { + -> Box { (self.expander)(ecx, span, token_tree) } } @@ -78,7 +78,7 @@ pub trait IdentMacroExpander { sp: Span, ident: ast::Ident, token_tree: Vec ) - -> ~MacResult; + -> Box; } impl IdentMacroExpander for BasicIdentMacroExpander { @@ -87,13 +87,13 @@ impl IdentMacroExpander for BasicIdentMacroExpander { sp: Span, ident: ast::Ident, token_tree: Vec ) - -> ~MacResult { + -> Box { (self.expander)(cx, sp, ident, token_tree) } } pub type IdentMacroExpanderFn = - fn(&mut ExtCtxt, Span, ast::Ident, Vec ) -> ~MacResult; + fn(&mut ExtCtxt, Span, ast::Ident, Vec) -> Box; pub type MacroCrateRegistrationFun = fn(|ast::Name, SyntaxExtension|); @@ -130,8 +130,8 @@ pub struct MacExpr { e: @ast::Expr } impl MacExpr { - pub fn new(e: @ast::Expr) -> ~MacResult { - box MacExpr { e: e } as ~MacResult + pub fn new(e: @ast::Expr) -> Box { + box MacExpr { e: e } as Box } } impl MacResult for MacExpr { @@ -144,8 +144,8 @@ pub struct MacItem { i: @ast::Item } impl MacItem { - pub fn new(i: @ast::Item) -> ~MacResult { - box MacItem { i: i } as ~MacResult + pub fn new(i: @ast::Item) -> Box { + box MacItem { i: i } as Box } } impl MacResult for MacItem { @@ -173,8 +173,8 @@ impl DummyResult { /// /// Use this as a return value after hitting any errors and /// calling `span_err`. - pub fn any(sp: Span) -> ~MacResult { - box DummyResult { expr_only: false, span: sp } as ~MacResult + pub fn any(sp: Span) -> Box { + box DummyResult { expr_only: false, span: sp } as Box } /// Create a default MacResult that can only be an expression. @@ -182,8 +182,8 @@ impl DummyResult { /// Use this for macros that must expand to an expression, so even /// if an error is encountered internally, the user will recieve /// an error that they also used it in the wrong place. - pub fn expr(sp: Span) -> ~MacResult { - box DummyResult { expr_only: true, span: sp } as ~MacResult + pub fn expr(sp: Span) -> Box { + box DummyResult { expr_only: true, span: sp } as Box } /// A plain dummy expression. @@ -229,13 +229,13 @@ pub enum SyntaxExtension { /// A normal, function-like syntax extension. /// /// `bytes!` is a `NormalTT`. - NormalTT(~MacroExpander:'static, Option), + NormalTT(Box, Option), /// A function-like syntax extension that has an extra ident before /// the block. /// /// `macro_rules!` is an `IdentTT`. - IdentTT(~IdentMacroExpander:'static, Option), + IdentTT(Box, Option), } pub struct BlockInfo { diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index c6349d616eca3..06b50e37cbd9e 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -16,7 +16,9 @@ use ext::base::*; use ext::base; use ext::build::AstBuilder; -pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~base::MacResult { + +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) + -> Box { // Gather all argument expressions let exprs = match get_exprs_from_tts(cx, sp, tts) { None => return DummyResult::expr(sp), diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax/ext/cfg.rs index 8cd899738bf29..3e74b2680e060 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax/ext/cfg.rs @@ -26,7 +26,9 @@ use parse::token::InternedString; use parse::token; use parse; -pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~base::MacResult { + +pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) + -> Box { let mut p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.iter() diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index fe7fa636e7d59..7c6c9892002c9 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -18,7 +18,8 @@ use std::strbuf::StrBuf; pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box { let es = match base::get_exprs_from_tts(cx, sp, tts) { Some(e) => e, None => return base::DummyResult::expr(sp) diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 9513c15c3d0b1..0e168e7b33b70 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -19,7 +19,7 @@ use parse::token::{str_to_ident}; use std::strbuf::StrBuf; pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { let mut res_str = StrBuf::new(); for (i, e) in tts.iter().enumerate() { if i & 1 == 1 { diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index bf886e51885d5..a3f9eaee892e7 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -571,7 +571,7 @@ impl<'a> MethodDef<'a> { Self if nonstatic => { self_args.push(arg_expr); } - Ptr(~Self, _) if nonstatic => { + Ptr(box Self, _) if nonstatic => { self_args.push(cx.expr_deref(trait_.span, arg_expr)) } _ => { diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 769bbe2fc4e2f..602245b4c470f 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -20,6 +20,7 @@ use ext::build::AstBuilder; use codemap::{Span,respan}; use owned_slice::OwnedSlice; + /// The types of pointers pub enum PtrTy<'a> { Send, // ~ @@ -31,7 +32,7 @@ pub enum PtrTy<'a> { pub struct Path<'a> { pub path: Vec<&'a str> , pub lifetime: Option<&'a str>, - pub params: Vec<~Ty<'a>> , + pub params: Vec>>, pub global: bool, } @@ -44,7 +45,7 @@ impl<'a> Path<'a> { } pub fn new_<'r>(path: Vec<&'r str> , lifetime: Option<&'r str>, - params: Vec<~Ty<'r>> , + params: Vec>>, global: bool) -> Path<'r> { Path { @@ -80,8 +81,8 @@ impl<'a> Path<'a> { /// A type. Supports pointers (except for *), Self, and literals pub enum Ty<'a> { Self, - // &/~/@ Ty - Ptr(~Ty<'a>, PtrTy<'a>), + // &/Box/@ Ty + Ptr(Box>, PtrTy<'a>), // mod::mod::Type<[lifetime], [Params...]>, including a plain type // parameter, and things like `int` Literal(Path<'a>), @@ -92,7 +93,7 @@ pub enum Ty<'a> { pub fn borrowed_ptrty<'r>() -> PtrTy<'r> { Borrowed(None, ast::MutImmutable) } -pub fn borrowed<'r>(ty: ~Ty<'r>) -> Ty<'r> { +pub fn borrowed<'r>(ty: Box>) -> Ty<'r> { Ptr(ty, borrowed_ptrty()) } diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 7229f5c1df9eb..ea3fef352be67 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -24,7 +24,7 @@ use parse::token; use std::os; pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { let var = match get_single_str_from_tts(cx, sp, tts, "option_env!") { None => return DummyResult::expr(sp), Some(v) => v @@ -60,7 +60,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { let exprs = match get_exprs_from_tts(cx, sp, tts) { Some(ref exprs) if exprs.len() == 0 => { cx.span_err(sp, "env! takes 1 or 2 arguments"); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 734d07ccb8f9b..0dc62728e5c95 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1100,12 +1100,6 @@ mod test { } } - //fn fake_print_crate(krate: &ast::Crate) { - // let mut out = ~std::io::stderr() as ~std::io::Writer; - // let mut s = pprust::rust_printer(out, get_ident_interner()); - // pprust::print_crate_(&mut s, krate); - //} - fn expand_crate_str(crate_str: ~str) -> ast::Crate { let ps = parse::new_parse_sess(); let crate_ast = string_to_parser(&ps, crate_str).parse_crate_mod(); diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 41c74ce9ae543..0907541eee0e0 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -15,8 +15,11 @@ use codemap::Span; use ext::base; use ext::build::AstBuilder; -pub fn expand_syntax_ext(ecx: &mut base::ExtCtxt, sp: Span, - _tts: &[ast::TokenTree]) -> ~base::MacResult { + +pub fn expand_syntax_ext(ecx: &mut base::ExtCtxt, + sp: Span, + _tts: &[ast::TokenTree]) + -> Box { ecx.span_err(sp, "`fmt!` is deprecated, use `format!` instead"); ecx.parse_sess.span_diagnostic.span_note(sp, "see http://static.rust-lang.org/doc/master/std/fmt/index.html \ diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 0d856fb689d44..fc3136996ae10 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -805,7 +805,7 @@ impl<'a, 'b> Context<'a, 'b> { } pub fn expand_args(ecx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) -> Box { match parse_args(ecx, sp, tts) { (extra, Some((efmt, args, order, names))) => { diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 666bc486fbf0b..486d060da77be 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -18,7 +18,7 @@ use std::rc::Rc; pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, tt: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { cx.print_backtrace(); println!("{}", print::pprust::tt_to_str(&ast::TTDelim( diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index fc7f772235474..4d8be9bab7685 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -17,6 +17,7 @@ use parse::token::*; use parse::token; use parse; + /** * * Quasiquoting works via token trees. @@ -312,7 +313,8 @@ pub mod rt { pub fn expand_quote_tokens(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box { let (cx_expr, expr) = expand_tts(cx, sp, tts); let expanded = expand_wrapper(cx, sp, cx_expr, expr); base::MacExpr::new(expanded) @@ -320,14 +322,15 @@ pub fn expand_quote_tokens(cx: &mut ExtCtxt, pub fn expand_quote_expr(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) -> Box { let expanded = expand_parse_call(cx, sp, "parse_expr", Vec::new(), tts); base::MacExpr::new(expanded) } pub fn expand_quote_item(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box { let e_attrs = cx.expr_vec_ng(sp); let expanded = expand_parse_call(cx, sp, "parse_item", vec!(e_attrs), tts); @@ -336,7 +339,8 @@ pub fn expand_quote_item(cx: &mut ExtCtxt, pub fn expand_quote_pat(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box { let e_refutable = cx.expr_lit(sp, ast::LitBool(true)); let expanded = expand_parse_call(cx, sp, "parse_pat", vec!(e_refutable), tts); @@ -345,7 +349,8 @@ pub fn expand_quote_pat(cx: &mut ExtCtxt, pub fn expand_quote_ty(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box { let e_param_colons = cx.expr_lit(sp, ast::LitBool(false)); let expanded = expand_parse_call(cx, sp, "parse_ty", vec!(e_param_colons), tts); @@ -354,7 +359,8 @@ pub fn expand_quote_ty(cx: &mut ExtCtxt, pub fn expand_quote_stmt(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box { let e_attrs = cx.expr_vec_ng(sp); let expanded = expand_parse_call(cx, sp, "parse_stmt", vec!(e_attrs), tts); diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 7f1d81722557e..e221ab80d7bbc 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -29,7 +29,7 @@ use std::str; /* line!(): expands to the current line number */ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { base::check_zero_tts(cx, sp, tts, "line!"); let topmost = topmost_expn_info(cx.backtrace().unwrap()); @@ -40,7 +40,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) /* col!(): expands to the current column number */ pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { base::check_zero_tts(cx, sp, tts, "col!"); let topmost = topmost_expn_info(cx.backtrace().unwrap()); @@ -52,7 +52,7 @@ pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) /* The filemap (`loc.file`) contains a bunch more information we could spit * out if we wanted. */ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { base::check_zero_tts(cx, sp, tts, "file!"); let topmost = topmost_expn_info(cx.backtrace().unwrap()); @@ -62,13 +62,13 @@ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { let s = pprust::tts_to_str(tts); base::MacExpr::new(cx.expr_str(sp, token::intern_and_get_ident(s))) } pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { base::check_zero_tts(cx, sp, tts, "module_path!"); let string = cx.mod_path() .iter() @@ -82,7 +82,7 @@ pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) // This is generally a bad idea because it's going to behave // unhygienically. pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { let file = match get_single_str_from_tts(cx, sp, tts, "include!") { Some(f) => f, None => return DummyResult::expr(sp), @@ -100,7 +100,7 @@ pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) // include_str! : read the given file, insert it as a literal string expr pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") { Some(f) => f, None => return DummyResult::expr(sp) @@ -131,8 +131,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult -{ + -> Box { let file = match get_single_str_from_tts(cx, sp, tts, "include_bin!") { Some(f) => f, None => return DummyResult::expr(sp) diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index d428251604c95..773246326648a 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -14,10 +14,11 @@ use ext::base::ExtCtxt; use ext::base; use parse::token::{keywords, is_keyword}; + pub fn expand_trace_macros(cx: &mut ExtCtxt, sp: Span, tt: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box { match tt { [ast::TTTok(_, ref tok)] if is_keyword(keywords::True, tok) => { cx.set_trace_macros(true); diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 4c426bef12e5b..ee3ff0c389e21 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -102,7 +102,7 @@ pub struct MatcherPos { elts: Vec , // maybe should be <'>? Need to understand regions. sep: Option, idx: uint, - up: Option<~MatcherPos>, + up: Option>, matches: Vec>>, match_lo: uint, match_hi: uint, sp_lo: BytePos, @@ -120,7 +120,7 @@ pub fn count_names(ms: &[Matcher]) -> uint { } pub fn initial_matcher_pos(ms: Vec , sep: Option, lo: BytePos) - -> ~MatcherPos { + -> Box { let mut match_idx_hi = 0u; for elt in ms.iter() { match elt.node { diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index ab0266cedaae9..5a02acdae1cea 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -95,7 +95,7 @@ impl MacroExpander for MacroRulesMacroExpander { cx: &mut ExtCtxt, sp: Span, arg: &[ast::TokenTree]) - -> ~MacResult { + -> Box { generic_extension(cx, sp, self.name, @@ -121,7 +121,7 @@ fn generic_extension(cx: &ExtCtxt, arg: &[ast::TokenTree], lhses: &[Rc], rhses: &[Rc]) - -> ~MacResult { + -> Box { if cx.trace_macros() { println!("{}! \\{ {} \\}", token::get_ident(name), @@ -171,7 +171,7 @@ fn generic_extension(cx: &ExtCtxt, // Weird, but useful for X-macros. return box ParserAnyMacro { parser: RefCell::new(p), - } as ~MacResult + } as Box } Failure(sp, ref msg) => if sp.lo >= best_fail_spot.lo { best_fail_spot = sp; @@ -193,7 +193,7 @@ pub fn add_new_extension(cx: &mut ExtCtxt, sp: Span, name: Ident, arg: Vec ) - -> ~base::MacResult { + -> Box { // these spans won't matter, anyways fn ms(m: Matcher_) -> Matcher { Spanned { @@ -250,5 +250,5 @@ pub fn add_new_extension(cx: &mut ExtCtxt, name: token::get_ident(name).to_str(), ext: NormalTT(exp, Some(sp)) })) - } as ~MacResult + } as Box } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 8fa4857cab02c..f6bee0335533b 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -254,7 +254,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { /* sidestep the interpolation tricks for ident because (a) idents can be in lots of places, so it'd be a pain (b) we actually can, since it's a token. */ - MatchedNonterminal(NtIdent(~sn,b)) => { + MatchedNonterminal(NtIdent(box sn, b)) => { r.cur_span = sp; r.cur_tok = IDENT(sn,b); return ret_val; diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index d09a002e11765..b9157e0043d1e 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -40,6 +40,9 @@ pub enum ObsoleteSyntax { ObsoleteManagedPattern, ObsoleteManagedString, ObsoleteManagedVec, + ObsoleteOwnedType, + ObsoleteOwnedExpr, + ObsoleteOwnedPattern, } pub trait ParserObsoleteMethods { @@ -126,6 +129,18 @@ impl<'a> ParserObsoleteMethods for Parser<'a> { "managed vector", "use `Rc<~[T]>` instead of a managed vector" ), + ObsoleteOwnedType => ( + "`~` notation for owned pointers", + "use `Box` in `std::owned` instead" + ), + ObsoleteOwnedExpr => ( + "`~` notation for owned pointer allocation", + "use the `box` operator instead of `~`" + ), + ObsoleteOwnedPattern => ( + "`~` notation for owned pointer patterns", + "use the `box` operator instead of `~`" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 11a773a7f0930..74c2ab9c494d6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -273,7 +273,10 @@ struct ParsedItemsAndViewItems { /* ident is handled by common.rs */ -pub fn Parser<'a>(sess: &'a ParseSess, cfg: ast::CrateConfig, mut rdr: ~Reader:) +pub fn Parser<'a>( + sess: &'a ParseSess, + cfg: ast::CrateConfig, + mut rdr: Box) -> Parser<'a> { let tok0 = rdr.next_token(); let span = tok0.sp; @@ -318,14 +321,14 @@ pub struct Parser<'a> { pub last_span: Span, pub cfg: CrateConfig, // the previous token or None (only stashed sometimes). - pub last_token: Option<~token::Token>, + pub last_token: Option>, pub buffer: [TokenAndSpan, ..4], pub buffer_start: int, pub buffer_end: int, pub tokens_consumed: uint, pub restriction: restriction, pub quote_depth: uint, // not (yet) related to the quasiquoter - pub reader: ~Reader:, + pub reader: Box, pub interner: Rc, /// The set of seen errors about obsolete syntax. Used to suppress /// extra detail when the same error is seen twice @@ -1221,6 +1224,14 @@ impl<'a> Parser<'a> { } else if self.token == token::TILDE { // OWNED POINTER self.bump(); + match self.token { + token::IDENT(ref ident, _) + if "str" == token::get_ident(*ident).get() => { + // This is OK (for now). + } + token::LBRACKET => {} // Also OK. + _ => self.obsolete(self.last_span, ObsoleteOwnedType), + }; TyUniq(self.parse_ty(false)) } else if self.token == token::BINOP(token::STAR) { // STAR POINTER (bare pointer?) @@ -1445,7 +1456,7 @@ impl<'a> Parser<'a> { _ => None, }; match found { - Some(INTERPOLATED(token::NtPath(~path))) => { + Some(INTERPOLATED(token::NtPath(box path))) => { return PathAndBounds { path: path, bounds: None, @@ -2258,9 +2269,13 @@ impl<'a> Parser<'a> { ex = match e.node { ExprVec(..) | ExprRepeat(..) => ExprVstore(e, ExprVstoreUniq), ExprLit(lit) if lit_is_str(lit) => { + self.obsolete(self.last_span, ObsoleteOwnedExpr); ExprVstore(e, ExprVstoreUniq) } - _ => self.mk_unary(UnUniq, e) + _ => { + self.obsolete(self.last_span, ObsoleteOwnedExpr); + self.mk_unary(UnUniq, e) + } }; } token::IDENT(_, _) if self.is_keyword(keywords::Box) => { @@ -2772,6 +2787,7 @@ impl<'a> Parser<'a> { let sub = self.parse_pat(); pat = PatUniq(sub); hi = self.last_span.hi; + self.obsolete(self.last_span, ObsoleteOwnedPattern); return @ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 519a7d141d33f..e4e71baad44eb 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -113,9 +113,9 @@ pub enum Nonterminal { NtPat( @ast::Pat), NtExpr(@ast::Expr), NtTy( P), - NtIdent(~ast::Ident, bool), + NtIdent(Box, bool), NtMeta(@ast::MetaItem), // stuff inside brackets for attributes - NtPath(~ast::Path), + NtPath(Box), NtTT( @ast::TokenTree), // needs @ed to break a circularity NtMatchers(Vec ) } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 21215748fb438..a32cad701754c 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -155,7 +155,7 @@ pub struct PrintStackElem { static SIZE_INFINITY: int = 0xffff; -pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer { +pub fn mk_printer(out: Box, linewidth: uint) -> Printer { // Yes 3, it makes the ring buffers big enough to never // fall behind. let n: uint = 3 * linewidth; @@ -262,7 +262,7 @@ pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer { * called 'print'. */ pub struct Printer { - pub out: ~io::Writer, + pub out: Box, buf_len: uint, margin: int, // width of lines we're constrained to space: int, // number of spaces left on line diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index fb82352261214..310ca18e4faf0 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -65,12 +65,12 @@ pub struct State<'a> { ann: &'a PpAnn } -pub fn rust_printer(writer: ~io::Writer) -> State<'static> { +pub fn rust_printer(writer: Box) -> State<'static> { static NO_ANN: NoAnn = NoAnn; rust_printer_annotated(writer, &NO_ANN) } -pub fn rust_printer_annotated<'a>(writer: ~io::Writer, +pub fn rust_printer_annotated<'a>(writer: Box, ann: &'a PpAnn) -> State<'a> { State { s: pp::mk_printer(writer, default_columns), @@ -99,7 +99,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap, krate: &ast::Crate, filename: ~str, input: &mut io::Reader, - out: ~io::Writer, + out: Box, ann: &'a PpAnn, is_expanded: bool) -> IoResult<()> { let (cmnts, lits) = comments::gather_comments_and_literals( @@ -140,7 +140,7 @@ pub fn to_str(f: |&mut State| -> IoResult<()>) -> ~str { // FIXME(pcwalton): A nasty function to extract the string from an `io::Writer` // that we "know" to be a `MemWriter` that works around the lack of checked // downcasts. - let (_, wr): (uint, ~MemWriter) = cast::transmute_copy(&s.s.out); + let (_, wr): (uint, Box) = cast::transmute_copy(&s.s.out); let result = str::from_utf8_owned(wr.get_ref().to_owned()).unwrap(); cast::forget(wr); result @@ -1113,7 +1113,7 @@ impl<'a> State<'a> { pub fn print_expr_vstore(&mut self, t: ast::ExprVstore) -> IoResult<()> { match t { - ast::ExprVstoreUniq => word(&mut self.s, "~"), + ast::ExprVstoreUniq => word(&mut self.s, "box "), ast::ExprVstoreSlice => word(&mut self.s, "&"), ast::ExprVstoreMutSlice => { try!(word(&mut self.s, "&")); @@ -1686,7 +1686,7 @@ impl<'a> State<'a> { try!(self.pclose()); } ast::PatUniq(inner) => { - try!(word(&mut self.s, "~")); + try!(word(&mut self.s, "box ")); try!(self.print_pat(inner)); } ast::PatRegion(inner) => { diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 9e3be403065ae..416c924310627 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -114,7 +114,7 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str { pub struct Terminal { num_colors: u16, out: T, - ti: ~TermInfo + ti: Box, } impl Terminal { diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index db5dd2d5c1907..2b50a20ac6ae1 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -159,8 +159,8 @@ pub static stringnames: &'static[&'static str] = &'static[ "cbt", "_", "cr", "cs "box1"]; /// Parse a compiled terminfo entry, using long capability names if `longnames` is true -pub fn parse(file: &mut io::Reader, - longnames: bool) -> Result<~TermInfo, ~str> { +pub fn parse(file: &mut io::Reader, longnames: bool) + -> Result, ~str> { macro_rules! try( ($e:expr) => ( match $e { Ok(e) => e, Err(e) => return Err(format!("{}", e)) } ) ) @@ -301,7 +301,7 @@ pub fn parse(file: &mut io::Reader, } /// Create a dummy TermInfo struct for msys terminals -pub fn msys_terminfo() -> ~TermInfo { +pub fn msys_terminfo() -> Box { let mut strings = HashMap::new(); strings.insert("sgr0".to_owned(), Vec::from_slice(bytes!("\x1b[0m"))); strings.insert("bold".to_owned(), Vec::from_slice(bytes!("\x1b[1m"))); diff --git a/src/libterm/terminfo/searcher.rs b/src/libterm/terminfo/searcher.rs index a491f7e863e96..a4be7ed51fbaf 100644 --- a/src/libterm/terminfo/searcher.rs +++ b/src/libterm/terminfo/searcher.rs @@ -17,7 +17,7 @@ use std::os::getenv; use std::{os, str}; /// Return path to database entry for `term` -pub fn get_dbpath_for_term(term: &str) -> Option<~Path> { +pub fn get_dbpath_for_term(term: &str) -> Option> { if term.len() == 0 { return None; } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index fa55444fe5b27..4040e079224fd 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -132,7 +132,7 @@ pub enum TestFn { StaticMetricFn(proc(&mut MetricMap)), DynTestFn(proc():Send), DynMetricFn(proc(&mut MetricMap)), - DynBenchFn(~TDynBenchFn) + DynBenchFn(Box) } impl TestFn { @@ -1001,8 +1001,8 @@ pub fn run_test(opts: &TestOpts, if nocapture { drop((stdout, stderr)); } else { - task.opts.stdout = Some(box stdout as ~Writer:Send); - task.opts.stderr = Some(box stderr as ~Writer:Send); + task.opts.stdout = Some(box stdout as Box); + task.opts.stderr = Some(box stderr as Box); } let result_future = task.future_result(); task.spawn(testfn); diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index 2ee096dad4256..a6afd73c0935f 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -783,7 +783,7 @@ mod test { #[test] fn test_rand_rand() { let mut rng = rand::task_rng(); - let u: ~Uuid = rand::Rand::rand(&mut rng); + let u: Box = rand::Rand::rand(&mut rng); let ub = u.as_bytes(); assert!(ub.len() == 16); diff --git a/src/test/auxiliary/issue-2380.rs b/src/test/auxiliary/issue-2380.rs index a34ec980bda22..c617c1b2d03b4 100644 --- a/src/test/auxiliary/issue-2380.rs +++ b/src/test/auxiliary/issue-2380.rs @@ -11,10 +11,11 @@ #![crate_id="a"] #![crate_type = "lib"] + pub trait i { } -pub fn f() -> ~i { +pub fn f() -> Box> { impl i for () { } - ~() as ~i + box() () as Box> } diff --git a/src/test/auxiliary/issue13507.rs b/src/test/auxiliary/issue13507.rs index be066187be52b..2b4df978cc8c5 100644 --- a/src/test/auxiliary/issue13507.rs +++ b/src/test/auxiliary/issue13507.rs @@ -59,7 +59,7 @@ pub mod testtypes { // Skipping ty_box // Tests ty_uniq (of u8) - pub type FooUniq = ~u8; + pub type FooUniq = Box; // As with ty_str, what type should be used for ty_vec? diff --git a/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs b/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs index 4e933be509256..a2c7e3533d8a7 100644 --- a/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs +++ b/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs @@ -29,7 +29,7 @@ impl Drop for Foo { #[macro_registrar] pub fn registrar(_: |Name, SyntaxExtension|) { - local_data_key!(foo: ~Any:Send); - local_data::set(foo, ~Foo { foo: 10 } as ~Any:Send); + local_data_key!(foo: Box); + local_data::set(foo, box Foo { foo: 10 } as Box); } diff --git a/src/test/auxiliary/macro_crate_test.rs b/src/test/auxiliary/macro_crate_test.rs index 070bb6dfcb793..95f2a8c1ca152 100644 --- a/src/test/auxiliary/macro_crate_test.rs +++ b/src/test/auxiliary/macro_crate_test.rs @@ -27,7 +27,7 @@ macro_rules! unexported_macro (() => (3)) #[macro_registrar] pub fn macro_registrar(register: |Name, SyntaxExtension|) { register(token::intern("make_a_1"), - NormalTT(~BasicMacroExpander { + NormalTT(box BasicMacroExpander { expander: expand_make_a_1, span: None, }, @@ -35,7 +35,8 @@ pub fn macro_registrar(register: |Name, SyntaxExtension|) { register(token::intern("into_foo"), ItemModifier(expand_into_foo)); } -fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> ~MacResult { +fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) + -> Box { if !tts.is_empty() { cx.span_fatal(sp, "make_a_1 takes no arguments"); } diff --git a/src/test/auxiliary/syntax-extension-with-dll-deps-2.rs b/src/test/auxiliary/syntax-extension-with-dll-deps-2.rs index 8156e7f0e348d..93b56a7600d09 100644 --- a/src/test/auxiliary/syntax-extension-with-dll-deps-2.rs +++ b/src/test/auxiliary/syntax-extension-with-dll-deps-2.rs @@ -25,14 +25,15 @@ use syntax::parse::token; #[macro_registrar] pub fn macro_registrar(register: |Name, SyntaxExtension|) { register(token::intern("foo"), - NormalTT(~BasicMacroExpander { + NormalTT(box BasicMacroExpander { expander: expand_foo, span: None, }, None)); } -fn expand_foo(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> ~MacResult { +fn expand_foo(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) + -> Box { let answer = other::the_answer(); MacExpr::new(quote_expr!(cx, $answer)) } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index dd6e504f1dec9..659270b555427 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -147,9 +147,9 @@ fn main() { let rdr = if os::getenv("RUST_BENCH").is_some() { let foo = include_bin!("shootout-k-nucleotide.data"); - ~MemReader::new(Vec::from_slice(foo)) as ~Reader + box MemReader::new(Vec::from_slice(foo)) as Box } else { - ~stdio::stdin() as ~Reader + box stdio::stdin() as Box }; let mut rdr = BufferedReader::new(rdr); diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 865b3a0372671..dfa287459f33c 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -91,16 +91,16 @@ impl TableCallback for PrintCallback { struct Entry { code: Code, count: uint, - next: Option<~Entry>, + next: Option>, } struct Table { count: uint, - items: Vec> } + items: Vec>> } struct Items<'a> { cur: Option<&'a Entry>, - items: slice::Items<'a, Option<~Entry>>, + items: slice::Items<'a, Option>>, } impl Table { @@ -114,7 +114,7 @@ impl Table { fn search_remainder(item: &mut Entry, key: Code, c: C) { match item.next { None => { - let mut entry = ~Entry { + let mut entry = box Entry { code: key, count: 0, next: None, @@ -138,7 +138,7 @@ impl Table { { if self.items.get(index as uint).is_none() { - let mut entry = ~Entry { + let mut entry = box Entry { code: key, count: 0, next: None, diff --git a/src/test/bench/shootout-regex-dna.rs b/src/test/bench/shootout-regex-dna.rs index 0f86b8043a02d..f5409688bc6c4 100644 --- a/src/test/bench/shootout-regex-dna.rs +++ b/src/test/bench/shootout-regex-dna.rs @@ -34,9 +34,9 @@ fn count_matches(seq: &str, variant: &Regex) -> int { fn main() { let mut rdr = if std::os::getenv("RUST_BENCH").is_some() { let fd = io::File::open(&Path::new("shootout-k-nucleotide.data")); - ~io::BufferedReader::new(fd) as ~io::Reader + box io::BufferedReader::new(fd) as Box } else { - ~io::stdin() as ~io::Reader + box io::stdin() as Box }; let mut seq = StrBuf::from_str(rdr.read_to_str().unwrap()); let ilen = seq.len(); diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 3398cd84acdc8..bd47734c3da89 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -15,8 +15,8 @@ use std::io; use std::io::stdio::StdReader; use std::io::BufferedReader; -use std::os; use std::num::Bitwise; +use std::os; // Computes a single solution to a given 9x9 sudoku // @@ -132,7 +132,7 @@ impl Sudoku { fn next_color(&mut self, row: u8, col: u8, start_color: u8) -> bool { if start_color < 10u8 { // colors not yet used - let mut avail = ~Colors::new(start_color); + let mut avail = box Colors::new(start_color); // drop colors already in use in neighbourhood self.drop_colors(avail, row, col); diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 813a75cfb4d32..fc47269ef876e 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -24,7 +24,7 @@ enum List { } enum UniqueList { - ULNil, ULCons(~UniqueList) + ULNil, ULCons(Box) } fn main() { @@ -53,8 +53,8 @@ type nillist = List<()>; struct State { managed: @nillist, - unique: ~nillist, - tuple: (@nillist, ~nillist), + unique: Box, + tuple: (@nillist, Box), vec: Vec<@nillist>, res: r } @@ -85,8 +85,8 @@ fn recurse_or_fail(depth: int, st: Option) { None => { State { managed: @Nil, - unique: ~Nil, - tuple: (@Nil, ~Nil), + unique: box Nil, + tuple: (@Nil, box Nil), vec: vec!(@Nil), res: r(@Nil) } @@ -94,9 +94,9 @@ fn recurse_or_fail(depth: int, st: Option) { Some(st) => { State { managed: @Cons((), st.managed), - unique: ~Cons((), @*st.unique), + unique: box Cons((), @*st.unique), tuple: (@Cons((), st.tuple.ref0().clone()), - ~Cons((), @*st.tuple.ref1().clone())), + box Cons((), @*st.tuple.ref1().clone())), vec: st.vec.clone().append(&[@Cons((), *st.vec.last().unwrap())]), res: r(@Cons((), st.res._l)) } diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs index c142876c5c2c5..fd96b750fc16c 100644 --- a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs +++ b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs @@ -11,8 +11,9 @@ // Test that we detect nested calls that could free pointers evaluated // for earlier arguments. -fn rewrite(v: &mut ~uint) -> uint { - *v = ~22; + +fn rewrite(v: &mut Box) -> uint { + *v = box 22; **v } @@ -21,7 +22,7 @@ fn add(v: &uint, w: uint) -> uint { } fn implicit() { - let mut a = ~1; + let mut a = box 1; // Note the danger here: // @@ -34,7 +35,7 @@ fn implicit() { } fn explicit() { - let mut a = ~1; + let mut a = box 1; add( &*a, rewrite(&mut a)); //~ ERROR cannot borrow diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs index 622d2e78ee794..d1ab70e4aedcc 100644 --- a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs +++ b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs @@ -11,17 +11,18 @@ // Test that we detect nested calls that could free pointers evaluated // for earlier arguments. -fn rewrite(v: &mut ~uint) -> uint { - *v = ~22; + +fn rewrite(v: &mut Box) -> uint { + *v = box 22; **v } -fn add(v: &uint, w: ~uint) -> uint { +fn add(v: &uint, w: Box) -> uint { *v + *w } fn implicit() { - let mut a = ~1; + let mut a = box 1; // Note the danger here: // @@ -34,7 +35,7 @@ fn implicit() { } fn explicit() { - let mut a = ~1; + let mut a = box 1; add( &*a, a); //~ ERROR cannot move diff --git a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs index 1051c5829ec38..c7695e0ff5fd8 100644 --- a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs +++ b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Foo { bar1: Bar, bar2: Bar @@ -18,7 +19,7 @@ struct Bar { int2: int, } -fn make_foo() -> ~Foo { fail!() } +fn make_foo() -> Box { fail!() } fn borrow_same_field_twice_mut_mut() { let mut foo = make_foo(); diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs index e43ac98aa9802..1e04a3568c350 100644 --- a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs +++ b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs @@ -78,7 +78,7 @@ fn deref_extend_mut_field2<'a>(x: &'a mut Own) -> &'a mut int { } fn deref_extend_mut_field3<'a>(x: &'a mut Own) { - // Hmm, this is unfortunate, because with ~ it would work, + // Hmm, this is unfortunate, because with box it would work, // but it's presently the expected outcome. See `deref_extend_mut_field4` // for the workaround. diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs index 20411723715ff..120223bbf60a9 100644 --- a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs @@ -15,9 +15,9 @@ use collections::HashMap; fn main() { let mut buggy_map: HashMap = HashMap::new(); - buggy_map.insert(42, &*~1); //~ ERROR borrowed value does not live long enough + buggy_map.insert(42, &*box 1); //~ ERROR borrowed value does not live long enough // but it is ok if we use a temporary - let tmp = ~2; + let tmp = box 2; buggy_map.insert(43, &*tmp); } diff --git a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs index 006f475b29d4e..ce8b17ea40bc6 100644 --- a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs +++ b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs @@ -11,6 +11,7 @@ // Tests that two closures cannot simultaneously have mutable // and immutable access to the variable. Issue #6801. + fn get(x: &int) -> int { *x } @@ -50,27 +51,27 @@ fn e() { } fn f() { - let mut x = ~3; + let mut x = box 3; let c1 = || get(&*x); *x = 5; //~ ERROR cannot assign } fn g() { struct Foo { - f: ~int + f: Box } - let mut x = ~Foo { f: ~3 }; + let mut x = box Foo { f: box 3 }; let c1 = || get(&*x.f); *x.f = 5; //~ ERROR cannot assign to `*x.f` } fn h() { struct Foo { - f: ~int + f: Box } - let mut x = ~Foo { f: ~3 }; + let mut x = box Foo { f: box 3 }; let c1 = || get(&*x.f); let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable } diff --git a/src/test/compile-fail/borrowck-closures-two-mut.rs b/src/test/compile-fail/borrowck-closures-two-mut.rs index 570249aed443b..e1967d4e6df94 100644 --- a/src/test/compile-fail/borrowck-closures-two-mut.rs +++ b/src/test/compile-fail/borrowck-closures-two-mut.rs @@ -12,6 +12,7 @@ // access to the variable, whether that mutable access be used // for direct assignment or for taking mutable ref. Issue #6801. + fn a() { let mut x = 3; let c1 = || x = 4; @@ -43,10 +44,10 @@ fn d() { fn g() { struct Foo { - f: ~int + f: Box } - let mut x = ~Foo { f: ~3 }; + let mut x = box Foo { f: box 3 }; let c1 = || set(&mut *x.f); let c2 = || set(&mut *x.f); //~^ ERROR cannot borrow `x` as mutable more than once diff --git a/src/test/compile-fail/borrowck-closures-use-after-free.rs b/src/test/compile-fail/borrowck-closures-use-after-free.rs index 38c13b1fce94f..ec31160f0d535 100644 --- a/src/test/compile-fail/borrowck-closures-use-after-free.rs +++ b/src/test/compile-fail/borrowck-closures-use-after-free.rs @@ -12,6 +12,7 @@ // cannot also be supplied a borrowed version of that // variable's contents. Issue #11192. + struct Foo { x: int } @@ -23,9 +24,9 @@ impl Drop for Foo { } fn main() { - let mut ptr = ~Foo { x: 0 }; + let mut ptr = box Foo { x: 0 }; let test = |foo: &Foo| { - ptr = ~Foo { x: ptr.x + 1 }; + ptr = box Foo { x: ptr.x + 1 }; }; test(ptr); //~ ERROR cannot borrow `*ptr` } diff --git a/src/test/compile-fail/borrowck-issue-2657-1.rs b/src/test/compile-fail/borrowck-issue-2657-1.rs index 8bcd5f9a72e70..9313473d6c916 100644 --- a/src/test/compile-fail/borrowck-issue-2657-1.rs +++ b/src/test/compile-fail/borrowck-issue-2657-1.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { -let x = Some(~1); +let x = Some(box 1); match x { Some(ref _y) => { let _a = x; //~ ERROR cannot move diff --git a/src/test/compile-fail/borrowck-issue-2657-2.rs b/src/test/compile-fail/borrowck-issue-2657-2.rs index fac805c57ca09..39c3ae8fdfde0 100644 --- a/src/test/compile-fail/borrowck-issue-2657-2.rs +++ b/src/test/compile-fail/borrowck-issue-2657-2.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { -let x = Some(~1); +let x = Some(box 1); match x { Some(ref y) => { let _b = *y; //~ ERROR cannot move out diff --git a/src/test/compile-fail/borrowck-lend-flow-if.rs b/src/test/compile-fail/borrowck-lend-flow-if.rs index 80b8770397fb2..b1ba057dc147a 100644 --- a/src/test/compile-fail/borrowck-lend-flow-if.rs +++ b/src/test/compile-fail/borrowck-lend-flow-if.rs @@ -14,21 +14,22 @@ // either genuine or would require more advanced changes. The latter // cases are noted. + fn borrow(_v: &int) {} fn borrow_mut(_v: &mut int) {} fn cond() -> bool { fail!() } fn for_func(_f: || -> bool) { fail!() } fn produce() -> T { fail!(); } -fn inc(v: &mut ~int) { - *v = ~(**v + 1); +fn inc(v: &mut Box) { + *v = box() (**v + 1); } fn pre_freeze_cond() { // In this instance, the freeze is conditional and starts before // the mut borrow. - let mut v = ~3; + let mut v = box 3; let _w; if cond() { _w = &v; @@ -40,7 +41,7 @@ fn pre_freeze_else() { // In this instance, the freeze and mut borrow are on separate sides // of the if. - let mut v = ~3; + let mut v = box 3; let _w; if cond() { _w = &v; diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 4f0c71457b2c5..831c4d3e824f5 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -14,19 +14,20 @@ // either genuine or would require more advanced changes. The latter // cases are noted. + fn borrow(_v: &int) {} fn borrow_mut(_v: &mut int) {} fn cond() -> bool { fail!() } fn produce() -> T { fail!(); } -fn inc(v: &mut ~int) { - *v = ~(**v + 1); +fn inc(v: &mut Box) { + *v = box() (**v + 1); } fn loop_overarching_alias_mut() { // In this instance, the borrow encompasses the entire loop. - let mut v = ~3; + let mut v = box 3; let mut x = &mut v; **x += 1; loop { @@ -37,19 +38,19 @@ fn loop_overarching_alias_mut() { fn block_overarching_alias_mut() { // In this instance, the borrow encompasses the entire closure call. - let mut v = ~3; + let mut v = box 3; let mut x = &mut v; for _ in range(0, 3) { borrow(v); //~ ERROR cannot borrow } - *x = ~5; + *x = box 5; } fn loop_aliased_mut() { // In this instance, the borrow is carried through the loop. - let mut v = ~3; - let mut w = ~4; + let mut v = box 3; + let mut w = box 4; let mut _x = &w; loop { borrow_mut(v); //~ ERROR cannot borrow @@ -60,8 +61,8 @@ fn loop_aliased_mut() { fn while_aliased_mut() { // In this instance, the borrow is carried through the loop. - let mut v = ~3; - let mut w = ~4; + let mut v = box 3; + let mut w = box 4; let mut _x = &w; while cond() { borrow_mut(v); //~ ERROR cannot borrow @@ -73,8 +74,8 @@ fn while_aliased_mut() { fn loop_aliased_mut_break() { // In this instance, the borrow is carried through the loop. - let mut v = ~3; - let mut w = ~4; + let mut v = box 3; + let mut w = box 4; let mut _x = &w; loop { borrow_mut(v); @@ -87,8 +88,8 @@ fn loop_aliased_mut_break() { fn while_aliased_mut_break() { // In this instance, the borrow is carried through the loop. - let mut v = ~3; - let mut w = ~4; + let mut v = box 3; + let mut w = box 4; let mut _x = &w; while cond() { borrow_mut(v); @@ -99,8 +100,8 @@ fn while_aliased_mut_break() { } fn while_aliased_mut_cond(cond: bool, cond2: bool) { - let mut v = ~3; - let mut w = ~4; + let mut v = box 3; + let mut w = box 4; let mut x = &mut w; while cond { **x += 1; diff --git a/src/test/compile-fail/borrowck-lend-flow-match.rs b/src/test/compile-fail/borrowck-lend-flow-match.rs index 9d234e0aaa632..ea0f5d34b72e5 100644 --- a/src/test/compile-fail/borrowck-lend-flow-match.rs +++ b/src/test/compile-fail/borrowck-lend-flow-match.rs @@ -37,24 +37,24 @@ fn guard() { // Here the guard performs a borrow. This borrow "infects" all // subsequent arms (but not the prior ones). - let mut a = ~3; - let mut b = ~4; + let mut a = box 3; + let mut b = box 4; let mut w = &*a; match 22 { _ if cond() => { - b = ~5; + b = box 5; } _ if link(&*b, &mut w) => { - b = ~6; //~ ERROR cannot assign + b = box 6; //~ ERROR cannot assign } _ => { - b = ~7; //~ ERROR cannot assign + b = box 7; //~ ERROR cannot assign } } - b = ~8; //~ ERROR cannot assign + b = box 8; //~ ERROR cannot assign } fn main() {} diff --git a/src/test/compile-fail/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck-lend-flow.rs index 5e4e5bb1e73f1..54f326b479af8 100644 --- a/src/test/compile-fail/borrowck-lend-flow.rs +++ b/src/test/compile-fail/borrowck-lend-flow.rs @@ -14,20 +14,21 @@ // either genuine or would require more advanced changes. The latter // cases are noted. + fn borrow(_v: &int) {} fn borrow_mut(_v: &mut int) {} fn cond() -> bool { fail!() } fn for_func(_f: || -> bool) { fail!() } fn produce() -> T { fail!(); } -fn inc(v: &mut ~int) { - *v = ~(**v + 1); +fn inc(v: &mut Box) { + *v = box() (**v + 1); } fn pre_freeze() { // In this instance, the freeze starts before the mut borrow. - let mut v = ~3; + let mut v = box 3; let _w = &v; borrow_mut(v); //~ ERROR cannot borrow } @@ -35,7 +36,7 @@ fn pre_freeze() { fn post_freeze() { // In this instance, the const alias starts after the borrow. - let mut v = ~3; + let mut v = box 3; borrow_mut(v); let _w = &v; } diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 0fa2ee5be17b7..d262bcee98317 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -15,7 +15,7 @@ fn borrow(v: &int, f: |x: &int|) { } fn box_imm() { - let v = ~3; + let v = box 3; let _w = &v; task::spawn(proc() { println!("v={}", *v); @@ -24,7 +24,7 @@ fn box_imm() { } fn box_imm_explicit() { - let v = ~3; + let v = box 3; let _w = &v; task::spawn(proc() { println!("v={}", *v); diff --git a/src/test/compile-fail/borrowck-loan-blocks-move.rs b/src/test/compile-fail/borrowck-loan-blocks-move.rs index b9a79f4f3b1b1..3c284ede0c89c 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn take(_v: ~int) { + +fn take(_v: Box) { } fn box_imm() { - let v = ~3; + let v = box 3; let _w = &v; take(v); //~ ERROR cannot move out of `v` because it is borrowed } diff --git a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs index 6a0d3ef82fb21..c11a08b254f1c 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs @@ -13,10 +13,10 @@ fn borrow(v: &int, f: |x: &int|) { } fn box_imm() { - let mut v = ~3; + let mut v = box 3; borrow(v, |w| { //~ ERROR cannot borrow `v` as mutable - v = ~4; + v = box 4; assert_eq!(*v, 3); assert_eq!(*w, 4); }) diff --git a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs index 962b70685460a..4a6c20079c17e 100644 --- a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs @@ -8,18 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct foo(~uint); + +struct foo(Box); impl Add for foo { fn add(&self, f: &foo) -> foo { - let foo(~i) = *self; - let foo(~j) = *f; - foo(~(i + j)) + let foo(box i) = *self; + let foo(box j) = *f; + foo(box() (i + j)) } } fn main() { - let x = foo(~3); + let x = foo(box 3); let _y = x + {x}; // the `{x}` forces a move to occur //~^ ERROR cannot move out of `x` } diff --git a/src/test/compile-fail/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck-move-by-capture.rs index f3869e5c9fdba..c52924ebdb789 100644 --- a/src/test/compile-fail/borrowck-move-by-capture.rs +++ b/src/test/compile-fail/borrowck-move-by-capture.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let bar = ~3; + let bar = box 3; let _g = || { let _h: proc() -> int = proc() *bar; //~ ERROR cannot move out of captured outer variable }; diff --git a/src/test/compile-fail/borrowck-move-error-with-note.rs b/src/test/compile-fail/borrowck-move-error-with-note.rs index 087e619f21399..72101d86960c2 100644 --- a/src/test/compile-fail/borrowck-move-error-with-note.rs +++ b/src/test/compile-fail/borrowck-move-error-with-note.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + enum Foo { - Foo1(~u32, ~u32), - Foo2(~u32), + Foo1(Box, Box), + Foo2(Box), Foo3, } fn blah() { - let f = &Foo1(~1u32, ~2u32); + let f = &Foo1(box 1u32, box 2u32); match *f { //~ ERROR cannot move out of Foo1(num1, //~ NOTE attempting to move value to here num2) => (), //~ NOTE and here @@ -24,7 +25,10 @@ fn blah() { } } -struct S {f:~str, g:~str} +struct S { + f: ~str, + g: ~str +} impl Drop for S { fn drop(&mut self) { println!("{}", self.f); } } @@ -40,13 +44,13 @@ fn move_in_match() { // from issue-8064 struct A { - a: ~int + a: Box, } fn free(_: T) {} fn blah2() { - let a = &A { a: ~1 }; + let a = &A { a: box 1 }; match a.a { //~ ERROR cannot move out of n => { //~ NOTE attempting to move value to here free(n) diff --git a/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs b/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs index 6106644a26310..35106487f3475 100644 --- a/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs +++ b/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs @@ -12,7 +12,7 @@ // borrowed path. fn main() { - let a = ~~2; + let a = box box 2; let b = &a; let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed diff --git a/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs b/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs index 8f332646bbccd..c507b636f15cf 100644 --- a/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs +++ b/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: *~int) -> ~int { + +fn foo(x: *Box) -> Box { let y = *x; //~ ERROR dereference of unsafe pointer requires unsafe function or block return y; } diff --git a/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs b/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs index 53b5d866b81d9..b385305d74aaa 100644 --- a/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs +++ b/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs @@ -13,7 +13,7 @@ fn call_f(f: proc() -> int) -> int { } fn main() { - let t = ~3; + let t = box 3; call_f(proc() { *t + 1 }); call_f(proc() { *t + 1 }); //~ ERROR capture of moved value diff --git a/src/test/compile-fail/borrowck-move-subcomponent.rs b/src/test/compile-fail/borrowck-move-subcomponent.rs index 6940c85e0e63d..a29a171e935dd 100644 --- a/src/test/compile-fail/borrowck-move-subcomponent.rs +++ b/src/test/compile-fail/borrowck-move-subcomponent.rs @@ -11,19 +11,15 @@ // Tests that the borrow checker checks all components of a path when moving // out. -#![no_std] - -#[lang="sized"] -pub trait Sized {} struct S { - x : ~int + x : Box } fn f(_: T) {} fn main() { - let a : S = S { x : ~1 }; + let a : S = S { x : box 1 }; let pb = &a; let S { x: ax } = a; //~ ERROR cannot move out f(pb); diff --git a/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs b/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs index ed270de51e2ed..ad90839b4bc43 100644 --- a/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs +++ b/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct node_ { - a: ~cycle + a: Box } enum cycle { @@ -17,7 +18,7 @@ enum cycle { empty } fn main() { - let mut x = ~node(node_ {a: ~empty}); + let mut x = box node(node_ {a: box empty}); // Create a cycle! match *x { node(ref mut y) => { diff --git a/src/test/compile-fail/borrowck-object-lifetime.rs b/src/test/compile-fail/borrowck-object-lifetime.rs index 92b77d8243efc..9466a78588c45 100644 --- a/src/test/compile-fail/borrowck-object-lifetime.rs +++ b/src/test/compile-fail/borrowck-object-lifetime.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { fn borrowed<'a>(&'a self) -> &'a (); } @@ -16,16 +17,16 @@ fn borrowed_receiver<'a>(x: &'a Foo) -> &'a () { x.borrowed() } -fn owned_receiver(x: ~Foo) -> &() { +fn owned_receiver(x: Box) -> &() { x.borrowed() //~ ERROR `*x` does not live long enough } -fn mut_owned_receiver(mut x: ~Foo) { +fn mut_owned_receiver(mut x: Box) { let _y = x.borrowed(); let _z = &mut x; //~ ERROR cannot borrow } -fn imm_owned_receiver(mut x: ~Foo) { +fn imm_owned_receiver(mut x: Box) { let _y = x.borrowed(); let _z = &x; } diff --git a/src/test/compile-fail/borrowck-object-mutability.rs b/src/test/compile-fail/borrowck-object-mutability.rs index d4203dc9916ab..9b5087bd7e0b7 100644 --- a/src/test/compile-fail/borrowck-object-mutability.rs +++ b/src/test/compile-fail/borrowck-object-mutability.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { fn borrowed(&self); fn borrowed_mut(&mut self); @@ -23,12 +24,12 @@ fn borrowed_mut_receiver(x: &mut Foo) { x.borrowed_mut(); } -fn owned_receiver(x: ~Foo) { +fn owned_receiver(x: Box) { x.borrowed(); x.borrowed_mut(); //~ ERROR cannot borrow } -fn mut_owned_receiver(mut x: ~Foo) { +fn mut_owned_receiver(mut x: Box) { x.borrowed(); x.borrowed_mut(); } diff --git a/src/test/compile-fail/borrowck-preserve-box-in-field.rs b/src/test/compile-fail/borrowck-preserve-box-in-field.rs index ff138451e93f2..168a331e9fe29 100644 --- a/src/test/compile-fail/borrowck-preserve-box-in-field.rs +++ b/src/test/compile-fail/borrowck-preserve-box-in-field.rs @@ -14,6 +14,7 @@ #![feature(managed_boxes)] + fn borrow(x: &int, f: |x: &int|) { let before = *x; f(x); @@ -21,16 +22,16 @@ fn borrow(x: &int, f: |x: &int|) { assert_eq!(before, after); } -struct F { f: ~int } +struct F { f: Box } pub fn main() { - let mut x = @F {f: ~3}; + let mut x = @F {f: box 3}; borrow(x.f, |b_x| { //~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable assert_eq!(*b_x, 3); assert_eq!(&(*x.f) as *int, &(*b_x) as *int); //~^ NOTE borrow occurs due to use of `x` in closure - x = @F {f: ~4}; + x = @F {f: box 4}; println!("&*b_x = {:p}", &(*b_x)); assert_eq!(*b_x, 3); diff --git a/src/test/compile-fail/borrowck-preserve-box-in-uniq.rs b/src/test/compile-fail/borrowck-preserve-box-in-uniq.rs index b06eb0d6ba23a..d79b7e040c769 100644 --- a/src/test/compile-fail/borrowck-preserve-box-in-uniq.rs +++ b/src/test/compile-fail/borrowck-preserve-box-in-uniq.rs @@ -14,6 +14,7 @@ #![feature(managed_boxes)] + fn borrow(x: &int, f: |x: &int|) { let before = *x; f(x); @@ -21,16 +22,16 @@ fn borrow(x: &int, f: |x: &int|) { assert_eq!(before, after); } -struct F { f: ~int } +struct F { f: Box } pub fn main() { - let mut x = ~@F{f: ~3}; + let mut x = box @F{f: box 3}; borrow(x.f, |b_x| { //~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable assert_eq!(*b_x, 3); assert_eq!(&(*x.f) as *int, &(*b_x) as *int); //~^ NOTE borrow occurs due to use of `x` in closure - *x = @F{f: ~4}; + *x = @F{f: box 4}; println!("&*b_x = {:p}", &(*b_x)); assert_eq!(*b_x, 3); diff --git a/src/test/compile-fail/borrowck-preserve-expl-deref.rs b/src/test/compile-fail/borrowck-preserve-expl-deref.rs index aeabf6d9f8b55..9b7966b0af05b 100644 --- a/src/test/compile-fail/borrowck-preserve-expl-deref.rs +++ b/src/test/compile-fail/borrowck-preserve-expl-deref.rs @@ -14,6 +14,7 @@ #![feature(managed_boxes)] + fn borrow(x: &int, f: |x: &int|) { let before = *x; f(x); @@ -21,16 +22,16 @@ fn borrow(x: &int, f: |x: &int|) { assert_eq!(before, after); } -struct F { f: ~int } +struct F { f: Box } pub fn main() { - let mut x = @F {f: ~3}; + let mut x = @F {f: box 3}; borrow((*x).f, |b_x| { //~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable assert_eq!(*b_x, 3); assert_eq!(&(*x.f) as *int, &(*b_x) as *int); //~^ NOTE borrow occurs due to use of `x` in closure - x = @F {f: ~4}; + x = @F {f: box 4}; println!("&*b_x = {:p}", &(*b_x)); assert_eq!(*b_x, 3); diff --git a/src/test/compile-fail/borrowck-struct-update-with-dtor.rs b/src/test/compile-fail/borrowck-struct-update-with-dtor.rs index 651104d1eda44..b5d274a5584ab 100644 --- a/src/test/compile-fail/borrowck-struct-update-with-dtor.rs +++ b/src/test/compile-fail/borrowck-struct-update-with-dtor.rs @@ -13,10 +13,12 @@ // NoCopy use NP = std::kinds::marker::NoCopy; + + struct S { a: int, np: NP } impl Drop for S { fn drop(&mut self) { } } -struct T { a: int, mv: ~int } +struct T { a: int, mv: Box } impl Drop for T { fn drop(&mut self) { } } fn f(s0:S) { diff --git a/src/test/compile-fail/borrowck-unary-move.rs b/src/test/compile-fail/borrowck-unary-move.rs index a67a12f9d0f73..72941f7721044 100644 --- a/src/test/compile-fail/borrowck-unary-move.rs +++ b/src/test/compile-fail/borrowck-unary-move.rs @@ -8,13 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: ~int) -> int { + +fn foo(x: Box) -> int { let y = &*x; free(x); //~ ERROR cannot move out of `x` because it is borrowed *y } -fn free(_x: ~int) { +fn free(_x: Box) { } fn main() { diff --git a/src/test/compile-fail/borrowck-uniq-via-lend.rs b/src/test/compile-fail/borrowck-uniq-via-lend.rs index c87428cd300a7..fb03ad61f3d1e 100644 --- a/src/test/compile-fail/borrowck-uniq-via-lend.rs +++ b/src/test/compile-fail/borrowck-uniq-via-lend.rs @@ -8,49 +8,50 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + fn borrow(_v: &int) {} fn local() { - let mut v = ~3; + let mut v = box 3; borrow(v); } fn local_rec() { - struct F { f: ~int } - let mut v = F {f: ~3}; + struct F { f: Box } + let mut v = F {f: box 3}; borrow(v.f); } fn local_recs() { struct F { f: G } struct G { g: H } - struct H { h: ~int } - let mut v = F {f: G {g: H {h: ~3}}}; + struct H { h: Box } + let mut v = F {f: G {g: H {h: box 3}}}; borrow(v.f.g.h); } fn aliased_imm() { - let mut v = ~3; + let mut v = box 3; let _w = &v; borrow(v); } fn aliased_mut() { - let mut v = ~3; + let mut v = box 3; let _w = &mut v; borrow(v); //~ ERROR cannot borrow `*v` } fn aliased_other() { - let mut v = ~3; - let mut w = ~4; + let mut v = box 3; + let mut w = box 4; let _x = &mut w; borrow(v); } fn aliased_other_reassign() { - let mut v = ~3; - let mut w = ~4; + let mut v = box 3; + let mut w = box 4; let mut _x = &mut w; _x = &mut v; borrow(v); //~ ERROR cannot borrow `*v` diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs index 7f0a6c84f8cad..f41f74b166fd2 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs @@ -8,28 +8,29 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + fn a() { - let mut vec = [~1, ~2, ~3]; + let mut vec = [box 1, box 2, box 3]; match vec { - [~ref _a, _, _] => { - vec[0] = ~4; //~ ERROR cannot assign + [box ref _a, _, _] => { + vec[0] = box 4; //~ ERROR cannot assign } } } fn b() { - let mut vec = vec!(~1, ~2, ~3); - let vec: &mut [~int] = vec.as_mut_slice(); + let mut vec = vec!(box 1, box 2, box 3); + let vec: &mut [Box] = vec.as_mut_slice(); match vec { [.._b] => { - vec[0] = ~4; //~ ERROR cannot assign + vec[0] = box 4; //~ ERROR cannot assign } } } fn c() { - let mut vec = vec!(~1, ~2, ~3); - let vec: &mut [~int] = vec.as_mut_slice(); + let mut vec = vec!(box 1, box 2, box 3); + let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_a, //~ ERROR cannot move out .._b] => { //~^ NOTE attempting to move value to here @@ -46,8 +47,8 @@ fn c() { } fn d() { - let mut vec = vec!(~1, ~2, ~3); - let vec: &mut [~int] = vec.as_mut_slice(); + let mut vec = vec!(box 1, box 2, box 3); + let vec: &mut [Box] = vec.as_mut_slice(); match vec { [.._a, //~ ERROR cannot move out _b] => {} //~ NOTE attempting to move value to here @@ -57,8 +58,8 @@ fn d() { } fn e() { - let mut vec = vec!(~1, ~2, ~3); - let vec: &mut [~int] = vec.as_mut_slice(); + let mut vec = vec!(box 1, box 2, box 3); + let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_a, _b, _c] => {} //~ ERROR cannot move out //~^ NOTE attempting to move value to here diff --git a/src/test/compile-fail/check-static-values-constraints.rs b/src/test/compile-fail/check-static-values-constraints.rs index a8581534848a8..6c1e759cc2fa7 100644 --- a/src/test/compile-fail/check-static-values-constraints.rs +++ b/src/test/compile-fail/check-static-values-constraints.rs @@ -94,7 +94,7 @@ static STATIC10: UnsafeStruct = UnsafeStruct; struct MyOwned; -static STATIC11: ~MyOwned = ~MyOwned; +static STATIC11: Box = box MyOwned; //~^ ERROR static items are not allowed to have owned pointers // The following examples test that mutable structs are just forbidden @@ -109,11 +109,12 @@ static mut STATIC13: SafeStruct = SafeStruct{field1: Variant1, field2: Variant3( static mut STATIC14: SafeStruct = SafeStruct{field1: Variant1, field2: Variant4("str".to_owned())}; //~^ ERROR mutable static items are not allowed to have destructors -static STATIC15: &'static [~MyOwned] = &'static [~MyOwned, ~MyOwned]; +static STATIC15: &'static [Box] = &'static [box MyOwned, box MyOwned]; //~^ ERROR static items are not allowed to have owned pointers //~^^ ERROR static items are not allowed to have owned pointers -static STATIC16: (&'static ~MyOwned, &'static ~MyOwned) = (&'static ~MyOwned, &'static ~MyOwned); +static STATIC16: (&'static Box, &'static Box) = + (&'static box MyOwned, &'static box MyOwned); //~^ ERROR static items are not allowed to have owned pointers //~^^ ERROR static items are not allowed to have owned pointers @@ -123,10 +124,10 @@ static mut STATIC17: SafeEnum = Variant1; static STATIC18: @SafeStruct = @SafeStruct{field1: Variant1, field2: Variant2(0)}; //~^ ERROR static items are not allowed to have managed pointers -static STATIC19: ~int = box 3; +static STATIC19: Box = box 3; //~^ ERROR static items are not allowed to have owned pointers pub fn main() { - let y = { static x: ~int = ~3; x }; + let y = { static x: Box = box 3; x }; //~^ ERROR static items are not allowed to have owned pointers } diff --git a/src/test/compile-fail/class-cast-to-trait.rs b/src/test/compile-fail/class-cast-to-trait.rs index 506e1cba9fded..c4344db027bae 100644 --- a/src/test/compile-fail/class-cast-to-trait.rs +++ b/src/test/compile-fail/class-cast-to-trait.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait noisy { fn speak(&self); } @@ -57,6 +58,6 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { } fn main() { - let nyan: ~noisy = ~cat(0, 2, "nyan".to_owned()) as ~noisy; + let nyan: Box = box cat(0, 2, "nyan".to_owned()) as Box; nyan.eat(); //~ ERROR does not implement any method in scope named `eat` } diff --git a/src/test/compile-fail/estr-subtyping.rs b/src/test/compile-fail/estr-subtyping.rs index 5927ae12f1ca0..db86b5e092c52 100644 --- a/src/test/compile-fail/estr-subtyping.rs +++ b/src/test/compile-fail/estr-subtyping.rs @@ -17,7 +17,7 @@ fn has_uniq(x: ~str) { } fn has_slice(x: &str) { - wants_uniq(x); //~ ERROR mismatched types: expected `~str` but found `&str` (expected ~-ptr but f + wants_uniq(x); //~ ERROR mismatched types: expected `~str` but found `&str` (expected box but f wants_slice(x); } diff --git a/src/test/compile-fail/immut-function-arguments.rs b/src/test/compile-fail/immut-function-arguments.rs index 663a50e9e553e..71328acdd7017 100644 --- a/src/test/compile-fail/immut-function-arguments.rs +++ b/src/test/compile-fail/immut-function-arguments.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(y: ~int) { + +fn f(y: Box) { *y = 5; //~ ERROR cannot assign } fn g() { - let _frob: |~int| = |q| { *q = 2; }; //~ ERROR cannot assign + let _frob: |Box| = |q| { *q = 2; }; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/infinite-autoderef.rs b/src/test/compile-fail/infinite-autoderef.rs index ddef459453ec4..b41797d0042fa 100644 --- a/src/test/compile-fail/infinite-autoderef.rs +++ b/src/test/compile-fail/infinite-autoderef.rs @@ -23,7 +23,7 @@ impl Deref for Foo { pub fn main() { let mut x; loop { - x = ~x; + x = box x; x.foo; x.bar(); } diff --git a/src/test/compile-fail/inherit-struct1.rs b/src/test/compile-fail/inherit-struct1.rs index 00ea4b7783b9c..47f2b29118702 100644 --- a/src/test/compile-fail/inherit-struct1.rs +++ b/src/test/compile-fail/inherit-struct1.rs @@ -11,7 +11,8 @@ // Test struct inheritance. #![feature(struct_inherit)] -struct S6 : ~S2; //~ ERROR not a struct + +struct S6 : int; //~ ERROR super-struct could not be resolved pub fn main() { } diff --git a/src/test/compile-fail/issue-10398.rs b/src/test/compile-fail/issue-10398.rs index a58c88737b604..97642377ba8f4 100644 --- a/src/test/compile-fail/issue-10398.rs +++ b/src/test/compile-fail/issue-10398.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let x = ~1; + let x = box 1; let f: proc() = proc() { let _a = x; drop(x); diff --git a/src/test/compile-fail/issue-11192.rs b/src/test/compile-fail/issue-11192.rs index f1da30328905a..e7fa8300bcb69 100644 --- a/src/test/compile-fail/issue-11192.rs +++ b/src/test/compile-fail/issue-11192.rs @@ -19,10 +19,10 @@ impl Drop for Foo { } fn main() { - let mut ptr = ~Foo { x: 0 }; + let mut ptr = box Foo { x: 0 }; let test = |foo: &Foo| { println!("access {}", foo.x); - ptr = ~Foo { x: ptr.x + 1 }; + ptr = box Foo { x: ptr.x + 1 }; println!("access {}", foo.x); }; test(ptr); diff --git a/src/test/compile-fail/issue-11515.rs b/src/test/compile-fail/issue-11515.rs index 52288a9ce020a..4d520b570b725 100644 --- a/src/test/compile-fail/issue-11515.rs +++ b/src/test/compile-fail/issue-11515.rs @@ -13,6 +13,6 @@ struct Test<'s> { } fn main() { - let test = ~Test { func: proc() {} }; + let test = box Test { func: proc() {} }; //~^ ERROR: expected `||` but found `proc()` } diff --git a/src/test/compile-fail/issue-11925.rs b/src/test/compile-fail/issue-11925.rs index 0b8eaa5b831c0..a8d2c7509ce3f 100644 --- a/src/test/compile-fail/issue-11925.rs +++ b/src/test/compile-fail/issue-11925.rs @@ -10,7 +10,7 @@ fn main() { let r = { - let x = ~42; + let x = box 42; let f = proc() &x; //~ ERROR: `x` does not live long enough f() }; diff --git a/src/test/compile-fail/issue-2063.rs b/src/test/compile-fail/issue-2063.rs index b6425dac3c117..4a6219aafd081 100644 --- a/src/test/compile-fail/issue-2063.rs +++ b/src/test/compile-fail/issue-2063.rs @@ -11,7 +11,9 @@ // test that autoderef of a type like this does not // cause compiler to loop. Note that no instances // of such a type could ever be constructed. -struct t(~t); //~ ERROR this type cannot be instantiated + + +struct t(Box); //~ ERROR this type cannot be instantiated trait to_str_2 { fn my_to_str() -> ~str; diff --git a/src/test/compile-fail/issue-3601.rs b/src/test/compile-fail/issue-3601.rs index c37c5a3e5afa5..6ca4e22576ec4 100644 --- a/src/test/compile-fail/issue-3601.rs +++ b/src/test/compile-fail/issue-3601.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct HTMLImageData { image: Option<~str> } struct ElementData { - kind: ~ElementKind + kind: Box } enum ElementKind { @@ -25,17 +26,17 @@ enum NodeKind { } struct NodeData { - kind: ~NodeKind + kind: Box, } fn main() { let mut id = HTMLImageData { image: None }; - let ed = ElementData { kind: ~HTMLImageElement(id) }; - let n = NodeData {kind : ~Element(ed)}; + let ed = ElementData { kind: box HTMLImageElement(id) }; + let n = NodeData {kind : box Element(ed)}; // n.b. span could be better match n.kind { - ~Element(ed) => match ed.kind { //~ ERROR non-exhaustive patterns - ~HTMLImageElement(ref d) if d.image.is_some() => { true } + box Element(ed) => match ed.kind { //~ ERROR non-exhaustive patterns + box HTMLImageElement(ref d) if d.image.is_some() => { true } }, _ => fail!("WAT") //~ ERROR unreachable pattern }; diff --git a/src/test/compile-fail/issue-3763.rs b/src/test/compile-fail/issue-3763.rs index 8eed8aa86441a..657d9c8f17ea5 100644 --- a/src/test/compile-fail/issue-3763.rs +++ b/src/test/compile-fail/issue-3763.rs @@ -26,12 +26,12 @@ fn main() { let my_struct = my_mod::MyStruct(); let _woohoo = (&my_struct).priv_field; //~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private - let _woohoo = (~my_struct).priv_field; + let _woohoo = (box my_struct).priv_field; //~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private let _woohoo = (@my_struct).priv_field; //~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private (&my_struct).happyfun(); //~ ERROR method `happyfun` is private - (~my_struct).happyfun(); //~ ERROR method `happyfun` is private + (box my_struct).happyfun(); //~ ERROR method `happyfun` is private (@my_struct).happyfun(); //~ ERROR method `happyfun` is private let nope = my_struct.priv_field; //~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private diff --git a/src/test/compile-fail/issue-4972.rs b/src/test/compile-fail/issue-4972.rs index 8d281a0b174ac..ffac6b499f4c1 100644 --- a/src/test/compile-fail/issue-4972.rs +++ b/src/test/compile-fail/issue-4972.rs @@ -8,15 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait MyTrait { } pub enum TraitWrapper { - A(~MyTrait), + A(Box), } fn get_tw_map<'lt>(tw: &'lt TraitWrapper) -> &'lt MyTrait { match *tw { - A(~ref map) => map, //~ ERROR found a `~`-box pattern + A(box ref map) => map, //~ ERROR found a box pattern } } diff --git a/src/test/compile-fail/issue-5100.rs b/src/test/compile-fail/issue-5100.rs index b7c440d30b3ae..6734a546be5fb 100644 --- a/src/test/compile-fail/issue-5100.rs +++ b/src/test/compile-fail/issue-5100.rs @@ -23,8 +23,8 @@ fn main() { } match (true, false) { - ~(true, false) => () - //~^ ERROR mismatched types: expected `(bool,bool)` but found a `~`-box pattern + box (true, false) => () + //~^ ERROR mismatched types: expected `(bool,bool)` but found a box pattern } match (true, false) { diff --git a/src/test/compile-fail/issue-5439.rs b/src/test/compile-fail/issue-5439.rs index 03fe86cb87977..55e3459a58922 100644 --- a/src/test/compile-fail/issue-5439.rs +++ b/src/test/compile-fail/issue-5439.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Foo { foo: int, } @@ -17,8 +18,8 @@ struct Bar { } impl Bar { - fn make_foo (&self, i: int) -> ~Foo { - return ~Foo { nonexistent: self, foo: i }; //~ ERROR: no field named + fn make_foo (&self, i: int) -> Box { + return box Foo { nonexistent: self, foo: i }; //~ ERROR: no field named } } diff --git a/src/test/compile-fail/issue-6801.rs b/src/test/compile-fail/issue-6801.rs index a80d4b721924e..5925f6869391a 100644 --- a/src/test/compile-fail/issue-6801.rs +++ b/src/test/compile-fail/issue-6801.rs @@ -12,7 +12,8 @@ // transferring ownership of the owned box before invoking the stack // closure results in a crash. -fn twice(x: ~uint) -> uint { + +fn twice(x: Box) -> uint { *x * 2 } @@ -21,7 +22,7 @@ fn invoke(f: || -> uint) { } fn main() { - let x : ~uint = ~9; + let x : Box = box 9; let sq : || -> uint = || { *x * *x }; twice(x); //~ ERROR: cannot move out of diff --git a/src/test/compile-fail/issue-7013.rs b/src/test/compile-fail/issue-7013.rs index 6a7f01e67679e..1bc4e07655323 100644 --- a/src/test/compile-fail/issue-7013.rs +++ b/src/test/compile-fail/issue-7013.rs @@ -8,35 +8,30 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; -trait Foo -{ +trait Foo { fn set(&mut self, v: Rc>); } -struct B -{ +struct B { v: Option>> } -impl Foo for B -{ +impl Foo for B { fn set(&mut self, v: Rc>) { self.v = Some(v); } } -struct A -{ - v: ~Foo:Send, +struct A { + v: Box, } -fn main() -{ - let a = A {v: ~B{v: None} as ~Foo:Send}; +fn main() { + let a = A {v: box B{v: None} as Box}; //~^ ERROR cannot pack type `~B`, which does not fulfill `Send` let v = Rc::new(RefCell::new(a)); let w = v.clone(); diff --git a/src/test/compile-fail/issue-8727.rs b/src/test/compile-fail/issue-8727.rs index 9d7edefbf024b..e2790eb7b39d9 100644 --- a/src/test/compile-fail/issue-8727.rs +++ b/src/test/compile-fail/issue-8727.rs @@ -11,7 +11,8 @@ // Verify the compiler fails with an error on infinite function // recursions. -struct Data(~Option); + +struct Data(Box>); fn generic( _ : Vec<(Data,T)> ) { //~^ ERROR reached the recursion limit during monomorphization diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs index d4010346998cf..694b0f1dbe27d 100644 --- a/src/test/compile-fail/kindck-copy.rs +++ b/src/test/compile-fail/kindck-copy.rs @@ -23,7 +23,7 @@ struct MyStruct { } struct MyNoncopyStruct { - x: ~int, + x: Box, } fn test<'a,T,U:Copy>(_: &'a int) { @@ -38,10 +38,10 @@ fn test<'a,T,U:Copy>(_: &'a int) { assert_copy::<&'a mut int>(); //~ ERROR does not fulfill // ~ pointers are not ok - assert_copy::<~int>(); //~ ERROR does not fulfill + assert_copy::>(); //~ ERROR does not fulfill assert_copy::<~str>(); //~ ERROR does not fulfill assert_copy:: >(); //~ ERROR does not fulfill - assert_copy::<~&'a mut int>(); //~ ERROR does not fulfill + assert_copy::>(); //~ ERROR does not fulfill // borrowed object types are generally ok assert_copy::<&'a Dummy>(); @@ -49,8 +49,8 @@ fn test<'a,T,U:Copy>(_: &'a int) { assert_copy::<&'static Dummy:Copy>(); // owned object types are not ok - assert_copy::<~Dummy>(); //~ ERROR does not fulfill - assert_copy::<~Dummy:Copy>(); //~ ERROR does not fulfill + assert_copy::>(); //~ ERROR does not fulfill + assert_copy::>(); //~ ERROR does not fulfill // mutable object types are not ok assert_copy::<&'a mut Dummy:Copy>(); //~ ERROR does not fulfill diff --git a/src/test/compile-fail/kindck-owned-trait-contains.rs b/src/test/compile-fail/kindck-owned-trait-contains.rs index e2005cbae918c..3f6c622dd0d6e 100644 --- a/src/test/compile-fail/kindck-owned-trait-contains.rs +++ b/src/test/compile-fail/kindck-owned-trait-contains.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Repeat { fn get(&self) -> A; } impl Repeat for A { fn get(&self) -> A { self.clone() } } -fn repeater(v: A) -> ~Repeat: { - ~v as ~Repeat: // No +fn repeater(v: A) -> Box:> { + box v as Box:> // No } fn main() { diff --git a/src/test/compile-fail/kindck-send.rs b/src/test/compile-fail/kindck-send.rs index cdf24257ce732..518e97515e799 100644 --- a/src/test/compile-fail/kindck-send.rs +++ b/src/test/compile-fail/kindck-send.rs @@ -28,28 +28,28 @@ fn test<'a,T,U:Send>(_: &'a int) { assert_send::<&'a str>(); //~ ERROR does not fulfill `Send` assert_send::<&'a [int]>(); //~ ERROR does not fulfill `Send` - // ~ pointers are ok - assert_send::<~int>(); + // boxes are ok + assert_send::>(); assert_send::<~str>(); assert_send:: >(); // but not if they own a bad thing - assert_send::<~&'a int>(); //~ ERROR does not fulfill `Send` + assert_send::>(); //~ ERROR does not fulfill `Send` // careful with object types, who knows what they close over... assert_send::<&'static Dummy>(); //~ ERROR does not fulfill `Send` assert_send::<&'a Dummy>(); //~ ERROR does not fulfill `Send` assert_send::<&'a Dummy:Send>(); //~ ERROR does not fulfill `Send` - assert_send::<~Dummy:>(); //~ ERROR does not fulfill `Send` + assert_send::>(); //~ ERROR does not fulfill `Send` // ...unless they are properly bounded assert_send::<&'static Dummy:Send>(); - assert_send::<~Dummy:Send>(); + assert_send::>(); // but closure and object types can have lifetime bounds which make // them not ok (FIXME #5121) // assert_send::(); // ERROR does not fulfill `Send` - // assert_send::<~Dummy:'a>(); // ERROR does not fulfill `Send` + // assert_send::>(); // ERROR does not fulfill `Send` // unsafe ptrs are ok unless they point at unsendable things assert_send::<*int>(); diff --git a/src/test/compile-fail/lint-allocation.rs b/src/test/compile-fail/lint-allocation.rs index 46199fa0280f8..c898107f5e330 100644 --- a/src/test/compile-fail/lint-allocation.rs +++ b/src/test/compile-fail/lint-allocation.rs @@ -14,6 +14,6 @@ fn f(_: &int) {} fn g(_: &mut int) {} fn main() { - f(~1); //~ ERROR unnecessary allocation, use & instead - g(~1); //~ ERROR unnecessary allocation, use &mut instead + f(box 1); //~ ERROR unnecessary allocation, use & instead + g(box 1); //~ ERROR unnecessary allocation, use &mut instead } diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index bbcc59f0d6cbd..10734f1f2430a 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -36,7 +36,7 @@ pub static used_static2: int = used_static; static USED_STATIC: int = 0; static STATIC_USED_IN_ENUM_DISCRIMINANT: uint = 10; -pub type typ = ~UsedStruct4; +pub type typ = *UsedStruct4; pub struct PubStruct(); struct PrivStruct; //~ ERROR: code is never used struct UsedStruct1 { x: int } @@ -57,7 +57,7 @@ pub struct PubStruct2 { } pub enum pub_enum { foo1, bar1 } -pub enum pub_enum2 { a(~StructUsedInEnum) } +pub enum pub_enum2 { a(*StructUsedInEnum) } pub enum pub_enum3 { Foo = STATIC_USED_IN_ENUM_DISCRIMINANT } enum priv_enum { foo2, bar2 } //~ ERROR: code is never used enum used_enum { foo3, bar3 } diff --git a/src/test/compile-fail/lint-heap-memory.rs b/src/test/compile-fail/lint-heap-memory.rs index 5f2987c6cfbd4..eaa1819bd53e5 100644 --- a/src/test/compile-fail/lint-heap-memory.rs +++ b/src/test/compile-fail/lint-heap-memory.rs @@ -13,19 +13,20 @@ #![allow(dead_code)] #![allow(deprecated_owned_vector)] + struct Foo { x: @int //~ ERROR type uses managed } -struct Bar { x: ~int } //~ ERROR type uses owned +struct Bar { x: Box } //~ ERROR type uses owned fn main() { - let _x : Bar = Bar {x : ~10}; //~ ERROR type uses owned + let _x : Bar = Bar {x : box 10}; //~ ERROR type uses owned @2; //~ ERROR type uses managed - ~2; //~ ERROR type uses owned - fn g(_: ~Clone) {} //~ ERROR type uses owned + box 2; //~ ERROR type uses owned + fn g(_: Box) {} //~ ERROR type uses owned "".to_owned(); //~ ERROR type uses owned proc() {}; //~ ERROR type uses owned } diff --git a/src/test/compile-fail/lint-owned-heap-memory.rs b/src/test/compile-fail/lint-owned-heap-memory.rs index 859dd127b9720..c9688ad49d77e 100644 --- a/src/test/compile-fail/lint-owned-heap-memory.rs +++ b/src/test/compile-fail/lint-owned-heap-memory.rs @@ -10,11 +10,12 @@ #![forbid(owned_heap_memory)] + struct Foo { - x: ~int //~ ERROR type uses owned + x: Box //~ ERROR type uses owned } fn main() { - let _x : Foo = Foo {x : ~10}; + let _x : Foo = Foo {x : box 10}; //~^ ERROR type uses owned } diff --git a/src/test/compile-fail/liveness-move-call-arg.rs b/src/test/compile-fail/liveness-move-call-arg.rs index ae1c086b34037..b9ad1c0fb65d9 100644 --- a/src/test/compile-fail/liveness-move-call-arg.rs +++ b/src/test/compile-fail/liveness-move-call-arg.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn take(_x: ~int) {} + +fn take(_x: Box) {} fn main() { - let x: ~int = ~25; + let x: Box = box 25; loop { take(x); //~ ERROR use of moved value: `x` } diff --git a/src/test/compile-fail/liveness-move-in-loop.rs b/src/test/compile-fail/liveness-move-in-loop.rs index a64d7578af319..018b0aaecfda4 100644 --- a/src/test/compile-fail/liveness-move-in-loop.rs +++ b/src/test/compile-fail/liveness-move-in-loop.rs @@ -8,9 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + fn main() { - let y: ~int = ~42; - let mut x: ~int; + let y: Box = box 42; + let mut x: Box; loop { println!("{:?}", y); loop { diff --git a/src/test/compile-fail/liveness-move-in-while.rs b/src/test/compile-fail/liveness-move-in-while.rs index 8aa85c03ad4ad..e32d8a78585de 100644 --- a/src/test/compile-fail/liveness-move-in-while.rs +++ b/src/test/compile-fail/liveness-move-in-while.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn main() { - let y: ~int = ~42; - let mut x: ~int; +fn main() { + let y: Box = box 42; + let mut x: Box; loop { println!("{:?}", y); //~ ERROR use of moved value: `y` while true { while true { while true { x = y; x.clone(); } } } diff --git a/src/test/compile-fail/liveness-use-after-move.rs b/src/test/compile-fail/liveness-use-after-move.rs index eccb3784325d9..f2b8976c61b93 100644 --- a/src/test/compile-fail/liveness-use-after-move.rs +++ b/src/test/compile-fail/liveness-use-after-move.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let x = ~5; + let x = box 5; let y = x; println!("{:?}", *x); //~ ERROR use of moved value: `x` y.clone(); diff --git a/src/test/compile-fail/liveness-use-after-send.rs b/src/test/compile-fail/liveness-use-after-send.rs index 8747d055ff945..2716d476c3a17 100644 --- a/src/test/compile-fail/liveness-use-after-send.rs +++ b/src/test/compile-fail/liveness-use-after-send.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + fn send(ch: _chan, data: T) { println!("{:?}", ch); println!("{:?}", data); @@ -18,7 +19,7 @@ struct _chan(int); // Tests that "log(debug, message);" is flagged as using // message after the send deinitializes it -fn test00_start(ch: _chan<~int>, message: ~int, _count: ~int) { +fn test00_start(ch: _chan>, message: Box, _count: Box) { send(ch, message); println!("{:?}", message); //~ ERROR use of moved value: `message` } diff --git a/src/test/compile-fail/map-types.rs b/src/test/compile-fail/map-types.rs index bd10c6ad8c37e..eda4deba7527b 100644 --- a/src/test/compile-fail/map-types.rs +++ b/src/test/compile-fail/map-types.rs @@ -15,9 +15,9 @@ use collections::HashMap; // Test that trait types printed in error msgs include the type arguments. fn main() { - let x: ~HashMap<~str, ~str> = ~HashMap::new(); - let x: ~Map<~str, ~str> = x; - let y: ~Map = ~x; + let x: Box> = box HashMap::new(); + let x: Box> = x; + let y: Box> = box x; //~^ ERROR failed to find an implementation of trait std::container::Map // for ~std::container::Map<~str,~str>:Send } diff --git a/src/test/compile-fail/moves-based-on-type-block-bad.rs b/src/test/compile-fail/moves-based-on-type-block-bad.rs index 4ec0831c588ef..73323def28d78 100644 --- a/src/test/compile-fail/moves-based-on-type-block-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-block-bad.rs @@ -8,13 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct S { - x: ~E + x: Box } enum E { - Foo(~S), - Bar(~int), + Foo(Box), + Bar(Box), Baz } @@ -23,13 +24,13 @@ fn f(s: &S, g: |&S|) { } fn main() { - let s = S { x: ~Bar(~42) }; + let s = S { x: box Bar(box 42) }; loop { f(&s, |hellothere| { match hellothere.x { //~ ERROR cannot move out - ~Foo(_) => {} - ~Bar(x) => println!("{}", x.to_str()), //~ NOTE attempting to move value to here - ~Baz => {} + box Foo(_) => {} + box Bar(x) => println!("{}", x.to_str()), //~ NOTE attempting to move value to here + box Baz => {} } }) } diff --git a/src/test/compile-fail/moves-based-on-type-cyclic-types-issue-4821.rs b/src/test/compile-fail/moves-based-on-type-cyclic-types-issue-4821.rs index cf82cf087a3fb..805c82f03f94c 100644 --- a/src/test/compile-fail/moves-based-on-type-cyclic-types-issue-4821.rs +++ b/src/test/compile-fail/moves-based-on-type-cyclic-types-issue-4821.rs @@ -12,9 +12,10 @@ // temporary kinds wound up being stored in a cache and used later. // See middle::ty::type_contents() for more information. -struct List { key: int, next: Option<~List> } -fn foo(node: ~List) -> int { +struct List { key: int, next: Option> } + +fn foo(node: Box) -> int { let r = match node.next { Some(right) => consume(right), None => 0 @@ -22,7 +23,7 @@ fn foo(node: ~List) -> int { consume(node) + r //~ ERROR use of partially moved value: `node` } -fn consume(v: ~List) -> int { +fn consume(v: Box) -> int { v.key } diff --git a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs index ac52f10ba701d..f9614574abda9 100644 --- a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs +++ b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs @@ -10,9 +10,9 @@ use std::uint; -fn test(_x: ~uint) {} +fn test(_x: Box) {} fn main() { - let i = ~3; + let i = box 3; let _f = || test(i); //~ ERROR cannot move out } diff --git a/src/test/compile-fail/moves-based-on-type-tuple.rs b/src/test/compile-fail/moves-based-on-type-tuple.rs index 6d5bb638be69b..85c435ef0db02 100644 --- a/src/test/compile-fail/moves-based-on-type-tuple.rs +++ b/src/test/compile-fail/moves-based-on-type-tuple.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn dup(x: ~int) -> ~(~int,~int) { ~(x, x) } //~ ERROR use of moved value + +fn dup(x: Box) -> Box<(Box,Box)> { box() (x, x) } //~ ERROR use of moved value fn main() { - dup(~3); + dup(box 3); } diff --git a/src/test/compile-fail/moves-sru-moved-field.rs b/src/test/compile-fail/moves-sru-moved-field.rs index 3306d19186c55..6f8353c61647f 100644 --- a/src/test/compile-fail/moves-sru-moved-field.rs +++ b/src/test/compile-fail/moves-sru-moved-field.rs @@ -8,18 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + type Noncopyable = proc(); struct Foo { copied: int, - moved: ~int, + moved: Box, noncopyable: Noncopyable } fn test0(f: Foo, g: Noncopyable, h: Noncopyable) { // just copy implicitly copyable fields from `f`, no moves: - let _b = Foo {moved: ~1, noncopyable: g, ..f}; - let _c = Foo {moved: ~2, noncopyable: h, ..f}; + let _b = Foo {moved: box 1, noncopyable: g, ..f}; + let _c = Foo {moved: box 2, noncopyable: h, ..f}; } fn test1(f: Foo, g: Noncopyable, h: Noncopyable) { @@ -30,7 +31,7 @@ fn test1(f: Foo, g: Noncopyable, h: Noncopyable) { fn test2(f: Foo, g: Noncopyable) { // move non-copyable field - let _b = Foo {copied: 22, moved: ~23, ..f}; + let _b = Foo {copied: 22, moved: box 23, ..f}; let _c = Foo {noncopyable: g, ..f}; //~ ERROR use of partially moved value: `f` } diff --git a/src/test/compile-fail/new-box-syntax-bad.rs b/src/test/compile-fail/new-box-syntax-bad.rs index 4b00334899dc7..543902a7a5580 100644 --- a/src/test/compile-fail/new-box-syntax-bad.rs +++ b/src/test/compile-fail/new-box-syntax-bad.rs @@ -14,11 +14,11 @@ // Tests that the new `box` syntax works with unique pointers and GC pointers. use std::gc::Gc; -use std::owned::HEAP; +use std::owned::{Box, HEAP}; pub fn main() { let x: Gc = box(HEAP) 2; //~ ERROR mismatched types let y: Gc = box(HEAP)(1 + 2); //~ ERROR mismatched types - let z: ~int = box(GC)(4 + 5); //~ ERROR mismatched types + let z: Box = box(GC)(4 + 5); //~ ERROR mismatched types } diff --git a/src/test/compile-fail/object-does-not-impl-trait.rs b/src/test/compile-fail/object-does-not-impl-trait.rs index 95f9238081665..17083933afaad 100644 --- a/src/test/compile-fail/object-does-not-impl-trait.rs +++ b/src/test/compile-fail/object-does-not-impl-trait.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Test that an object type `~Foo` is not considered to implement the +// Test that an object type `Box` is not considered to implement the // trait `Foo`. Issue #5087. + trait Foo {} fn take_foo(f: F) {} -fn take_object(f: ~Foo) { take_foo(f); } //~ ERROR failed to find an implementation of trait +fn take_object(f: Box) { take_foo(f); } //~ ERROR failed to find an implementation of trait fn main() {} diff --git a/src/test/compile-fail/object-pointer-types.rs b/src/test/compile-fail/object-pointer-types.rs index ab2aa928c2639..8868ddd4dfa30 100644 --- a/src/test/compile-fail/object-pointer-types.rs +++ b/src/test/compile-fail/object-pointer-types.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { fn borrowed(&self); fn borrowed_mut(&mut self); @@ -27,7 +28,7 @@ fn borrowed_mut_receiver(x: &mut Foo) { x.owned(); //~ ERROR does not implement any method } -fn owned_receiver(x: ~Foo) { +fn owned_receiver(x: Box) { x.borrowed(); x.borrowed_mut(); // See [1] x.managed(); //~ ERROR does not implement any method diff --git a/src/test/compile-fail/owned-ptr-static-bound.rs b/src/test/compile-fail/owned-ptr-static-bound.rs index 508633d294146..48f04c334941a 100644 --- a/src/test/compile-fail/owned-ptr-static-bound.rs +++ b/src/test/compile-fail/owned-ptr-static-bound.rs @@ -8,22 +8,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait A {} struct B<'a, T>(&'a A); trait X {} impl<'a, T> X for B<'a, T> {} -fn f<'a, T, U>(v: ~A) -> ~X: { - ~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `T` +fn f<'a, T, U>(v: Box>) -> Box { + box B(v) as Box //~ ERROR value may contain references; add `'static` bound to `T` } -fn g<'a, T, U>(v: ~A) -> ~X: { - ~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `U` +fn g<'a, T, U>(v: Box>) -> Box { + box B(v) as Box //~ ERROR value may contain references; add `'static` bound to `U` } -fn h<'a, T: 'static>(v: ~A) -> ~X: { - ~B(v) as ~X: // ok +fn h<'a, T: 'static>(v: Box>) -> Box { + box B(v) as Box // ok } fn main() {} diff --git a/src/test/compile-fail/pinned-deep-copy.rs b/src/test/compile-fail/pinned-deep-copy.rs index 0589d58a4c25d..49f2f35d29dcd 100644 --- a/src/test/compile-fail/pinned-deep-copy.rs +++ b/src/test/compile-fail/pinned-deep-copy.rs @@ -39,7 +39,7 @@ fn main() { let i = @Cell::new(0); { // Can't do this copy - let x = ~~~A {y: r(i)}; + let x = box box box A {y: r(i)}; let _z = x.clone(); //~ ERROR failed to find an implementation println!("{:?}", x); } diff --git a/src/test/compile-fail/privacy-ns1.rs b/src/test/compile-fail/privacy-ns1.rs index cb11a50055f7d..b7eee206b4074 100644 --- a/src/test/compile-fail/privacy-ns1.rs +++ b/src/test/compile-fail/privacy-ns1.rs @@ -15,6 +15,7 @@ #![allow(dead_code)] #![allow(unused_imports)] + // public type, private value pub mod foo1 { pub trait Bar { @@ -42,7 +43,7 @@ pub mod foo2 { fn test_glob2() { use foo2::*; - let _x: ~Bar; //~ ERROR use of undeclared type name `Bar` + let _x: Box; //~ ERROR use of undeclared type name `Bar` } // neither public @@ -58,7 +59,7 @@ fn test_glob3() { use foo3::*; Bar(); //~ ERROR unresolved name `Bar`. - let _x: ~Bar; //~ ERROR use of undeclared type name `Bar` + let _x: Box; //~ ERROR use of undeclared type name `Bar` } fn main() { diff --git a/src/test/compile-fail/privacy-ns2.rs b/src/test/compile-fail/privacy-ns2.rs index c75b12165c090..5ce0fb7e56a2c 100644 --- a/src/test/compile-fail/privacy-ns2.rs +++ b/src/test/compile-fail/privacy-ns2.rs @@ -15,6 +15,7 @@ #![allow(dead_code)] #![allow(unused_imports)] + // public type, private value pub mod foo1 { pub trait Bar { @@ -49,13 +50,13 @@ pub mod foo2 { fn test_single2() { use foo2::Bar; //~ ERROR `Bar` is private - let _x : ~Bar; + let _x : Box; } fn test_list2() { use foo2::{Bar,Baz}; //~ ERROR `Bar` is private - let _x: ~Bar; + let _x: Box; } // neither public @@ -76,14 +77,14 @@ fn test_single3() { use foo3::Bar; //~ ERROR `Bar` is private Bar(); - let _x: ~Bar; + let _x: Box; } fn test_list3() { use foo3::{Bar,Baz}; //~ ERROR `Bar` is private Bar(); - let _x: ~Bar; + let _x: Box; } fn main() { diff --git a/src/test/compile-fail/regions-bound-lists-feature-gate.rs b/src/test/compile-fail/regions-bound-lists-feature-gate.rs index 05050b72e5e8d..aa398bcd55746 100644 --- a/src/test/compile-fail/regions-bound-lists-feature-gate.rs +++ b/src/test/compile-fail/regions-bound-lists-feature-gate.rs @@ -8,9 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { } -fn foo<'a>(x: ~Foo:'a) { //~ ERROR only the 'static lifetime is accepted here +fn foo<'a>(x: Box) { //~ ERROR only the 'static lifetime is accepted here } fn bar<'a, T:'a>() { //~ ERROR only the 'static lifetime is accepted here diff --git a/src/test/compile-fail/regions-ref-in-fn-arg.rs b/src/test/compile-fail/regions-ref-in-fn-arg.rs index 8c8404f7abc83..47fca8bb8df23 100644 --- a/src/test/compile-fail/regions-ref-in-fn-arg.rs +++ b/src/test/compile-fail/regions-ref-in-fn-arg.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn arg_item(~ref x: ~int) -> &'static int { + +fn arg_item(box ref x: Box) -> &'static int { x //~^ ERROR borrowed value does not live long enough } -fn with(f: |~int| -> R) -> R { f(~3) } +fn with(f: |Box| -> R) -> R { f(box 3) } fn arg_closure() -> &'static int { - with(|~ref x| x) //~ ERROR borrowed value does not live long enough + with(|box ref x| x) //~ ERROR borrowed value does not live long enough } fn main() {} diff --git a/src/test/compile-fail/regions-trait-1.rs b/src/test/compile-fail/regions-trait-1.rs index 7aa545ab1b940..7771a71c79bc0 100644 --- a/src/test/compile-fail/regions-trait-1.rs +++ b/src/test/compile-fail/regions-trait-1.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct ctxt { v: uint } trait get_ctxt { @@ -27,12 +28,12 @@ impl<'a> get_ctxt for has_ctxt<'a> { } -fn get_v(gc: ~get_ctxt) -> uint { +fn get_v(gc: Box) -> uint { gc.get_ctxt().v } fn main() { let ctxt = ctxt { v: 22u }; let hc = has_ctxt { c: &ctxt }; - assert_eq!(get_v(~hc as ~get_ctxt), 22u); + assert_eq!(get_v(box hc as Box), 22u); } diff --git a/src/test/compile-fail/removed-syntax-closure-lifetime.rs b/src/test/compile-fail/removed-syntax-closure-lifetime.rs index e2ab70b1678cb..c5c8aa043f38f 100644 --- a/src/test/compile-fail/removed-syntax-closure-lifetime.rs +++ b/src/test/compile-fail/removed-syntax-closure-lifetime.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type closure = ~lt/fn(); //~ ERROR expected `;` but found `/` +type closure = Box; //~ ERROR expected `,` but found `/` diff --git a/src/test/compile-fail/removed-syntax-uniq-mut-expr.rs b/src/test/compile-fail/removed-syntax-uniq-mut-expr.rs index 0c2693a898b76..5603cd21f3b31 100644 --- a/src/test/compile-fail/removed-syntax-uniq-mut-expr.rs +++ b/src/test/compile-fail/removed-syntax-uniq-mut-expr.rs @@ -9,7 +9,7 @@ // except according to those terms. fn f() { - let a_box = ~mut 42; + let a_box = box mut 42; //~^ ERROR found `mut` in ident position //~^^ ERROR expected `;` but found `42` } diff --git a/src/test/compile-fail/removed-syntax-uniq-mut-ty.rs b/src/test/compile-fail/removed-syntax-uniq-mut-ty.rs index 98ab7522966e2..128dbbd9cabfc 100644 --- a/src/test/compile-fail/removed-syntax-uniq-mut-ty.rs +++ b/src/test/compile-fail/removed-syntax-uniq-mut-ty.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type mut_box = ~mut int; +type mut_box = Box; //~^ ERROR found `mut` in ident position - //~^^ ERROR expected `;` but found `int` + //~^^ ERROR expected `,` but found `int` diff --git a/src/test/compile-fail/removed-syntax-uniq-self.rs b/src/test/compile-fail/removed-syntax-uniq-self.rs deleted file mode 100644 index 8fb9c5e0e6f84..0000000000000 --- a/src/test/compile-fail/removed-syntax-uniq-self.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct S; - -impl S { - fn f(~mut self) {} //~ ERROR found `self` in ident position - //~^ ERROR expected `:` but found `)` -} diff --git a/src/test/compile-fail/selftype-traittype.rs b/src/test/compile-fail/selftype-traittype.rs index 73df5c3967c09..3bf547e3affc3 100644 --- a/src/test/compile-fail/selftype-traittype.rs +++ b/src/test/compile-fail/selftype-traittype.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait add { fn plus(&self, x: Self) -> Self; } -fn do_add(x: ~add, y: ~add) -> ~add { +fn do_add(x: Box, y: Box) -> Box { x.plus(y) //~ ERROR cannot call a method whose type contains a self-type through an object } diff --git a/src/test/compile-fail/static-mut-not-constant.rs b/src/test/compile-fail/static-mut-not-constant.rs index 90dabb7e3a271..927006adc9e26 100644 --- a/src/test/compile-fail/static-mut-not-constant.rs +++ b/src/test/compile-fail/static-mut-not-constant.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static mut a: ~int = ~3; //~ ERROR: mutable static items are not allowed to have owned pointers + +static mut a: Box = box 3; +//~^ ERROR mutable static items are not allowed to have owned pointers fn main() {} diff --git a/src/test/compile-fail/struct-fields-missing.rs b/src/test/compile-fail/struct-fields-missing.rs index 81d2ea3b959cf..0afc84ee1b367 100644 --- a/src/test/compile-fail/struct-fields-missing.rs +++ b/src/test/compile-fail/struct-fields-missing.rs @@ -8,9 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct BuildData { foo: int, - bar: ~int + bar: Box, } fn main() { diff --git a/src/test/compile-fail/trait-bounds-cant-coerce.rs b/src/test/compile-fail/trait-bounds-cant-coerce.rs index 958a97412bce7..12205ef062da0 100644 --- a/src/test/compile-fail/trait-bounds-cant-coerce.rs +++ b/src/test/compile-fail/trait-bounds-cant-coerce.rs @@ -8,17 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { } -fn a(_x: ~Foo:Send) { +fn a(_x: Box) { } -fn c(x: ~Foo:Share+Send) { +fn c(x: Box) { a(x); } -fn d(x: ~Foo:) { +fn d(x: Box) { a(x); //~ ERROR found no bounds } diff --git a/src/test/compile-fail/trait-bounds-not-on-struct.rs b/src/test/compile-fail/trait-bounds-not-on-struct.rs index ebffd0303e047..be5375d29384d 100644 --- a/src/test/compile-fail/trait-bounds-not-on-struct.rs +++ b/src/test/compile-fail/trait-bounds-not-on-struct.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Foo; -fn foo(_x: ~Foo:Send) { } //~ ERROR kind bounds can only be used on trait types +fn foo(_x: Box) { } //~ ERROR kind bounds can only be used on trait types fn main() { } diff --git a/src/test/compile-fail/trait-bounds-sugar.rs b/src/test/compile-fail/trait-bounds-sugar.rs index 32c23a3efdd36..9447030a7f461 100644 --- a/src/test/compile-fail/trait-bounds-sugar.rs +++ b/src/test/compile-fail/trait-bounds-sugar.rs @@ -10,15 +10,16 @@ // Tests for "default" bounds inferred for traits with no bounds list. + trait Foo {} -fn a(_x: ~Foo:Send) { +fn a(_x: Box) { } fn b(_x: &'static Foo) { // should be same as &'static Foo:'static } -fn c(x: ~Foo:Share) { +fn c(x: Box) { a(x); //~ ERROR expected bounds `Send` } diff --git a/src/test/compile-fail/trait-coercion-generic-bad.rs b/src/test/compile-fail/trait-coercion-generic-bad.rs index 297d36c3a0e83..7c4b633fa9e2d 100644 --- a/src/test/compile-fail/trait-coercion-generic-bad.rs +++ b/src/test/compile-fail/trait-coercion-generic-bad.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Struct { person: &'static str } @@ -23,7 +24,7 @@ impl Trait<&'static str> for Struct { } fn main() { - let s: ~Trait = ~Struct { person: "Fred" }; + let s: Box> = box Struct { person: "Fred" }; //~^ ERROR expected Trait, but found Trait<&'static str> //~^^ ERROR expected Trait, but found Trait<&'static str> s.f(1); diff --git a/src/test/compile-fail/trait-coercion-generic-regions.rs b/src/test/compile-fail/trait-coercion-generic-regions.rs index 6ffee2ef22b21..04239de2a83cc 100644 --- a/src/test/compile-fail/trait-coercion-generic-regions.rs +++ b/src/test/compile-fail/trait-coercion-generic-regions.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Struct { person: &'static str } @@ -25,6 +26,6 @@ impl Trait<&'static str> for Struct { fn main() { let person = "Fred".to_owned(); let person: &str = person; //~ ERROR `person[..]` does not live long enough - let s: ~Trait<&'static str> = ~Struct { person: person }; + let s: Box> = box Struct { person: person }; } diff --git a/src/test/compile-fail/trait-test-2.rs b/src/test/compile-fail/trait-test-2.rs index acac7ae9556cd..5e0340ce4f5c1 100644 --- a/src/test/compile-fail/trait-test-2.rs +++ b/src/test/compile-fail/trait-test-2.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait bar { fn dup(&self) -> Self; fn blah(&self); } impl bar for int { fn dup(&self) -> int { *self } fn blah(&self) {} } impl bar for uint { fn dup(&self) -> uint { *self } fn blah(&self) {} } @@ -15,5 +16,5 @@ impl bar for uint { fn dup(&self) -> uint { *self } fn blah(&self) {} } fn main() { 10i.dup::(); //~ ERROR does not take type parameters 10i.blah::(); //~ ERROR incorrect number of type parameters - (~10 as ~bar).dup(); //~ ERROR contains a self-type + (box 10 as Box).dup(); //~ ERROR contains a self-type } diff --git a/src/test/compile-fail/unique-object-noncopyable.rs b/src/test/compile-fail/unique-object-noncopyable.rs index 843b61c9dbee2..e237e2c8b7561 100644 --- a/src/test/compile-fail/unique-object-noncopyable.rs +++ b/src/test/compile-fail/unique-object-noncopyable.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { fn f(&self); } @@ -27,7 +28,7 @@ impl Foo for Bar { } fn main() { - let x = ~Bar { x: 10 }; - let y: ~Foo = x as ~Foo; + let x = box Bar { x: 10 }; + let y: Box = x as Box; let _z = y.clone(); //~ ERROR does not implement any method in scope } diff --git a/src/test/compile-fail/unique-pinned-nocopy.rs b/src/test/compile-fail/unique-pinned-nocopy.rs index da9e24b731434..04d8bc96a4717 100644 --- a/src/test/compile-fail/unique-pinned-nocopy.rs +++ b/src/test/compile-fail/unique-pinned-nocopy.rs @@ -17,7 +17,7 @@ impl Drop for r { } fn main() { - let i = ~r { b: true }; + let i = box r { b: true }; let _j = i.clone(); //~ ERROR failed to find an implementation println!("{:?}", i); } diff --git a/src/test/compile-fail/unique-unique-kind.rs b/src/test/compile-fail/unique-unique-kind.rs index 8e951cc9b55d3..6a62256b88131 100644 --- a/src/test/compile-fail/unique-unique-kind.rs +++ b/src/test/compile-fail/unique-unique-kind.rs @@ -14,6 +14,6 @@ fn f(_i: T) { } fn main() { - let i = ~@100; + let i = box @100; f(i); //~ ERROR does not fulfill `Send` } diff --git a/src/test/compile-fail/unique-vec-res.rs b/src/test/compile-fail/unique-vec-res.rs index b83277b38a689..adeecf2babf32 100644 --- a/src/test/compile-fail/unique-vec-res.rs +++ b/src/test/compile-fail/unique-vec-res.rs @@ -31,8 +31,8 @@ fn f(_i: Vec , _j: Vec ) { fn main() { let i1 = @Cell::new(0); let i2 = @Cell::new(1); - let r1 = vec!(~r { i: i1 }); - let r2 = vec!(~r { i: i2 }); + let r1 = vec!(box r { i: i1 }); + let r2 = vec!(box r { i: i2 }); f(r1.clone(), r2.clone()); //~^ ERROR failed to find an implementation of println!("{:?}", (r2, i1.get())); diff --git a/src/test/compile-fail/unreachable-arm.rs b/src/test/compile-fail/unreachable-arm.rs index b983eabb74350..e356f87af69d5 100644 --- a/src/test/compile-fail/unreachable-arm.rs +++ b/src/test/compile-fail/unreachable-arm.rs @@ -10,6 +10,7 @@ // error-pattern:unreachable pattern -enum foo { a(~foo, int), b(uint), } -fn main() { match b(1u) { b(_) | a(~_, 1) => { } a(_, 1) => { } } } +enum foo { a(Box, int), b(uint), } + +fn main() { match b(1u) { b(_) | a(box _, 1) => { } a(_, 1) => { } } } diff --git a/src/test/compile-fail/unsized3.rs b/src/test/compile-fail/unsized3.rs index 0ff5b1c9b5ad8..c321871c40f2c 100644 --- a/src/test/compile-fail/unsized3.rs +++ b/src/test/compile-fail/unsized3.rs @@ -10,6 +10,7 @@ // Test sized-ness checking in substitution. + // Unbounded. fn f1(x: &X) { f2::(x); //~ ERROR instantiating a type parameter with an incompatible type `X`, which does n @@ -49,7 +50,7 @@ fn f8(x1: &S, x2: &S) { } // Test some tuples. -fn f9(x1: ~S, x2: ~E) { +fn f9(x1: Box>, x2: Box>) { f5(&(*x1, 34)); //~ERROR instantiating a type parameter with an incompatible type `(S,int)`, f5(&(32, *x2)); //~ERROR instantiating a type parameter with an incompatible type `(int,E)`, } diff --git a/src/test/compile-fail/unsized6.rs b/src/test/compile-fail/unsized6.rs index a763373e3644c..9916fdba20f6e 100644 --- a/src/test/compile-fail/unsized6.rs +++ b/src/test/compile-fail/unsized6.rs @@ -10,6 +10,7 @@ // Test `type` local variables. + trait T for type {} fn f1(x: &X) { @@ -25,12 +26,12 @@ fn f2(x: &X) { let y: (int, (X, int)); //~ERROR variable `y` has dynamically sized type `(int,(X,int))` } -fn f3(x1: ~X, x2: ~X, x3: ~X) { +fn f3(x1: Box, x2: Box, x3: Box) { let y: X = *x1; //~ERROR variable `y` has dynamically sized type `X` let y = *x2; //~ERROR variable `y` has dynamically sized type `X` let (y, z) = (*x3, 4); //~ERROR variable `y` has dynamically sized type `X` } -fn f4(x1: ~X, x2: ~X, x3: ~X) { +fn f4(x1: Box, x2: Box, x3: Box) { let y: X = *x1; //~ERROR variable `y` has dynamically sized type `X` let y = *x2; //~ERROR variable `y` has dynamically sized type `X` let (y, z) = (*x3, 4); //~ERROR variable `y` has dynamically sized type `X` diff --git a/src/test/compile-fail/use-after-move-implicity-coerced-object.rs b/src/test/compile-fail/use-after-move-implicity-coerced-object.rs index 4d57470a72165..e95ab71e5aaea 100644 --- a/src/test/compile-fail/use-after-move-implicity-coerced-object.rs +++ b/src/test/compile-fail/use-after-move-implicity-coerced-object.rs @@ -23,17 +23,17 @@ impl fmt::Show for Number { } struct List { - list: Vec<~ToStr> } + list: Vec> } impl List { - fn push(&mut self, n: ~ToStr) { + fn push(&mut self, n: Box) { self.list.push(n); } } fn main() { - let n = ~Number { n: 42 }; - let mut l = ~List { list: Vec::new() }; + let n = box Number { n: 42 }; + let mut l = box List { list: Vec::new() }; l.push(n); let x = n.to_str(); //~^ ERROR: use of moved value: `n` diff --git a/src/test/compile-fail/use-after-move-self.rs b/src/test/compile-fail/use-after-move-self.rs index 56e5fdce3cf71..8d1ab1bcd947c 100644 --- a/src/test/compile-fail/use-after-move-self.rs +++ b/src/test/compile-fail/use-after-move-self.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct S { - x: ~int + x: Box, } impl S { @@ -22,6 +23,6 @@ impl S { } fn main() { - let x = S { x: ~1 }; + let x = S { x: box 1 }; println!("{}", x.foo()); } diff --git a/src/test/debug-info/borrowed-struct.rs b/src/test/debug-info/borrowed-struct.rs index c5f4bf0ac6288..e271a221611ae 100644 --- a/src/test/debug-info/borrowed-struct.rs +++ b/src/test/debug-info/borrowed-struct.rs @@ -65,7 +65,7 @@ fn main() { let managed_val_interior_ref_1: &int = &managed_val.x; let managed_val_interior_ref_2: &f64 = &managed_val.y; - let unique_val = ~SomeStruct { x: 13, y: 26.5 }; + let unique_val = box SomeStruct { x: 13, y: 26.5 }; let unique_val_ref: &SomeStruct = unique_val; let unique_val_interior_ref_1: &int = &unique_val.x; let unique_val_interior_ref_2: &f64 = &unique_val.y; diff --git a/src/test/debug-info/borrowed-tuple.rs b/src/test/debug-info/borrowed-tuple.rs index 5cc69c94d596b..b619f8e8ba12f 100644 --- a/src/test/debug-info/borrowed-tuple.rs +++ b/src/test/debug-info/borrowed-tuple.rs @@ -31,6 +31,7 @@ #![allow(unused_variable)] + fn main() { let stack_val: (i16, f32) = (-14, -19f32); let stack_val_ref: &(i16, f32) = &stack_val; @@ -39,7 +40,7 @@ fn main() { let managed_val: @(i16, f32) = @(-16, -21f32); let managed_val_ref: &(i16, f32) = managed_val; - let unique_val: ~(i16, f32) = ~(-17, -22f32); + let unique_val: Box<(i16, f32)> = box() (-17, -22f32); let unique_val_ref: &(i16, f32) = unique_val; zzz(); diff --git a/src/test/debug-info/borrowed-unique-basic.rs b/src/test/debug-info/borrowed-unique-basic.rs index 98cf0905f2ae4..eaa2679e698c4 100644 --- a/src/test/debug-info/borrowed-unique-basic.rs +++ b/src/test/debug-info/borrowed-unique-basic.rs @@ -63,46 +63,46 @@ fn main() { - let bool_box: ~bool = ~true; + let bool_box: Box = box true; let bool_ref: &bool = bool_box; - let int_box: ~int = ~-1; + let int_box: Box = box -1; let int_ref: &int = int_box; - let char_box: ~char = ~'a'; + let char_box: Box = box 'a'; let char_ref: &char = char_box; - let i8_box: ~i8 = ~68; + let i8_box: Box = box 68; let i8_ref: &i8 = i8_box; - let i16_box: ~i16 = ~-16; + let i16_box: Box = box -16; let i16_ref: &i16 = i16_box; - let i32_box: ~i32 = ~-32; + let i32_box: Box = box -32; let i32_ref: &i32 = i32_box; - let i64_box: ~i64 = ~-64; + let i64_box: Box = box -64; let i64_ref: &i64 = i64_box; - let uint_box: ~uint = ~1; + let uint_box: Box = box 1; let uint_ref: &uint = uint_box; - let u8_box: ~u8 = ~100; + let u8_box: Box = box 100; let u8_ref: &u8 = u8_box; - let u16_box: ~u16 = ~16; + let u16_box: Box = box 16; let u16_ref: &u16 = u16_box; - let u32_box: ~u32 = ~32; + let u32_box: Box = box 32; let u32_ref: &u32 = u32_box; - let u64_box: ~u64 = ~64; + let u64_box: Box = box 64; let u64_ref: &u64 = u64_box; - let f32_box: ~f32 = ~2.5; + let f32_box: Box = box 2.5; let f32_ref: &f32 = f32_box; - let f64_box: ~f64 = ~3.5; + let f64_box: Box = box 3.5; let f64_ref: &f64 = f64_box; zzz(); } diff --git a/src/test/debug-info/box.rs b/src/test/debug-info/box.rs index 208dd52f9ace2..a849a058332c3 100644 --- a/src/test/debug-info/box.rs +++ b/src/test/debug-info/box.rs @@ -28,8 +28,8 @@ #![allow(unused_variable)] fn main() { - let a = ~1; - let b = ~(2, 3.5); + let a = box 1; + let b = box() (2, 3.5); let c = @4; let d = @false; _zzz(); diff --git a/src/test/debug-info/boxed-struct.rs b/src/test/debug-info/boxed-struct.rs index 84b35134ad581..a286fca22c1c2 100644 --- a/src/test/debug-info/boxed-struct.rs +++ b/src/test/debug-info/boxed-struct.rs @@ -30,6 +30,7 @@ #![feature(managed_boxes)] #![allow(unused_variable)] + struct StructWithSomePadding { x: i16, y: i32, @@ -50,10 +51,10 @@ impl Drop for StructWithDestructor { fn main() { - let unique = ~StructWithSomePadding { x: 99, y: 999, z: 9999, w: 99999 }; + let unique = box StructWithSomePadding { x: 99, y: 999, z: 9999, w: 99999 }; let managed = @StructWithSomePadding { x: 88, y: 888, z: 8888, w: 88888 }; - let unique_dtor = ~StructWithDestructor { x: 77, y: 777, z: 7777, w: 77777 }; + let unique_dtor = box StructWithDestructor { x: 77, y: 777, z: 7777, w: 77777 }; let managed_dtor = @StructWithDestructor { x: 33, y: 333, z: 3333, w: 33333 }; zzz(); diff --git a/src/test/debug-info/closure-in-generic-function.rs b/src/test/debug-info/closure-in-generic-function.rs index 1184ce8643b44..f3692e7bf961a 100644 --- a/src/test/debug-info/closure-in-generic-function.rs +++ b/src/test/debug-info/closure-in-generic-function.rs @@ -40,7 +40,7 @@ fn some_generic_fun(a: T1, b: T2) -> (T2, T1) { fn main() { some_generic_fun(0.5, 10); - some_generic_fun(&29, ~110); + some_generic_fun(&29, box 110); } fn zzz() {()} diff --git a/src/test/debug-info/destructured-fn-argument.rs b/src/test/debug-info/destructured-fn-argument.rs index 246857d345c45..2f7fc961cddb1 100644 --- a/src/test/debug-info/destructured-fn-argument.rs +++ b/src/test/debug-info/destructured-fn-argument.rs @@ -183,6 +183,7 @@ #![allow(unused_variable)] + struct Struct { a: i64, b: i32 @@ -249,7 +250,7 @@ fn contained_borrowed_pointer((&cc, _): (&int, int)) { zzz(); } -fn unique_pointer(~dd: ~(int, int, int)) { +fn unique_pointer(box dd: Box<(int, int, int)>) { zzz(); } @@ -299,7 +300,7 @@ fn main() { managed_box(&(34, 35)); borrowed_pointer(&(36, 37)); contained_borrowed_pointer((&38, 39)); - unique_pointer(~(40, 41, 42)); + unique_pointer(box() (40, 41, 42)); ref_binding((43, 44, 45)); ref_binding_in_tuple((46, (47, 48))); ref_binding_in_struct(Struct { a: 49, b: 50 }); diff --git a/src/test/debug-info/destructured-local.rs b/src/test/debug-info/destructured-local.rs index 5aabf1fe82ff1..3dab6ace9a82a 100644 --- a/src/test/debug-info/destructured-local.rs +++ b/src/test/debug-info/destructured-local.rs @@ -181,7 +181,7 @@ fn main() { let (&cc, _) = (&38, 39); // unique pointer - let ~dd = ~(40, 41, 42); + let box dd = box() (40, 41, 42); // ref binding let ref ee = (43, 44, 45); diff --git a/src/test/debug-info/generic-method-on-generic-struct.rs b/src/test/debug-info/generic-method-on-generic-struct.rs index 38d260678b7f6..7afa89529989a 100644 --- a/src/test/debug-info/generic-method-on-generic-struct.rs +++ b/src/test/debug-info/generic-method-on-generic-struct.rs @@ -91,7 +91,7 @@ fn main() { let _ = stack.self_by_ref(-1, -2_i8); let _ = stack.self_by_val(-3, -4_i16); - let owned = ~Struct { x: 1234.5 }; + let owned = box Struct { x: 1234.5 }; let _ = owned.self_by_ref(-5, -6_i32); let _ = owned.self_by_val(-7, -8_i64); let _ = owned.self_owned(-9, -10.5_f32); diff --git a/src/test/debug-info/managed-pointer-within-unique.rs b/src/test/debug-info/managed-pointer-within-unique.rs index 79fb353ac4d01..2207b3ef798ee 100644 --- a/src/test/debug-info/managed-pointer-within-unique.rs +++ b/src/test/debug-info/managed-pointer-within-unique.rs @@ -35,9 +35,9 @@ struct ContainsManaged { } fn main() { - let ordinary_unique = ~(-1, -2); + let ordinary_unique = box() (-1, -2); - let managed_within_unique = ~ContainsManaged { x: -3, y: @-4 }; + let managed_within_unique = box ContainsManaged { x: -3, y: @-4 }; zzz(); } diff --git a/src/test/debug-info/method-on-enum.rs b/src/test/debug-info/method-on-enum.rs index 3ef78c49a54c1..9c8718a4295cd 100644 --- a/src/test/debug-info/method-on-enum.rs +++ b/src/test/debug-info/method-on-enum.rs @@ -94,7 +94,7 @@ fn main() { let _ = stack.self_by_ref(-1, -2); let _ = stack.self_by_val(-3, -4); - let owned = ~Variant1{ x: 1799, y: 1799 }; + let owned = box Variant1{ x: 1799, y: 1799 }; let _ = owned.self_by_ref(-5, -6); let _ = owned.self_by_val(-7, -8); let _ = owned.self_owned(-9, -10); diff --git a/src/test/debug-info/method-on-generic-struct.rs b/src/test/debug-info/method-on-generic-struct.rs index 1c82fec2a8b23..f2cdadd8aadf9 100644 --- a/src/test/debug-info/method-on-generic-struct.rs +++ b/src/test/debug-info/method-on-generic-struct.rs @@ -91,7 +91,7 @@ fn main() { let _ = stack.self_by_ref(-1, -2); let _ = stack.self_by_val(-3, -4); - let owned = ~Struct { x: 1234.5 }; + let owned = box Struct { x: 1234.5 }; let _ = owned.self_by_ref(-5, -6); let _ = owned.self_by_val(-7, -8); let _ = owned.self_owned(-9, -10); diff --git a/src/test/debug-info/method-on-struct.rs b/src/test/debug-info/method-on-struct.rs index 1bfec62dedccf..dcd285b0a14b3 100644 --- a/src/test/debug-info/method-on-struct.rs +++ b/src/test/debug-info/method-on-struct.rs @@ -91,7 +91,7 @@ fn main() { let _ = stack.self_by_ref(-1, -2); let _ = stack.self_by_val(-3, -4); - let owned = ~Struct { x: 200 }; + let owned = box Struct { x: 200 }; let _ = owned.self_by_ref(-5, -6); let _ = owned.self_by_val(-7, -8); let _ = owned.self_owned(-9, -10); diff --git a/src/test/debug-info/method-on-trait.rs b/src/test/debug-info/method-on-trait.rs index 473ed973bb522..6e1f8e6c72d56 100644 --- a/src/test/debug-info/method-on-trait.rs +++ b/src/test/debug-info/method-on-trait.rs @@ -97,7 +97,7 @@ fn main() { let _ = stack.self_by_ref(-1, -2); let _ = stack.self_by_val(-3, -4); - let owned = ~Struct { x: 200 }; + let owned = box Struct { x: 200 }; let _ = owned.self_by_ref(-5, -6); let _ = owned.self_by_val(-7, -8); let _ = owned.self_owned(-9, -10); diff --git a/src/test/debug-info/method-on-tuple-struct.rs b/src/test/debug-info/method-on-tuple-struct.rs index d0b97a079cca9..184bee99d872c 100644 --- a/src/test/debug-info/method-on-tuple-struct.rs +++ b/src/test/debug-info/method-on-tuple-struct.rs @@ -89,7 +89,7 @@ fn main() { let _ = stack.self_by_ref(-1, -2); let _ = stack.self_by_val(-3, -4); - let owned = ~TupleStruct(200, -200.5); + let owned = box TupleStruct(200, -200.5); let _ = owned.self_by_ref(-5, -6); let _ = owned.self_by_val(-7, -8); let _ = owned.self_owned(-9, -10); diff --git a/src/test/debug-info/recursive-struct.rs b/src/test/debug-info/recursive-struct.rs index ca178468941e6..a46a1c248ff01 100644 --- a/src/test/debug-info/recursive-struct.rs +++ b/src/test/debug-info/recursive-struct.rs @@ -105,13 +105,14 @@ #![allow(unused_variable)] #![feature(struct_variant)] + enum Opt { Empty, Val { val: T } } struct UniqueNode { - next: Opt<~UniqueNode>, + next: Opt>>, value: T } @@ -121,27 +122,27 @@ struct ManagedNode { } struct LongCycle1 { - next: ~LongCycle2, + next: Box>, value: T, } struct LongCycle2 { - next: ~LongCycle3, + next: Box>, value: T, } struct LongCycle3 { - next: ~LongCycle4, + next: Box>, value: T, } struct LongCycle4 { - next: Option<~LongCycle1>, + next: Option>>, value: T, } struct LongCycleWithAnonymousTypes { - next: Opt<~~~~~LongCycleWithAnonymousTypes>, + next: Opt>>>>>, value: uint, } @@ -163,7 +164,7 @@ struct LongCycleWithAnonymousTypes { fn main() { let stack_unique: UniqueNode = UniqueNode { next: Val { - val: ~UniqueNode { + val: box UniqueNode { next: Empty, value: 1_u16, } @@ -171,9 +172,9 @@ fn main() { value: 0_u16, }; - let unique_unique: ~UniqueNode = ~UniqueNode { + let unique_unique: Box> = box UniqueNode { next: Val { - val: ~UniqueNode { + val: box UniqueNode { next: Empty, value: 3, } @@ -183,7 +184,7 @@ fn main() { let box_unique: @UniqueNode = @UniqueNode { next: Val { - val: ~UniqueNode { + val: box UniqueNode { next: Empty, value: 5, } @@ -193,7 +194,7 @@ fn main() { let vec_unique: [UniqueNode, ..1] = [UniqueNode { next: Val { - val: ~UniqueNode { + val: box UniqueNode { next: Empty, value: 7.5, } @@ -203,7 +204,7 @@ fn main() { let borrowed_unique: &UniqueNode = &UniqueNode { next: Val { - val: ~UniqueNode { + val: box UniqueNode { next: Empty, value: 9.5, } @@ -221,7 +222,7 @@ fn main() { value: 10, }; - let unique_managed: ~ManagedNode = ~ManagedNode { + let unique_managed: Box> = box ManagedNode { next: Val { val: @ManagedNode { next: Empty, @@ -263,9 +264,9 @@ fn main() { // LONG CYCLE let long_cycle1: LongCycle1 = LongCycle1 { - next: ~LongCycle2 { - next: ~LongCycle3 { - next: ~LongCycle4 { + next: box LongCycle2 { + next: box LongCycle3 { + next: box LongCycle4 { next: None, value: 23, }, @@ -277,8 +278,8 @@ fn main() { }; let long_cycle2: LongCycle2 = LongCycle2 { - next: ~LongCycle3 { - next: ~LongCycle4 { + next: box LongCycle3 { + next: box LongCycle4 { next: None, value: 26, }, @@ -288,7 +289,7 @@ fn main() { }; let long_cycle3: LongCycle3 = LongCycle3 { - next: ~LongCycle4 { + next: box LongCycle4 { next: None, value: 28, }, @@ -301,10 +302,10 @@ fn main() { }; // It's important that LongCycleWithAnonymousTypes is encountered only at the end of the - // `~` chain. - let long_cycle_w_anonymous_types = ~~~~~LongCycleWithAnonymousTypes { + // `box` chain. + let long_cycle_w_anonymous_types = box box box box box LongCycleWithAnonymousTypes { next: Val { - val: ~~~~~LongCycleWithAnonymousTypes { + val: box box box box box LongCycleWithAnonymousTypes { next: Empty, value: 31, } diff --git a/src/test/debug-info/self-in-default-method.rs b/src/test/debug-info/self-in-default-method.rs index c8ab9d1f0bc25..194cfc77bf344 100644 --- a/src/test/debug-info/self-in-default-method.rs +++ b/src/test/debug-info/self-in-default-method.rs @@ -92,7 +92,7 @@ fn main() { let _ = stack.self_by_ref(-1, -2); let _ = stack.self_by_val(-3, -4); - let owned = ~Struct { x: 200 }; + let owned = box Struct { x: 200 }; let _ = owned.self_by_ref(-5, -6); let _ = owned.self_by_val(-7, -8); let _ = owned.self_owned(-9, -10); diff --git a/src/test/debug-info/self-in-generic-default-method.rs b/src/test/debug-info/self-in-generic-default-method.rs index 51fb886076179..9e7504be15b46 100644 --- a/src/test/debug-info/self-in-generic-default-method.rs +++ b/src/test/debug-info/self-in-generic-default-method.rs @@ -93,7 +93,7 @@ fn main() { let _ = stack.self_by_ref(-1, -2_i8); let _ = stack.self_by_val(-3, -4_i16); - let owned = ~Struct { x: 879 }; + let owned = box Struct { x: 879 }; let _ = owned.self_by_ref(-5, -6_i32); let _ = owned.self_by_val(-7, -8_i64); let _ = owned.self_owned(-9, -10.5_f32); diff --git a/src/test/debug-info/trait-pointers.rs b/src/test/debug-info/trait-pointers.rs index 8d114a3f8ddee..fcb0f6082a361 100644 --- a/src/test/debug-info/trait-pointers.rs +++ b/src/test/debug-info/trait-pointers.rs @@ -15,6 +15,7 @@ #![allow(unused_variable)] + trait Trait { fn method(&self) -> int { 0 } } @@ -30,5 +31,5 @@ impl Trait for Struct {} fn main() { let stack_struct = Struct { a:0, b: 1.0 }; let reference: &Trait = &stack_struct as &Trait; - let unique: ~Trait = ~Struct { a:2, b: 3.0 } as ~Trait; + let unique: Box = box Struct { a:2, b: 3.0 } as Box; } diff --git a/src/test/debug-info/unique-enum.rs b/src/test/debug-info/unique-enum.rs index 1c2cc8832856b..45f0213bf8c1a 100644 --- a/src/test/debug-info/unique-enum.rs +++ b/src/test/debug-info/unique-enum.rs @@ -50,15 +50,15 @@ fn main() { // 0b01111100011111000111110001111100 = 2088533116 // 0b0111110001111100 = 31868 // 0b01111100 = 124 - let the_a = ~TheA { x: 0, y: 8970181431921507452 }; + let the_a = box TheA { x: 0, y: 8970181431921507452 }; // 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441 // 0b00010001000100010001000100010001 = 286331153 // 0b0001000100010001 = 4369 // 0b00010001 = 17 - let the_b = ~TheB (0, 286331153, 286331153); + let the_b = box TheB (0, 286331153, 286331153); - let univariant = ~TheOnlyCase(123234); + let univariant = box TheOnlyCase(123234); zzz(); } diff --git a/src/test/debug-info/var-captured-in-nested-closure.rs b/src/test/debug-info/var-captured-in-nested-closure.rs index 8dd22e6061791..7677c9e923565 100644 --- a/src/test/debug-info/var-captured-in-nested-closure.rs +++ b/src/test/debug-info/var-captured-in-nested-closure.rs @@ -68,7 +68,7 @@ fn main() { }; let struct_ref = &a_struct; - let owned = ~6; + let owned = box 6; let managed = @7; let closure = || { diff --git a/src/test/debug-info/var-captured-in-sendable-closure.rs b/src/test/debug-info/var-captured-in-sendable-closure.rs index 83b26e0897597..4316e503a5140 100644 --- a/src/test/debug-info/var-captured-in-sendable-closure.rs +++ b/src/test/debug-info/var-captured-in-sendable-closure.rs @@ -39,7 +39,7 @@ fn main() { c: 4 }; - let owned = ~5; + let owned = box 5; let closure: proc() = proc() { zzz(); diff --git a/src/test/debug-info/var-captured-in-stack-closure.rs b/src/test/debug-info/var-captured-in-stack-closure.rs index 4daaf8f7a0e62..57dcabe90b689 100644 --- a/src/test/debug-info/var-captured-in-stack-closure.rs +++ b/src/test/debug-info/var-captured-in-stack-closure.rs @@ -48,7 +48,7 @@ fn main() { }; let struct_ref = &a_struct; - let owned = ~6; + let owned = box 6; let managed = @7; let closure = || { diff --git a/src/test/pretty/path-type-bounds.rs b/src/test/pretty/path-type-bounds.rs index 7b09c58932099..0fdbad67f160d 100644 --- a/src/test/pretty/path-type-bounds.rs +++ b/src/test/pretty/path-type-bounds.rs @@ -10,14 +10,15 @@ // pp-exact + trait Tr { } impl Tr for int { } -fn foo(x: ~Tr: Share) -> ~Tr: Share { x } +fn foo(x: Box) -> Box { x } fn main() { - let x: ~Tr: Share; + let x: Box; - ~1 as ~Tr: Share; + box() 1 as Box; } diff --git a/src/test/run-fail/fail-macro-any-wrapped.rs b/src/test/run-fail/fail-macro-any-wrapped.rs index 5a3dda88f705a..e1eea1d89b9db 100644 --- a/src/test/run-fail/fail-macro-any-wrapped.rs +++ b/src/test/run-fail/fail-macro-any-wrapped.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:failed at '~Any' +// error-pattern:failed at 'Box' fn main() { - fail!(~612_i64); + fail!(box 612_i64); } diff --git a/src/test/run-fail/fail-macro-any.rs b/src/test/run-fail/fail-macro-any.rs index d812e19e1c85e..09b507433080e 100644 --- a/src/test/run-fail/fail-macro-any.rs +++ b/src/test/run-fail/fail-macro-any.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:failed at '~Any' +// error-pattern:failed at 'Box' + fn main() { - fail!(~413 as ~::std::any::Any:Send); + fail!(box 413 as Box<::std::any::Any:Send>); } diff --git a/src/test/run-fail/issue-2272.rs b/src/test/run-fail/issue-2272.rs index c27ddef8711b8..9ac5790f2b708 100644 --- a/src/test/run-fail/issue-2272.rs +++ b/src/test/run-fail/issue-2272.rs @@ -13,7 +13,8 @@ // error-pattern:explicit failure // Issue #2272 - unwind this without leaking the unique pointer -struct X { y: Y, a: ~int } + +struct X { y: Y, a: Box } struct Y { z: @int } @@ -22,7 +23,7 @@ fn main() { y: Y { z: @0 }, - a: ~0 + a: box 0 }; fail!(); } diff --git a/src/test/run-fail/unique-fail.rs b/src/test/run-fail/unique-fail.rs index 86fde5b7f9781..f1804c1069189 100644 --- a/src/test/run-fail/unique-fail.rs +++ b/src/test/run-fail/unique-fail.rs @@ -9,4 +9,4 @@ // except according to those terms. // error-pattern: fail -fn main() { ~fail!(); } +fn main() { box fail!(); } diff --git a/src/test/run-fail/unwind-box-fn-unique.rs b/src/test/run-fail/unwind-box-fn-unique.rs index 3fabbdff9b3b3..50ecedd68fe2d 100644 --- a/src/test/run-fail/unwind-box-fn-unique.rs +++ b/src/test/run-fail/unwind-box-fn-unique.rs @@ -17,7 +17,7 @@ fn failfn() { } fn main() { - let y = ~0; + let y = box 0; let x: @proc():Send = @(proc() { println!("{:?}", y.clone()); }); diff --git a/src/test/run-fail/unwind-box-res.rs b/src/test/run-fail/unwind-box-res.rs index 2e4ebf5ea34b0..ecaae7f5cc72d 100644 --- a/src/test/run-fail/unwind-box-res.rs +++ b/src/test/run-fail/unwind-box-res.rs @@ -25,7 +25,7 @@ struct r { impl Drop for r { fn drop(&mut self) { unsafe { - let _v2: ~int = cast::transmute(self.v); + let _v2: Box = cast::transmute(self.v); } } } @@ -38,7 +38,7 @@ fn r(v: *int) -> r { fn main() { unsafe { - let i1 = ~0; + let i1 = box 0; let i1p = cast::transmute_copy(&i1); cast::forget(i1); let x = @r(i1p); diff --git a/src/test/run-fail/unwind-box-unique-unique.rs b/src/test/run-fail/unwind-box-unique-unique.rs index dcfaccf5ab789..82da2bc6ca3d1 100644 --- a/src/test/run-fail/unwind-box-unique-unique.rs +++ b/src/test/run-fail/unwind-box-unique-unique.rs @@ -12,12 +12,13 @@ #![feature(managed_boxes)] + fn failfn() { fail!(); } fn main() { - let x = @~~0; + let x = @box box 0; failfn(); println!("{:?}", x); } diff --git a/src/test/run-fail/unwind-box-unique.rs b/src/test/run-fail/unwind-box-unique.rs index bfe72835f453b..99adaaad314d5 100644 --- a/src/test/run-fail/unwind-box-unique.rs +++ b/src/test/run-fail/unwind-box-unique.rs @@ -17,7 +17,7 @@ fn failfn() { } fn main() { - let x = @~0; + let x = @box 0; failfn(); println!("{:?}", x); } diff --git a/src/test/run-fail/unwind-partial-unique.rs b/src/test/run-fail/unwind-partial-unique.rs index f265655e0ef6a..8d5fcfff963f2 100644 --- a/src/test/run-fail/unwind-partial-unique.rs +++ b/src/test/run-fail/unwind-partial-unique.rs @@ -22,7 +22,7 @@ fn prime() { } fn partial() { - let _x = ~f(); + let _x = box f(); } fn main() { diff --git a/src/test/run-fail/unwind-unique.rs b/src/test/run-fail/unwind-unique.rs index 53b2a55602c29..af1e499d1f203 100644 --- a/src/test/run-fail/unwind-unique.rs +++ b/src/test/run-fail/unwind-unique.rs @@ -10,11 +10,12 @@ // error-pattern:fail + fn failfn() { fail!(); } fn main() { - ~0; + box 0; failfn(); } diff --git a/src/test/run-pass/alignment-gep-tup-like-1.rs b/src/test/run-pass/alignment-gep-tup-like-1.rs index 2c71d791cd48f..0af2be8ab2940 100644 --- a/src/test/run-pass/alignment-gep-tup-like-1.rs +++ b/src/test/run-pass/alignment-gep-tup-like-1.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct pair { a: A, b: B } @@ -27,11 +28,11 @@ impl Invokable for Invoker { } } -fn f(a: A, b: u16) -> ~Invokable: { - ~Invoker { +fn f(a: A, b: u16) -> Box:> { + box Invoker { a: a, b: b, - } as ~Invokable: + } as Box>: } pub fn main() { diff --git a/src/test/run-pass/assert-eq-macro-success.rs b/src/test/run-pass/assert-eq-macro-success.rs index 1e0418d880600..4aea57871b94d 100644 --- a/src/test/run-pass/assert-eq-macro-success.rs +++ b/src/test/run-pass/assert-eq-macro-success.rs @@ -14,7 +14,7 @@ struct Point { x : int } pub fn main() { assert_eq!(14,14); assert_eq!("abc".to_owned(),"abc".to_owned()); - assert_eq!(~Point{x:34},~Point{x:34}); + assert_eq!(box Point{x:34},box Point{x:34}); assert_eq!(&Point{x:34},&Point{x:34}); assert_eq!(@Point{x:34},@Point{x:34}); } diff --git a/src/test/run-pass/auto-ref-slice-plus-ref.rs b/src/test/run-pass/auto-ref-slice-plus-ref.rs index 2c3e6c6f04e84..626f19b51085d 100644 --- a/src/test/run-pass/auto-ref-slice-plus-ref.rs +++ b/src/test/run-pass/auto-ref-slice-plus-ref.rs @@ -26,8 +26,6 @@ impl<'a> MyIter for &'a str { } pub fn main() { - // NB: Associativity of ~, etc. in this context is surprising. These must be parenthesized - ([1]).test_imm(); (vec!(1)).as_slice().test_imm(); (&[1]).test_imm(); diff --git a/src/test/run-pass/autoderef-method-on-trait.rs b/src/test/run-pass/autoderef-method-on-trait.rs index 6f0bba72025f4..e50825a401fc6 100644 --- a/src/test/run-pass/autoderef-method-on-trait.rs +++ b/src/test/run-pass/autoderef-method-on-trait.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait double { fn double(~self) -> uint; } @@ -17,6 +18,6 @@ impl double for uint { } pub fn main() { - let x = ~(~3u as ~double); + let x = box() (box 3u as Box); assert_eq!(x.double(), 6u); } diff --git a/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs b/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs index a03ac80a3f16b..7acd54788a8c2 100644 --- a/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs +++ b/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs @@ -8,15 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait double { fn double(~self) -> uint; } -impl double for ~uint { +impl double for Box { fn double(~self) -> uint { **self * 2u } } pub fn main() { - let x = ~~~~~3u; + let x = box box box box box 3u; assert_eq!(x.double(), 6u); } diff --git a/src/test/run-pass/autoderef-method-twice.rs b/src/test/run-pass/autoderef-method-twice.rs index 7835eaae510d3..a8b6b6f74f4ff 100644 --- a/src/test/run-pass/autoderef-method-twice.rs +++ b/src/test/run-pass/autoderef-method-twice.rs @@ -17,6 +17,6 @@ impl double for uint { } pub fn main() { - let x = ~~3u; + let x = box box 3u; assert_eq!(x.double(), 6u); } diff --git a/src/test/run-pass/autoderef-method.rs b/src/test/run-pass/autoderef-method.rs index 81469e5454a88..4c4ebdc94f030 100644 --- a/src/test/run-pass/autoderef-method.rs +++ b/src/test/run-pass/autoderef-method.rs @@ -17,6 +17,6 @@ impl double for uint { } pub fn main() { - let x = ~3u; + let x = box 3u; assert_eq!(x.double(), 6u); } diff --git a/src/test/run-pass/bitv-perf-test.rs b/src/test/run-pass/bitv-perf-test.rs index 658c888b8d83a..0f114969420c2 100644 --- a/src/test/run-pass/bitv-perf-test.rs +++ b/src/test/run-pass/bitv-perf-test.rs @@ -13,8 +13,8 @@ extern crate collections; use collections::Bitv; fn bitv_test() { - let mut v1 = ~Bitv::new(31, false); - let v2 = ~Bitv::new(31, true); + let mut v1 = box Bitv::new(31, false); + let v2 = box Bitv::new(31, true); v1.union(v2); } diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index 66b9d0430a126..2db2f8c16e06b 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -10,11 +10,12 @@ #![feature(managed_boxes)] + fn borrow(x: &int, f: |x: &int|) { f(x) } -fn test1(x: @~int) { +fn test1(x: @Box) { borrow(&*(*x).clone(), |p| { let x_a = &**x as *int; assert!((x_a as uint) != (p as *int as uint)); @@ -23,5 +24,5 @@ fn test1(x: @~int) { } pub fn main() { - test1(@~22); + test1(@box 22); } diff --git a/src/test/run-pass/borrowck-lend-args.rs b/src/test/run-pass/borrowck-lend-args.rs index a912e1ef65c42..68d1b74e2019b 100644 --- a/src/test/run-pass/borrowck-lend-args.rs +++ b/src/test/run-pass/borrowck-lend-args.rs @@ -8,17 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + fn borrow(_v: &int) {} -fn borrow_from_arg_imm_ref(v: ~int) { +fn borrow_from_arg_imm_ref(v: Box) { borrow(v); } -fn borrow_from_arg_mut_ref(v: &mut ~int) { +fn borrow_from_arg_mut_ref(v: &mut Box) { borrow(*v); } -fn borrow_from_arg_copy(v: ~int) { +fn borrow_from_arg_copy(v: Box) { borrow(v); } diff --git a/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs b/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs index 881a5b4d3f6ff..10835730fa54e 100644 --- a/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs +++ b/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs @@ -13,24 +13,25 @@ #![feature(macro_rules)] + struct Foo { a: int } pub enum Bar { - Bar1, Bar2(int, ~Bar), + Bar1, Bar2(int, Box), } impl Foo { - fn elaborate_stm(&mut self, s: ~Bar) -> ~Bar { + fn elaborate_stm(&mut self, s: Box) -> Box { macro_rules! declare( ($id:expr, $rest:expr) => ({ self.check_id($id); - ~Bar2($id, $rest) + box Bar2($id, $rest) }) ); match s { - ~Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)), + box Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)), _ => fail!() } } diff --git a/src/test/run-pass/borrowck-move-by-capture-ok.rs b/src/test/run-pass/borrowck-move-by-capture-ok.rs index 8ceef83094876..48ddf927722a3 100644 --- a/src/test/run-pass/borrowck-move-by-capture-ok.rs +++ b/src/test/run-pass/borrowck-move-by-capture-ok.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let bar = ~3; + let bar = box 3; let h: proc() -> int = proc() *bar; assert_eq!(h(), 3); } diff --git a/src/test/run-pass/borrowck-mut-uniq.rs b/src/test/run-pass/borrowck-mut-uniq.rs index bed6fcd0091af..ea849ee9829e9 100644 --- a/src/test/run-pass/borrowck-mut-uniq.rs +++ b/src/test/run-pass/borrowck-mut-uniq.rs @@ -10,7 +10,7 @@ use std::mem::swap; -struct Ints {sum: ~int, values: Vec } +struct Ints {sum: Box, values: Vec } fn add_int(x: &mut Ints, v: int) { *x.sum += v; @@ -26,7 +26,7 @@ fn iter_ints(x: &Ints, f: |x: &int| -> bool) -> bool { } pub fn main() { - let mut ints = ~Ints {sum: ~0, values: Vec::new()}; + let mut ints = box Ints {sum: box 0, values: Vec::new()}; add_int(ints, 22); add_int(ints, 44); diff --git a/src/test/run-pass/borrowck-uniq-via-ref.rs b/src/test/run-pass/borrowck-uniq-via-ref.rs index d50b4f15f4efe..451f9ccf5bd6d 100644 --- a/src/test/run-pass/borrowck-uniq-via-ref.rs +++ b/src/test/run-pass/borrowck-uniq-via-ref.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Rec { - f: ~int, + f: Box, } struct Outer { @@ -21,12 +22,12 @@ struct Inner { } struct Innermost { - h: ~int, + h: Box, } fn borrow(_v: &int) {} -fn box_mut(v: &mut ~int) { +fn box_mut(v: &mut Box) { borrow(*v); // OK: &mut -> &imm } @@ -38,7 +39,7 @@ fn box_mut_recs(v: &mut Outer) { borrow(v.f.g.h); // OK: &mut -> &imm } -fn box_imm(v: &~int) { +fn box_imm(v: &Box) { borrow(*v); // OK } diff --git a/src/test/run-pass/cancel-clean-via-immediate-rvalue-ref.rs b/src/test/run-pass/cancel-clean-via-immediate-rvalue-ref.rs index 2b9e97be2c7ef..d326c20707d9f 100644 --- a/src/test/run-pass/cancel-clean-via-immediate-rvalue-ref.rs +++ b/src/test/run-pass/cancel-clean-via-immediate-rvalue-ref.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: &mut ~u8) { - *x = ~5; + +fn foo(x: &mut Box) { + *x = box 5; } pub fn main() { - foo(&mut ~4); + foo(&mut box 4); } diff --git a/src/test/run-pass/capturing-logging.rs b/src/test/run-pass/capturing-logging.rs index 3859ed3a53d3e..e0e60289f9dbf 100644 --- a/src/test/run-pass/capturing-logging.rs +++ b/src/test/run-pass/capturing-logging.rs @@ -17,9 +17,9 @@ extern crate log; extern crate native; +use log::{set_logger, Logger, LogRecord}; use std::fmt; use std::io::{ChanReader, ChanWriter}; -use log::{set_logger, Logger, LogRecord}; struct MyWriter(ChanWriter); @@ -41,7 +41,7 @@ fn main() { let (tx, rx) = channel(); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); spawn(proc() { - set_logger(~MyWriter(w) as ~Logger:Send); + set_logger(box MyWriter(w) as Box); debug!("debug"); info!("info"); }); diff --git a/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs b/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs index 85c3c5d518ed1..c6c78283e19f5 100644 --- a/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs +++ b/src/test/run-pass/class-cast-to-trait-cross-crate-2.rs @@ -10,16 +10,17 @@ // aux-build:cci_class_cast.rs extern crate cci_class_cast; + use std::to_str::ToStr; use cci_class_cast::kitty::cat; -fn print_out(thing: ~ToStr, expected: ~str) { +fn print_out(thing: Box, expected: ~str) { let actual = thing.to_str(); println!("{}", actual); assert_eq!(actual, expected); } pub fn main() { - let nyan: ~ToStr = ~cat(0u, 2, "nyan".to_owned()) as ~ToStr; + let nyan: Box = box cat(0u, 2, "nyan".to_owned()) as Box; print_out(nyan, "nyan".to_owned()); } diff --git a/src/test/run-pass/class-separate-impl.rs b/src/test/run-pass/class-separate-impl.rs index 0f1e8aa2724b8..417c927701d32 100644 --- a/src/test/run-pass/class-separate-impl.rs +++ b/src/test/run-pass/class-separate-impl.rs @@ -57,13 +57,13 @@ impl fmt::Show for cat { } } -fn print_out(thing: ~ToStr, expected: ~str) { +fn print_out(thing: Box, expected: ~str) { let actual = thing.to_str(); println!("{}", actual); assert_eq!(actual, expected); } pub fn main() { - let nyan: ~ToStr = ~cat(0u, 2, "nyan".to_owned()) as ~ToStr; + let nyan: Box = box cat(0u, 2, "nyan".to_owned()) as Box; print_out(nyan, "nyan".to_owned()); } diff --git a/src/test/run-pass/cleanup-arm-conditional.rs b/src/test/run-pass/cleanup-arm-conditional.rs index 360f94564b748..65ad68ba702f4 100644 --- a/src/test/run-pass/cleanup-arm-conditional.rs +++ b/src/test/run-pass/cleanup-arm-conditional.rs @@ -26,8 +26,8 @@ use std::os; struct Test { x: int } impl Test { - fn get_x(&self) -> Option<~int> { - Some(~self.x) + fn get_x(&self) -> Option> { + Some(box self.x) } } diff --git a/src/test/run-pass/cleanup-rvalue-during-if-and-while.rs b/src/test/run-pass/cleanup-rvalue-during-if-and-while.rs index 1ae907065bfac..89b0010208132 100644 --- a/src/test/run-pass/cleanup-rvalue-during-if-and-while.rs +++ b/src/test/run-pass/cleanup-rvalue-during-if-and-while.rs @@ -12,6 +12,7 @@ // This test verifies that temporaries created for `while`'s and `if` // conditions are dropped after the condition is evaluated. + struct Temporary; static mut DROPPED: int = 0; @@ -26,7 +27,7 @@ impl Temporary { fn do_stuff(&self) -> bool {true} } -fn borrow() -> ~Temporary { ~Temporary } +fn borrow() -> Box { box Temporary } pub fn main() { diff --git a/src/test/run-pass/cleanup-rvalue-scopes.rs b/src/test/run-pass/cleanup-rvalue-scopes.rs index f6f0da745ab74..470e16b4888a7 100644 --- a/src/test/run-pass/cleanup-rvalue-scopes.rs +++ b/src/test/run-pass/cleanup-rvalue-scopes.rs @@ -111,8 +111,8 @@ pub fn main() { end_of_block!(AddFlags { bits: ref _x }, AddFlags(1)); end_of_block!(&AddFlags { bits }, &AddFlags(1)); end_of_block!((_, ref _y), (AddFlags(1), 22)); - end_of_block!(~ref _x, ~AddFlags(1)); - end_of_block!(~_x, ~AddFlags(1)); + end_of_block!(box ref _x, box AddFlags(1)); + end_of_block!(box _x, box AddFlags(1)); end_of_block!(_, { { check_flags(0); &AddFlags(1) } }); end_of_block!(_, &((Box { f: AddFlags(1) }).f)); end_of_block!(_, &(([AddFlags(1)])[0])); diff --git a/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs b/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs index 8c906bf96b69f..fda4a31375bcd 100644 --- a/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs +++ b/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs @@ -8,16 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Test cleanup of rvalue temporary that occurs while `~` construction +// Test cleanup of rvalue temporary that occurs while `box` construction // is in progress. This scenario revealed a rather terrible bug. The // ingredients are: // -// 1. Partial cleanup of `~` is in scope, +// 1. Partial cleanup of `box` is in scope, // 2. cleanup of return value from `get_bar()` is in scope, // 3. do_it() fails. // // This led to a bug because `the top-most frame that was to be -// cleaned (which happens to be the partial cleanup of `~`) required +// cleaned (which happens to be the partial cleanup of `box`) required // multiple basic blocks, which led to us dropping part of the cleanup // from the top-most frame. // @@ -30,7 +30,7 @@ enum Conzabble { Bickwick(Foo) } -struct Foo { field: ~uint } +struct Foo { field: Box } fn do_it(x: &[uint]) -> Foo { fail!() @@ -41,7 +41,7 @@ fn get_bar(x: uint) -> Vec { vec!(x * 2) } pub fn fails() { let x = 2; let mut y = Vec::new(); - y.push(~Bickwick(do_it(get_bar(x).as_slice()))); + y.push(box Bickwick(do_it(get_bar(x).as_slice()))); } pub fn main() { diff --git a/src/test/run-pass/clone-with-exterior.rs b/src/test/run-pass/clone-with-exterior.rs index 038c0418ecb4c..f676a6f09594e 100644 --- a/src/test/run-pass/clone-with-exterior.rs +++ b/src/test/run-pass/clone-with-exterior.rs @@ -16,7 +16,7 @@ struct Pair { } pub fn main() { - let z = ~Pair { a : 10, b : 12}; + let z = box Pair { a : 10, b : 12}; let f: proc():Send = proc() { assert_eq!(z.a, 10); diff --git a/src/test/run-pass/close-over-big-then-small-data.rs b/src/test/run-pass/close-over-big-then-small-data.rs index c57b6fdf38495..3e14d5b82c47d 100644 --- a/src/test/run-pass/close-over-big-then-small-data.rs +++ b/src/test/run-pass/close-over-big-then-small-data.rs @@ -12,6 +12,7 @@ // storing closure data (as we used to do), the u64 would // overwrite the u16. + struct Pair { a: A, b: B } @@ -31,11 +32,11 @@ impl Invokable for Invoker { } } -fn f(a: A, b: u16) -> ~Invokable: { - ~Invoker { +fn f(a: A, b: u16) -> Box:> { + box Invoker { a: a, b: b, - } as ~Invokable: + } as Box>: } pub fn main() { diff --git a/src/test/run-pass/const-bound.rs b/src/test/run-pass/const-bound.rs index ff47f078da300..c864db33b21ad 100644 --- a/src/test/run-pass/const-bound.rs +++ b/src/test/run-pass/const-bound.rs @@ -23,5 +23,5 @@ pub fn main() { foo(F{field: 42}); foo((1, 2u)); foo(@1);*/ - foo(~1); + foo(box 1); } diff --git a/src/test/run-pass/empty-allocation-non-null.rs b/src/test/run-pass/empty-allocation-non-null.rs index 9695296ec1561..a6baf21549e58 100644 --- a/src/test/run-pass/empty-allocation-non-null.rs +++ b/src/test/run-pass/empty-allocation-non-null.rs @@ -9,10 +9,10 @@ // except according to those terms. pub fn main() { - assert!(Some(~()).is_some()); + assert!(Some(box() ()).is_some()); struct Foo; - assert!(Some(~Foo).is_some()); + assert!(Some(box Foo).is_some()); let xs: ~[()] = ~[]; assert!(Some(xs).is_some()); diff --git a/src/test/run-pass/empty-allocation-rvalue-non-null.rs b/src/test/run-pass/empty-allocation-rvalue-non-null.rs index a5fc8425cf6b0..96c5f81558e39 100644 --- a/src/test/run-pass/empty-allocation-rvalue-non-null.rs +++ b/src/test/run-pass/empty-allocation-rvalue-non-null.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - let x = *~(); + let x = *box() (); } diff --git a/src/test/run-pass/enum-nullable-const-null-with-fields.rs b/src/test/run-pass/enum-nullable-const-null-with-fields.rs index 5defd83702225..a48f3bcd59ca4 100644 --- a/src/test/run-pass/enum-nullable-const-null-with-fields.rs +++ b/src/test/run-pass/enum-nullable-const-null-with-fields.rs @@ -9,7 +9,8 @@ // except according to those terms. use std::result::{Result,Ok}; -static C: Result<(), ~int> = Ok(()); + +static C: Result<(), Box> = Ok(()); // This is because of yet another bad assertion (ICE) about the null side of a nullable enum. // So we won't actually compile if the bug is present, but we check the value in main anyway. diff --git a/src/test/run-pass/explicit-self-generic.rs b/src/test/run-pass/explicit-self-generic.rs index 30b716f75d8df..ac2922e92d42c 100644 --- a/src/test/run-pass/explicit-self-generic.rs +++ b/src/test/run-pass/explicit-self-generic.rs @@ -37,6 +37,6 @@ impl HashMap { } pub fn main() { - let mut m = ~linear_map::<(),()>(); + let mut m = box linear_map::<(),()>(); assert_eq!(m.len(), 0); } diff --git a/src/test/run-pass/explicit-self-objects-uniq.rs b/src/test/run-pass/explicit-self-objects-uniq.rs index 69ca98eb018ed..595bb4f6b9e44 100644 --- a/src/test/run-pass/explicit-self-objects-uniq.rs +++ b/src/test/run-pass/explicit-self-objects-uniq.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { fn f(~self); } @@ -23,7 +24,7 @@ impl Foo for S { } pub fn main() { - let x = ~S { x: 3 }; - let y = x as ~Foo; + let x = box S { x: 3 }; + let y = x as Box; y.f(); } diff --git a/src/test/run-pass/explicit-self.rs b/src/test/run-pass/explicit-self.rs index 1076fc1662fa2..6c2e17046d3c1 100644 --- a/src/test/run-pass/explicit-self.rs +++ b/src/test/run-pass/explicit-self.rs @@ -67,7 +67,7 @@ trait Nus { fn f(&self); } impl Nus for thing { fn f(&self) {} } pub fn main() { - let y = ~thing(A {a: 10}); + let y = box thing(A {a: 10}); assert_eq!(y.clone().bar(), 10); assert_eq!(y.quux(), 10); diff --git a/src/test/run-pass/expr-block-generic-unique1.rs b/src/test/run-pass/expr-block-generic-unique1.rs index 95f3ff62d2697..ec5013122acae 100644 --- a/src/test/run-pass/expr-block-generic-unique1.rs +++ b/src/test/run-pass/expr-block-generic-unique1.rs @@ -9,21 +9,20 @@ // except according to those terms. +type compare<'a, T> = |Box, Box|: 'a -> bool; -type compare<'a, T> = |~T, ~T|: 'a -> bool; - -fn test_generic(expected: ~T, eq: compare) { - let actual: ~T = { expected.clone() }; +fn test_generic(expected: Box, eq: compare) { + let actual: Box = { expected.clone() }; assert!((eq(expected, actual))); } fn test_box() { - fn compare_box(b1: ~bool, b2: ~bool) -> bool { + fn compare_box(b1: Box, b2: Box) -> bool { println!("{}", *b1); println!("{}", *b2); return *b1 == *b2; } - test_generic::(~true, compare_box); + test_generic::(box true, compare_box); } pub fn main() { test_box(); } diff --git a/src/test/run-pass/expr-block-generic-unique2.rs b/src/test/run-pass/expr-block-generic-unique2.rs index f45312f9e09d3..48e27dc449cba 100644 --- a/src/test/run-pass/expr-block-generic-unique2.rs +++ b/src/test/run-pass/expr-block-generic-unique2.rs @@ -17,8 +17,8 @@ fn test_generic(expected: T, eq: compare) { } fn test_vec() { - fn compare_vec(v1: ~int, v2: ~int) -> bool { return v1 == v2; } - test_generic::<~int>(~1, compare_vec); + fn compare_vec(v1: Box, v2: Box) -> bool { return v1 == v2; } + test_generic::>(box 1, compare_vec); } pub fn main() { test_vec(); } diff --git a/src/test/run-pass/expr-block-unique.rs b/src/test/run-pass/expr-block-unique.rs index 6ef7ffe86fa18..12777bce710b5 100644 --- a/src/test/run-pass/expr-block-unique.rs +++ b/src/test/run-pass/expr-block-unique.rs @@ -11,4 +11,4 @@ -pub fn main() { let x = { ~100 }; assert!((*x == 100)); } +pub fn main() { let x = { box 100 }; assert!((*x == 100)); } diff --git a/src/test/run-pass/expr-if-unique.rs b/src/test/run-pass/expr-if-unique.rs index b40dc03ccfb9b..aa96a93cdb302 100644 --- a/src/test/run-pass/expr-if-unique.rs +++ b/src/test/run-pass/expr-if-unique.rs @@ -14,7 +14,7 @@ // Tests for if as expressions returning boxed types fn test_box() { - let rs = if true { ~100 } else { ~101 }; + let rs = if true { box 100 } else { box 101 }; assert_eq!(*rs, 100); } diff --git a/src/test/run-pass/expr-match-generic-unique1.rs b/src/test/run-pass/expr-match-generic-unique1.rs index 991a1f449f191..e2f8f7c8ebf0a 100644 --- a/src/test/run-pass/expr-match-generic-unique1.rs +++ b/src/test/run-pass/expr-match-generic-unique1.rs @@ -9,11 +9,10 @@ // except according to those terms. +type compare = |Box, Box|: 'static -> bool; -type compare = |~T, ~T|: 'static -> bool; - -fn test_generic(expected: ~T, eq: compare) { - let actual: ~T = match true { +fn test_generic(expected: Box, eq: compare) { + let actual: Box = match true { true => { expected.clone() }, _ => fail!("wat") }; @@ -21,8 +20,10 @@ fn test_generic(expected: ~T, eq: compare) { } fn test_box() { - fn compare_box(b1: ~bool, b2: ~bool) -> bool { return *b1 == *b2; } - test_generic::(~true, compare_box); + fn compare_box(b1: Box, b2: Box) -> bool { + return *b1 == *b2; + } + test_generic::(box true, compare_box); } pub fn main() { test_box(); } diff --git a/src/test/run-pass/expr-match-generic-unique2.rs b/src/test/run-pass/expr-match-generic-unique2.rs index d229672d05729..a9b02a6e79938 100644 --- a/src/test/run-pass/expr-match-generic-unique2.rs +++ b/src/test/run-pass/expr-match-generic-unique2.rs @@ -20,8 +20,8 @@ fn test_generic(expected: T, eq: compare) { } fn test_vec() { - fn compare_box(v1: ~int, v2: ~int) -> bool { return v1 == v2; } - test_generic::<~int>(~1, compare_box); + fn compare_box(v1: Box, v2: Box) -> bool { return v1 == v2; } + test_generic::>(box 1, compare_box); } pub fn main() { test_vec(); } diff --git a/src/test/run-pass/expr-match-unique.rs b/src/test/run-pass/expr-match-unique.rs index 85c6652c5aab3..ca6e8799eae7a 100644 --- a/src/test/run-pass/expr-match-unique.rs +++ b/src/test/run-pass/expr-match-unique.rs @@ -9,12 +9,9 @@ // except according to those terms. - - - // Tests for match as expressions resulting in boxed types fn test_box() { - let res = match true { true => { ~100 }, _ => fail!() }; + let res = match true { true => { box 100 }, _ => fail!() }; assert_eq!(*res, 100); } diff --git a/src/test/run-pass/fsu-moves-and-copies.rs b/src/test/run-pass/fsu-moves-and-copies.rs index 571ef4bd7b4a4..0e6b857d7cf52 100644 --- a/src/test/run-pass/fsu-moves-and-copies.rs +++ b/src/test/run-pass/fsu-moves-and-copies.rs @@ -21,9 +21,9 @@ impl NoFoo { fn new(x:int,y:int) -> NoFoo { NoFoo { copied: x, nocopy: ncint(y) } } } -struct MoveFoo { copied: int, moved: ~int, } +struct MoveFoo { copied: int, moved: Box, } impl MoveFoo { - fn new(x:int,y:int) -> MoveFoo { MoveFoo { copied: x, moved: ~y } } + fn new(x:int,y:int) -> MoveFoo { MoveFoo { copied: x, moved: box y } } } struct DropNoFoo { inner: NoFoo } @@ -59,8 +59,8 @@ fn test0() { // Case 2: Owned let f = DropMoveFoo::new(5, 6); - let b = DropMoveFoo { inner: MoveFoo { moved: ~7, ..f.inner }}; - let c = DropMoveFoo { inner: MoveFoo { moved: ~8, ..f.inner }}; + let b = DropMoveFoo { inner: MoveFoo { moved: box 7, ..f.inner }}; + let c = DropMoveFoo { inner: MoveFoo { moved: box 8, ..f.inner }}; assert_eq!(f.inner.copied, 5); assert_eq!(*f.inner.moved, 6); @@ -75,7 +75,7 @@ fn test1() { // copying move-by-default fields from `f`, so it moves: let f = MoveFoo::new(11, 12); - let b = MoveFoo {moved: ~13, ..f}; + let b = MoveFoo {moved: box 13, ..f}; let c = MoveFoo {copied: 14, ..f}; assert_eq!(b.copied, 11); assert_eq!(*b.moved, 13); diff --git a/src/test/run-pass/func-arg-incomplete-pattern.rs b/src/test/run-pass/func-arg-incomplete-pattern.rs index 6dc9ef2fa4bbf..5ab3930e7a39a 100644 --- a/src/test/run-pass/func-arg-incomplete-pattern.rs +++ b/src/test/run-pass/func-arg-incomplete-pattern.rs @@ -11,9 +11,10 @@ // Test that we do not leak when the arg pattern must drop part of the // argument (in this case, the `y` field). + struct Foo { - x: ~uint, - y: ~uint, + x: Box, + y: Box, } fn foo(Foo {x, ..}: Foo) -> *uint { @@ -22,9 +23,9 @@ fn foo(Foo {x, ..}: Foo) -> *uint { } pub fn main() { - let obj = ~1; + let obj = box 1; let objptr: *uint = &*obj; - let f = Foo {x: obj, y: ~2}; + let f = Foo {x: obj, y: box 2}; let xptr = foo(f); assert_eq!(objptr, xptr); } diff --git a/src/test/run-pass/func-arg-ref-pattern.rs b/src/test/run-pass/func-arg-ref-pattern.rs index 11df22d7433d6..bb4be948a5ee0 100644 --- a/src/test/run-pass/func-arg-ref-pattern.rs +++ b/src/test/run-pass/func-arg-ref-pattern.rs @@ -10,25 +10,26 @@ // exec-env:RUST_POISON_ON_FREE=1 -// Test argument patterns where we create refs to the inside of `~` +// Test argument patterns where we create refs to the inside of // boxes. Make sure that we don't free the box as we match the // pattern. -fn getaddr(~ref x: ~uint) -> *uint { + +fn getaddr(box ref x: Box) -> *uint { let addr: *uint = &*x; addr } -fn checkval(~ref x: ~uint) -> uint { +fn checkval(box ref x: Box) -> uint { *x } pub fn main() { - let obj = ~1; + let obj = box 1; let objptr: *uint = &*obj; let xptr = getaddr(obj); assert_eq!(objptr, xptr); - let obj = ~22; + let obj = box 22; assert_eq!(checkval(obj), 22); } diff --git a/src/test/run-pass/generic-alias-unique.rs b/src/test/run-pass/generic-alias-unique.rs index 898d0c0ec2317..f13383589035c 100644 --- a/src/test/run-pass/generic-alias-unique.rs +++ b/src/test/run-pass/generic-alias-unique.rs @@ -9,12 +9,11 @@ // except according to those terms. - fn id(t: T) -> T { return t; } pub fn main() { - let expected = ~100; - let actual = id::<~int>(expected.clone()); + let expected = box 100; + let actual = id::>(expected.clone()); println!("{:?}", *actual); assert_eq!(*expected, *actual); } diff --git a/src/test/run-pass/generic-exterior-unique.rs b/src/test/run-pass/generic-exterior-unique.rs index 0820923efcfec..0746c994c2a6b 100644 --- a/src/test/run-pass/generic-exterior-unique.rs +++ b/src/test/run-pass/generic-exterior-unique.rs @@ -8,9 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Recbox {x: ~T} -fn reclift(t: T) -> Recbox { return Recbox {x: ~t}; } +struct Recbox {x: Box} + +fn reclift(t: T) -> Recbox { return Recbox {x: box t}; } pub fn main() { let foo: int = 17; diff --git a/src/test/run-pass/generic-fn-unique.rs b/src/test/run-pass/generic-fn-unique.rs index c27aff53b6797..c0b3fd5bc94b0 100644 --- a/src/test/run-pass/generic-fn-unique.rs +++ b/src/test/run-pass/generic-fn-unique.rs @@ -9,6 +9,6 @@ // except according to those terms. -fn f(x: ~T) -> ~T { return x; } +fn f(x: Box) -> Box { return x; } -pub fn main() { let x = f(~3); println!("{:?}", *x); } +pub fn main() { let x = f(box 3); println!("{:?}", *x); } diff --git a/src/test/run-pass/generic-object.rs b/src/test/run-pass/generic-object.rs index 76db4a01829ab..d0a5af8e2cecf 100644 --- a/src/test/run-pass/generic-object.rs +++ b/src/test/run-pass/generic-object.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { fn get(&self) -> T; } @@ -23,7 +24,7 @@ impl Foo for S { } pub fn main() { - let x = ~S { x: 1 }; - let y = x as ~Foo; + let x = box S { x: 1 }; + let y = x as Box>; assert_eq!(y.get(), 1); } diff --git a/src/test/run-pass/generic-unique.rs b/src/test/run-pass/generic-unique.rs index 3b817b314cf14..4821b9354bfda 100644 --- a/src/test/run-pass/generic-unique.rs +++ b/src/test/run-pass/generic-unique.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Triple { x: T, y: T, z: T } -fn box_it(x: Triple) -> ~Triple { return ~x; } +fn box_it(x: Triple) -> Box> { return box x; } pub fn main() { - let x: ~Triple = box_it::(Triple{x: 1, y: 2, z: 3}); + let x: Box> = box_it::(Triple{x: 1, y: 2, z: 3}); assert_eq!(x.y, 2); } diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 16b21f5f53729..9227477c31e91 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -40,7 +40,7 @@ pub fn main() { t!(format!("{:?}", 1), "1"); t!(format!("{:?}", A), "A"); t!(format!("{:?}", ()), "()"); - t!(format!("{:?}", @(~1, "foo")), "@(~1, \"foo\")"); + t!(format!("{:?}", @(box 1, "foo")), "@(box 1, \"foo\")"); // Various edge cases without formats t!(format!(""), ""); @@ -142,7 +142,7 @@ pub fn main() { test_order(); // make sure that format! doesn't move out of local variables - let a = ~3; + let a = box 3; format!("{:?}", a); format!("{:?}", a); diff --git a/src/test/run-pass/init-res-into-things.rs b/src/test/run-pass/init-res-into-things.rs index 4c1455e25cbc8..c573ca9184071 100644 --- a/src/test/run-pass/init-res-into-things.rs +++ b/src/test/run-pass/init-res-into-things.rs @@ -73,7 +73,7 @@ fn test_tup() { fn test_unique() { let i = @Cell::new(0); { - let _a = ~r(i); + let _a = box r(i); } assert_eq!(i.get(), 1); } diff --git a/src/test/run-pass/intrinsic-atomics.rs b/src/test/run-pass/intrinsic-atomics.rs index b663cbfa50974..8fa89303fa950 100644 --- a/src/test/run-pass/intrinsic-atomics.rs +++ b/src/test/run-pass/intrinsic-atomics.rs @@ -36,7 +36,7 @@ mod rusti { pub fn main() { unsafe { - let mut x = ~1; + let mut x = box 1; assert_eq!(rusti::atomic_load(&*x), 1); *x = 5; diff --git a/src/test/run-pass/intrinsic-move-val.rs b/src/test/run-pass/intrinsic-move-val.rs index f42d5ff2e5267..5f5c1444819d2 100644 --- a/src/test/run-pass/intrinsic-move-val.rs +++ b/src/test/run-pass/intrinsic-move-val.rs @@ -19,7 +19,7 @@ mod rusti { pub fn main() { unsafe { - let x = ~1; + let x = box 1; let mut y = rusti::init(); let mut z: *uint = transmute(&x); rusti::move_val_init(&mut y, x); diff --git a/src/test/run-pass/issue-10682.rs b/src/test/run-pass/issue-10682.rs index 461167d5ea4e7..f2f8b17daa264 100644 --- a/src/test/run-pass/issue-10682.rs +++ b/src/test/run-pass/issue-10682.rs @@ -11,10 +11,11 @@ // Regression test for issue #10682 // Nested `proc` usage can't use outer owned data -fn work(_: ~int) {} + +fn work(_: Box) {} fn foo(_: proc()) {} pub fn main() { - let a = ~1; + let a = box 1; foo(proc() { foo(proc() { work(a) }) }) } diff --git a/src/test/run-pass/issue-10767.rs b/src/test/run-pass/issue-10767.rs index 3254f5bc35f90..a30eb8120eae1 100644 --- a/src/test/run-pass/issue-10767.rs +++ b/src/test/run-pass/issue-10767.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + pub fn main() { fn f() { }; - let _: ~fn() = ~f; + let _: Box = box f; } diff --git a/src/test/run-pass/issue-10802.rs b/src/test/run-pass/issue-10802.rs index b7b65c9de0a6c..6c4f0cc7f5f20 100644 --- a/src/test/run-pass/issue-10802.rs +++ b/src/test/run-pass/issue-10802.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct DroppableStruct; static mut DROPPED: bool = false; @@ -19,19 +20,19 @@ impl Drop for DroppableStruct { } trait MyTrait { } -impl MyTrait for ~DroppableStruct {} +impl MyTrait for Box {} -struct Whatever { w: ~MyTrait } +struct Whatever { w: Box } impl Whatever { - fn new(w: ~MyTrait) -> Whatever { + fn new(w: Box) -> Whatever { Whatever { w: w } } } fn main() { { - let f = ~DroppableStruct; - let _a = Whatever::new(~f as ~MyTrait); + let f = box DroppableStruct; + let _a = Whatever::new(box f as Box); } assert!(unsafe { DROPPED }); } diff --git a/src/test/run-pass/issue-11552.rs b/src/test/run-pass/issue-11552.rs index 418bf5f0f9a2a..42b5bbc8623e4 100644 --- a/src/test/run-pass/issue-11552.rs +++ b/src/test/run-pass/issue-11552.rs @@ -8,22 +8,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + #[deriving(Clone)] enum Noun { Atom(int), - Cell(~Noun, ~Noun) + Cell(Box, Box) } fn fas(n: &Noun) -> Noun { - match n - { - &Cell(~Atom(2), ~Cell(ref a, _)) => (**a).clone(), + match n { + &Cell(box Atom(2), box Cell(ref a, _)) => (**a).clone(), _ => fail!("Invalid fas pattern") } } pub fn main() { - fas(&Cell(~Atom(2), ~Cell(~Atom(2), ~Atom(3)))); + fas(&Cell(box Atom(2), box Cell(box Atom(2), box Atom(3)))); } diff --git a/src/test/run-pass/issue-2288.rs b/src/test/run-pass/issue-2288.rs index 9e03023a9e9ba..85dd879c830ce 100644 --- a/src/test/run-pass/issue-2288.rs +++ b/src/test/run-pass/issue-2288.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait clam { fn chowder(&self, y: A); } @@ -26,13 +27,13 @@ fn foo(b: A) -> foo { } } -fn f(x: ~clam, a: A) { +fn f(x: Box>, a: A) { x.chowder(a); } pub fn main() { let c = foo(42); - let d: ~clam = ~c as ~clam; + let d: Box> = box c as Box>; f(d, c.x); } diff --git a/src/test/run-pass/issue-2633-2.rs b/src/test/run-pass/issue-2633-2.rs index 71a491b8a3955..42170bfe83240 100644 --- a/src/test/run-pass/issue-2633-2.rs +++ b/src/test/run-pass/issue-2633-2.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn a_val(x: ~int, y: ~int) -> int { + +fn a_val(x: Box, y: Box) -> int { *x + *y } pub fn main() { - let z = ~22; + let z = box 22; a_val(z.clone(), z.clone()); } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 0598fafd96e84..2b1ba332841cb 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -42,7 +42,7 @@ pub mod pipes { pub fn packet() -> *packet { unsafe { - let p: *packet = cast::transmute(~Stuff{ + let p: *packet = cast::transmute(box Stuff{ state: empty, blocked_task: None::, payload: None:: @@ -59,7 +59,7 @@ pub mod pipes { // We should consider moving this to ::std::unsafe, although I // suspect graydon would want us to use void pointers instead. - pub unsafe fn uniquify(x: *T) -> ~T { + pub unsafe fn uniquify(x: *T) -> Box { cast::transmute(x) } diff --git a/src/test/run-pass/issue-2734.rs b/src/test/run-pass/issue-2734.rs index faf3b090312d8..9f337ecfe37ce 100644 --- a/src/test/run-pass/issue-2734.rs +++ b/src/test/run-pass/issue-2734.rs @@ -8,17 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait hax { } impl hax for A { } -fn perform_hax(x: ~T) -> ~hax: { - ~x as ~hax: +fn perform_hax(x: Box) -> Box { + box x as Box } fn deadcode() { - perform_hax(~"deadcode".to_owned()); + perform_hax(box "deadcode".to_owned()); } pub fn main() { - let _ = perform_hax(~42); + let _ = perform_hax(box 42); } diff --git a/src/test/run-pass/issue-2735.rs b/src/test/run-pass/issue-2735.rs index af6dc66b95b58..bdaf8ac975504 100644 --- a/src/test/run-pass/issue-2735.rs +++ b/src/test/run-pass/issue-2735.rs @@ -8,17 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait hax { } impl hax for A { } -fn perform_hax(x: ~T) -> ~hax: { - ~x as ~hax: +fn perform_hax(x: Box) -> Box { + box x as Box } fn deadcode() { - perform_hax(~"deadcode".to_owned()); + perform_hax(box "deadcode".to_owned()); } pub fn main() { - perform_hax(~42); + perform_hax(box 42); } diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index 91e21dedd4972..dfd34fcf5918c 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -21,7 +21,7 @@ enum object { int_value(i64), } -fn lookup(table: ~json::Object, key: ~str, default: ~str) -> ~str +fn lookup(table: Box, key: ~str, default: ~str) -> ~str { match table.find(&key) { option::Some(&json::String(ref s)) => { diff --git a/src/test/run-pass/issue-2935.rs b/src/test/run-pass/issue-2935.rs index aeef29acd0eaf..cdc41e892f964 100644 --- a/src/test/run-pass/issue-2935.rs +++ b/src/test/run-pass/issue-2935.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + //type t = { a: int }; // type t = { a: bool }; type t = bool; @@ -22,10 +23,10 @@ impl it for t { pub fn main() { // let x = ({a: 4i} as it); - // let y = ~({a: 4i}); - // let z = ~({a: 4i} as it); - // let z = ~({a: true} as it); - let z = ~(~true as ~it); + // let y = box ({a: 4i}); + // let z = box ({a: 4i} as it); + // let z = box ({a: true} as it); + let z = box() (box true as Box); // x.f(); // y.f(); // (*z).f(); diff --git a/src/test/run-pass/issue-3026.rs b/src/test/run-pass/issue-3026.rs index 6c18193520582..9d18e176638ad 100644 --- a/src/test/run-pass/issue-3026.rs +++ b/src/test/run-pass/issue-3026.rs @@ -15,6 +15,6 @@ use collections::HashMap; pub fn main() { let mut buggy_map: HashMap = HashMap::new(); - let x = ~1; + let x = box 1; buggy_map.insert(42, &*x); } diff --git a/src/test/run-pass/issue-3290.rs b/src/test/run-pass/issue-3290.rs index f2beda5973323..00b78ee8e4057 100644 --- a/src/test/run-pass/issue-3290.rs +++ b/src/test/run-pass/issue-3290.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut x = ~3; + let mut x = box 3; x = x; assert_eq!(*x, 3); } diff --git a/src/test/run-pass/issue-3702.rs b/src/test/run-pass/issue-3702.rs index 43f2e764e6902..84414461e96c9 100644 --- a/src/test/run-pass/issue-3702.rs +++ b/src/test/run-pass/issue-3702.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + pub fn main() { trait Text { fn to_str(&self) -> ~str; } - fn to_string(t: ~Text) { + fn to_string(t: Box) { println!("{}", t.to_str()); } diff --git a/src/test/run-pass/issue-3794.rs b/src/test/run-pass/issue-3794.rs index 8cc7d275789e9..b08e6525ba513 100644 --- a/src/test/run-pass/issue-3794.rs +++ b/src/test/run-pass/issue-3794.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait T { fn print(&self); } @@ -31,9 +32,9 @@ fn print_s(s: &S) { } pub fn main() { - let s: ~S = ~S { s: 5 }; + let s: Box = box S { s: 5 }; print_s(s); - let t: ~T = s as ~T; + let t: Box = s as Box; print_t(t); } diff --git a/src/test/run-pass/issue-3878.rs b/src/test/run-pass/issue-3878.rs index 4330663db2599..1b09889c887fb 100644 --- a/src/test/run-pass/issue-3878.rs +++ b/src/test/run-pass/issue-3878.rs @@ -11,6 +11,6 @@ #![allow(path_statement)] pub fn main() { - let y = ~1; + let y = box 1; y; } diff --git a/src/test/run-pass/issue-4735.rs b/src/test/run-pass/issue-4735.rs index b23158522a308..e89e661e9d847 100644 --- a/src/test/run-pass/issue-4735.rs +++ b/src/test/run-pass/issue-4735.rs @@ -20,12 +20,12 @@ struct NonCopyable(*c_void); impl Drop for NonCopyable { fn drop(&mut self) { let NonCopyable(p) = *self; - let _v = unsafe { transmute::<*c_void, ~int>(p) }; + let _v = unsafe { transmute::<*c_void, Box>(p) }; } } pub fn main() { - let t = ~0; - let p = unsafe { transmute::<~int, *c_void>(t) }; + let t = box 0; + let p = unsafe { transmute::, *c_void>(t) }; let _z = NonCopyable(p); } diff --git a/src/test/run-pass/issue-4759.rs b/src/test/run-pass/issue-4759.rs index 45912039857fe..4b5c3566965f9 100644 --- a/src/test/run-pass/issue-4759.rs +++ b/src/test/run-pass/issue-4759.rs @@ -8,18 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct T { a: ~int } + +struct T { a: Box } trait U { fn f(self); } -impl U for ~int { +impl U for Box { fn f(self) { } } pub fn main() { - let T { a: a } = T { a: ~0 }; + let T { a: a } = T { a: box 0 }; a.f(); } diff --git a/src/test/run-pass/issue-4830.rs b/src/test/run-pass/issue-4830.rs index 168389bf2b879..7fc1c10895ef6 100644 --- a/src/test/run-pass/issue-4830.rs +++ b/src/test/run-pass/issue-4830.rs @@ -8,9 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + pub struct Scheduler { /// The event loop used to drive the scheduler and perform I/O - event_loop: ~int + event_loop: Box } pub fn main() { } diff --git a/src/test/run-pass/issue-5192.rs b/src/test/run-pass/issue-5192.rs index 202a3cbcafa2b..0dd6623a34907 100644 --- a/src/test/run-pass/issue-5192.rs +++ b/src/test/run-pass/issue-5192.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + pub trait EventLoop { } @@ -27,12 +28,12 @@ impl EventLoop for UvEventLoop { } pub struct Scheduler { - event_loop: ~EventLoop, + event_loop: Box, } impl Scheduler { - pub fn new(event_loop: ~EventLoop) -> Scheduler { + pub fn new(event_loop: Box) -> Scheduler { Scheduler { event_loop: event_loop, } @@ -40,5 +41,5 @@ impl Scheduler { } pub fn main() { - let _sched = Scheduler::new(~UvEventLoop::new() as ~EventLoop); + let _sched = Scheduler::new(box UvEventLoop::new() as Box); } diff --git a/src/test/run-pass/issue-5666.rs b/src/test/run-pass/issue-5666.rs index a6efa5954f116..a3dc1fae7f184 100644 --- a/src/test/run-pass/issue-5666.rs +++ b/src/test/run-pass/issue-5666.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Dog { name : ~str } @@ -24,9 +25,9 @@ impl Barks for Dog { pub fn main() { - let snoopy = ~Dog{name: "snoopy".to_owned()}; - let bubbles = ~Dog{name: "bubbles".to_owned()}; - let barker = [snoopy as ~Barks, bubbles as ~Barks]; + let snoopy = box Dog{name: "snoopy".to_owned()}; + let bubbles = box Dog{name: "bubbles".to_owned()}; + let barker = [snoopy as Box, bubbles as Box]; for pup in barker.iter() { println!("{}", pup.bark()); diff --git a/src/test/run-pass/issue-5884.rs b/src/test/run-pass/issue-5884.rs index 4a4c8a4011c2c..8d336c6e31b19 100644 --- a/src/test/run-pass/issue-5884.rs +++ b/src/test/run-pass/issue-5884.rs @@ -10,17 +10,18 @@ #![feature(managed_boxes)] + pub struct Foo { a: int, } struct Bar<'a> { - a: ~Option, + a: Box>, b: &'a Foo, } fn check(a: @Foo) { - let _ic = Bar{ b: a, a: ~None }; + let _ic = Bar{ b: a, a: box None }; } pub fn main(){} diff --git a/src/test/run-pass/issue-6128.rs b/src/test/run-pass/issue-6128.rs index 3694421c69196..9f44f11e5c892 100644 --- a/src/test/run-pass/issue-6128.rs +++ b/src/test/run-pass/issue-6128.rs @@ -24,6 +24,6 @@ impl Graph for HashMap { } pub fn main() { - let g : ~HashMap = ~HashMap::new(); - let _g2 : ~Graph = g as ~Graph; + let g : Box> = box HashMap::new(); + let _g2 : Box> = g as Box>; } diff --git a/src/test/run-pass/issue-6318.rs b/src/test/run-pass/issue-6318.rs index 00a94c0cc376a..4eb005f339725 100644 --- a/src/test/run-pass/issue-6318.rs +++ b/src/test/run-pass/issue-6318.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + pub enum Thing { - A(~Foo) + A(Box) } pub trait Foo {} @@ -19,7 +20,7 @@ pub struct Struct; impl Foo for Struct {} pub fn main() { - match A(~Struct as ~Foo) { + match A(box Struct as Box) { A(_a) => 0, }; } diff --git a/src/test/run-pass/issue-6557.rs b/src/test/run-pass/issue-6557.rs index 5722461257324..7061a17dcdd0c 100644 --- a/src/test/run-pass/issue-6557.rs +++ b/src/test/run-pass/issue-6557.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(~(_x, _y): ~(int, int)) {} + +fn foo(box (_x, _y): Box<(int, int)>) {} pub fn main() {} diff --git a/src/test/run-pass/issue-7320.rs b/src/test/run-pass/issue-7320.rs index ccd2e8077399f..99ed4288a7ec1 100644 --- a/src/test/run-pass/issue-7320.rs +++ b/src/test/run-pass/issue-7320.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { - fn foo(~self) { bar(self as ~Foo); } + fn foo(~self) { bar(self as Box); } } -fn bar(_b: ~Foo) { } +fn bar(_b: Box) { } fn main() {} diff --git a/src/test/run-pass/issue-7673-cast-generically-implemented-trait.rs b/src/test/run-pass/issue-7673-cast-generically-implemented-trait.rs index cf1f979acb4b0..7cd7e70be74fa 100644 --- a/src/test/run-pass/issue-7673-cast-generically-implemented-trait.rs +++ b/src/test/run-pass/issue-7673-cast-generically-implemented-trait.rs @@ -14,11 +14,12 @@ */ + pub fn main() {} trait A {} impl A for T {} -fn owned1(a: T) { ~a as ~A:; } /* note `:` */ -fn owned2(a: ~T) { a as ~A:; } -fn owned3(a: ~T) { ~a as ~A:; } +fn owned1(a: T) { box a as Box; } /* note `:` */ +fn owned2(a: Box) { a as Box; } +fn owned3(a: Box) { box a as Box; } diff --git a/src/test/run-pass/issue-8498.rs b/src/test/run-pass/issue-8498.rs index ac95b5e7c1953..770de8f534666 100644 --- a/src/test/run-pass/issue-8498.rs +++ b/src/test/run-pass/issue-8498.rs @@ -9,14 +9,14 @@ // except according to those terms. pub fn main() { - match &[(~5,~7)] { + match &[(box 5,box 7)] { ps => { let (ref y, _) = ps[0]; assert!(**y == 5); } } - match Some(&[(~5,)]) { + match Some(&[(box 5,)]) { Some(ps) => { let (ref y,) = ps[0]; assert!(**y == 5); @@ -24,7 +24,7 @@ pub fn main() { None => () } - match Some(&[(~5,~7)]) { + match Some(&[(box 5,box 7)]) { Some(ps) => { let (ref y, ref z) = ps[0]; assert!(**y == 5); diff --git a/src/test/run-pass/issue-9129.rs b/src/test/run-pass/issue-9129.rs index 52fc33d121db9..b61263d17542a 100644 --- a/src/test/run-pass/issue-9129.rs +++ b/src/test/run-pass/issue-9129.rs @@ -12,6 +12,7 @@ #![feature(macro_rules)] + pub trait bomb { fn boom(&self, Ident); } pub struct S; impl bomb for S { fn boom(&self, _: Ident) { } } @@ -26,7 +27,7 @@ fn Ident_new() -> Ident { Ident {name: 0x6789ABCD } } -pub fn light_fuse(fld: ~bomb) { +pub fn light_fuse(fld: Box) { int3!(); let f = || { int3!(); @@ -36,6 +37,6 @@ pub fn light_fuse(fld: ~bomb) { } pub fn main() { - let b = ~S as ~bomb; + let b = box S as Box; light_fuse(b); } diff --git a/src/test/run-pass/issue-9382.rs b/src/test/run-pass/issue-9382.rs index 3b79782878b89..bba4b69ee1ef6 100644 --- a/src/test/run-pass/issue-9382.rs +++ b/src/test/run-pass/issue-9382.rs @@ -18,23 +18,23 @@ struct Thing1<'a> { - baz: &'a [~int], - bar: ~u64, + baz: &'a [Box], + bar: Box, } struct Thing2<'a> { - baz: &'a [~int], + baz: &'a [Box], bar: u64, } pub fn main() { let _t1_fixed = Thing1 { baz: &[], - bar: ~32, + bar: box 32, }; Thing1 { baz: Vec::new().as_slice(), - bar: ~32, + bar: box 32, }; let _t2_fixed = Thing2 { baz: &[], diff --git a/src/test/run-pass/kindck-owned-trait-contains-1.rs b/src/test/run-pass/kindck-owned-trait-contains-1.rs index e4a7e7af14f7f..3dae50bda3376 100644 --- a/src/test/run-pass/kindck-owned-trait-contains-1.rs +++ b/src/test/run-pass/kindck-owned-trait-contains-1.rs @@ -8,21 +8,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait repeat { fn get(&self) -> A; } -impl repeat for ~A { +impl repeat for Box { fn get(&self) -> A { (**self).clone() } } -fn repeater(v: ~A) -> ~repeat: { +fn repeater(v: Box) -> Box:> { // Note: owned kind is not necessary as A appears in the trait type - ~v as ~repeat: // No + box v as Box:> // No } pub fn main() { let x = 3; - let y = repeater(~x); + let y = repeater(box x); assert_eq!(x, y.get()); } diff --git a/src/test/run-pass/last-use-in-cap-clause.rs b/src/test/run-pass/last-use-in-cap-clause.rs index ec26dc0b3ed36..463ea0c686310 100644 --- a/src/test/run-pass/last-use-in-cap-clause.rs +++ b/src/test/run-pass/last-use-in-cap-clause.rs @@ -10,10 +10,11 @@ // Make sure #1399 stays fixed -struct A { a: ~int } + +struct A { a: Box } fn foo() -> ||: 'static -> int { - let k = ~22; + let k = box 22; let _u = A {a: k.clone()}; let result: ||: 'static -> int = || 22; result diff --git a/src/test/run-pass/last-use-is-capture.rs b/src/test/run-pass/last-use-is-capture.rs index f0149c811f0d8..5e892d5433e7a 100644 --- a/src/test/run-pass/last-use-is-capture.rs +++ b/src/test/run-pass/last-use-is-capture.rs @@ -10,11 +10,12 @@ // Make sure #1399 stays fixed -struct A { a: ~int } + +struct A { a: Box } pub fn main() { fn invoke(f: ||) { f(); } - let k = ~22; + let k = box 22; let _u = A {a: k.clone()}; invoke(|| println!("{:?}", k.clone()) ) } diff --git a/src/test/run-pass/leak-unique-as-tydesc.rs b/src/test/run-pass/leak-unique-as-tydesc.rs index ab186d935df36..b109e94b74f2b 100644 --- a/src/test/run-pass/leak-unique-as-tydesc.rs +++ b/src/test/run-pass/leak-unique-as-tydesc.rs @@ -9,7 +9,6 @@ // except according to those terms. - fn leaky(_t: T) { } -pub fn main() { let x = ~10; leaky::<~int>(x); } +pub fn main() { let x = box 10; leaky::>(x); } diff --git a/src/test/run-pass/match-implicit-copy-unique.rs b/src/test/run-pass/match-implicit-copy-unique.rs index 23074894490d6..679fb472503ce 100644 --- a/src/test/run-pass/match-implicit-copy-unique.rs +++ b/src/test/run-pass/match-implicit-copy-unique.rs @@ -8,13 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Pair { a: ~int, b: ~int } + +struct Pair { a: Box, b: Box } pub fn main() { - let mut x = ~Pair {a: ~10, b: ~20}; + let mut x = box Pair {a: box 10, b: box 20}; match x { - ~Pair {a: ref mut a, b: ref mut _b} => { - assert!(**a == 10); *a = ~30; assert!(**a == 30); + box Pair {a: ref mut a, b: ref mut _b} => { + assert!(**a == 10); *a = box 30; assert!(**a == 30); } } } diff --git a/src/test/run-pass/match-unique-bind.rs b/src/test/run-pass/match-unique-bind.rs index 9fc3a7acf7179..9fae0e30d5935 100644 --- a/src/test/run-pass/match-unique-bind.rs +++ b/src/test/run-pass/match-unique-bind.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - match ~100 { - ~x => { + match box 100 { + box x => { println!("{:?}", x); assert_eq!(x, 100); } diff --git a/src/test/run-pass/match-value-binding-in-guard-3291.rs b/src/test/run-pass/match-value-binding-in-guard-3291.rs index 33785b2fbb096..0e7e9be6765b4 100644 --- a/src/test/run-pass/match-value-binding-in-guard-3291.rs +++ b/src/test/run-pass/match-value-binding-in-guard-3291.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: Option<~int>, b: bool) -> int { + +fn foo(x: Option>, b: bool) -> int { match x { None => { 1 } Some(ref x) if b => { *x.clone() } @@ -17,8 +18,8 @@ fn foo(x: Option<~int>, b: bool) -> int { } pub fn main() { - foo(Some(~22), true); - foo(Some(~22), false); + foo(Some(box 22), true); + foo(Some(box 22), false); foo(None, true); foo(None, false); } diff --git a/src/test/run-pass/move-1-unique.rs b/src/test/run-pass/move-1-unique.rs index ac6dfa00f4841..19153dd3742e2 100644 --- a/src/test/run-pass/move-1-unique.rs +++ b/src/test/run-pass/move-1-unique.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + #[deriving(Clone)] struct Triple { x: int, @@ -15,15 +16,15 @@ struct Triple { z: int, } -fn test(x: bool, foo: ~Triple) -> int { +fn test(x: bool, foo: Box) -> int { let bar = foo; - let mut y: ~Triple; - if x { y = bar; } else { y = ~Triple{x: 4, y: 5, z: 6}; } + let mut y: Box; + if x { y = bar; } else { y = box Triple{x: 4, y: 5, z: 6}; } return y.y; } pub fn main() { - let x = ~Triple{x: 1, y: 2, z: 3}; + let x = box Triple{x: 1, y: 2, z: 3}; assert_eq!(test(true, x.clone()), 2); assert_eq!(test(true, x.clone()), 2); assert_eq!(test(true, x.clone()), 2); diff --git a/src/test/run-pass/move-2-unique.rs b/src/test/run-pass/move-2-unique.rs index e3595d4ac9a31..65d8281407c4f 100644 --- a/src/test/run-pass/move-2-unique.rs +++ b/src/test/run-pass/move-2-unique.rs @@ -11,4 +11,8 @@ struct X { x: int, y: int, z: int } -pub fn main() { let x = ~X{x: 1, y: 2, z: 3}; let y = x; assert!((y.y == 2)); } +pub fn main() { + let x = box X{x: 1, y: 2, z: 3}; + let y = x; + assert!((y.y == 2)); +} diff --git a/src/test/run-pass/move-3-unique.rs b/src/test/run-pass/move-3-unique.rs index 867f00aff530e..1977842536749 100644 --- a/src/test/run-pass/move-3-unique.rs +++ b/src/test/run-pass/move-3-unique.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + #[deriving(Clone)] struct Triple { x: int, @@ -15,15 +16,15 @@ struct Triple { z: int, } -fn test(x: bool, foo: ~Triple) -> int { +fn test(x: bool, foo: Box) -> int { let bar = foo; - let mut y: ~Triple; - if x { y = bar; } else { y = ~Triple {x: 4, y: 5, z: 6}; } + let mut y: Box; + if x { y = bar; } else { y = box Triple {x: 4, y: 5, z: 6}; } return y.y; } pub fn main() { - let x = ~Triple{x: 1, y: 2, z: 3}; + let x = box Triple{x: 1, y: 2, z: 3}; for _ in range(0u, 10000u) { assert_eq!(test(true, x.clone()), 2); } diff --git a/src/test/run-pass/move-4-unique.rs b/src/test/run-pass/move-4-unique.rs index 60537d99d84e5..286781a482277 100644 --- a/src/test/run-pass/move-4-unique.rs +++ b/src/test/run-pass/move-4-unique.rs @@ -8,9 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Triple {a: int, b: int, c: int} -fn test(foo: ~Triple) -> ~Triple { +fn test(foo: Box) -> Box { let foo = foo; let bar = foo; let baz = bar; @@ -18,4 +19,8 @@ fn test(foo: ~Triple) -> ~Triple { return quux; } -pub fn main() { let x = ~Triple{a: 1, b: 2, c: 3}; let y = test(x); assert!((y.c == 3)); } +pub fn main() { + let x = box Triple{a: 1, b: 2, c: 3}; + let y = test(x); + assert!((y.c == 3)); +} diff --git a/src/test/run-pass/move-arg-2-unique.rs b/src/test/run-pass/move-arg-2-unique.rs index 6bc3605156c5e..ac90f8f6ecf4e 100644 --- a/src/test/run-pass/move-arg-2-unique.rs +++ b/src/test/run-pass/move-arg-2-unique.rs @@ -9,13 +9,13 @@ // except according to those terms. -fn test(foo: ~Vec ) { assert!((*foo.get(0) == 10)); } +fn test(foo: Box> ) { assert!((*foo.get(0) == 10)); } pub fn main() { - let x = ~vec!(10); + let x = box vec!(10); // Test forgetting a local by move-in test(x); // Test forgetting a temporary by move-in. - test(~vec!(10)); + test(box vec!(10)); } diff --git a/src/test/run-pass/mut-function-arguments.rs b/src/test/run-pass/mut-function-arguments.rs index 5801ccebb0fcd..39441227f6074 100644 --- a/src/test/run-pass/mut-function-arguments.rs +++ b/src/test/run-pass/mut-function-arguments.rs @@ -8,20 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(mut y: ~int) { + +fn f(mut y: Box) { *y = 5; assert_eq!(*y, 5); } fn g() { - let frob: |~int| = |mut q| { *q = 2; assert!(*q == 2); }; - let w = ~37; + let frob: |Box| = |mut q| { *q = 2; assert!(*q == 2); }; + let w = box 37; frob(w); } pub fn main() { - let z = ~17; + let z = box 17; f(z); g(); } diff --git a/src/test/run-pass/new-box-syntax.rs b/src/test/run-pass/new-box-syntax.rs index 7a90ea436e056..cab3f36a9f4fd 100644 --- a/src/test/run-pass/new-box-syntax.rs +++ b/src/test/run-pass/new-box-syntax.rs @@ -14,7 +14,7 @@ // Tests that the new `box` syntax works with unique pointers and GC pointers. use std::gc::Gc; -use std::owned::HEAP; +use std::owned::{Box, HEAP}; struct Structure { x: int, @@ -22,14 +22,14 @@ struct Structure { } pub fn main() { - let x: ~int = box(HEAP) 2; - let y: ~int = box 2; + let x: Box = box(HEAP) 2; + let y: Box = box 2; let z: Gc = box(GC) 2; let a: Gc = box(GC) Structure { x: 10, y: 20, }; - let b: ~int = box()(1 + 2); + let b: Box = box()(1 + 2); let c = box()(3 + 4); let d = box(GC)(5 + 6); } diff --git a/src/test/run-pass/new-box.rs b/src/test/run-pass/new-box.rs index 0202695841e1a..d41896ffb41d0 100644 --- a/src/test/run-pass/new-box.rs +++ b/src/test/run-pass/new-box.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::owned::Box; fn f(x: Box) { let y: &int = x; diff --git a/src/test/run-pass/nullable-pointer-iotareduction.rs b/src/test/run-pass/nullable-pointer-iotareduction.rs index 237212e7eb75e..04b2e94f1a0c7 100644 --- a/src/test/run-pass/nullable-pointer-iotareduction.rs +++ b/src/test/run-pass/nullable-pointer-iotareduction.rs @@ -74,7 +74,7 @@ macro_rules! check_type { pub fn main() { check_type!(&17: &int); - check_type!(~18: ~int); + check_type!(box 18: Box); check_type!(@19: @int); check_type!("foo".to_owned(): ~str); check_type!(vec!(20, 22): Vec ); diff --git a/src/test/run-pass/nullable-pointer-size.rs b/src/test/run-pass/nullable-pointer-size.rs index 4e5627237fb8e..00edcd6a0924b 100644 --- a/src/test/run-pass/nullable-pointer-size.rs +++ b/src/test/run-pass/nullable-pointer-size.rs @@ -38,7 +38,7 @@ macro_rules! check_type { pub fn main() { check_type!(&'static int); - check_type!(~int); + check_type!(Box); check_type!(@int); check_type!(~str); check_type!(extern fn()); diff --git a/src/test/run-pass/objects-owned-object-borrowed-method-header.rs b/src/test/run-pass/objects-owned-object-borrowed-method-header.rs index c39e79e052819..456a5c5d29753 100644 --- a/src/test/run-pass/objects-owned-object-borrowed-method-header.rs +++ b/src/test/run-pass/objects-owned-object-borrowed-method-header.rs @@ -14,7 +14,7 @@ // Test invoked `&self` methods on owned objects where the values -// closed over contain managed values. This implies that the ~ boxes +// closed over contain managed values. This implies that the boxes // will have headers that must be skipped over. trait FooTrait { @@ -32,10 +32,10 @@ impl FooTrait for BarStruct { } pub fn main() { - let foos: Vec<~FooTrait:> = vec!( - ~BarStruct{ x: @0 } as ~FooTrait:, - ~BarStruct{ x: @1 } as ~FooTrait:, - ~BarStruct{ x: @2 } as ~FooTrait: + let foos: Vec> = vec!( + box BarStruct{ x: @0 } as Box, + box BarStruct{ x: @1 } as Box, + box BarStruct{ x: @2 } as Box ); for i in range(0u, foos.len()) { diff --git a/src/test/run-pass/objects-owned-object-borrowed-method-headerless.rs b/src/test/run-pass/objects-owned-object-borrowed-method-headerless.rs index bd4a933205cf1..9ca6598b47c9a 100644 --- a/src/test/run-pass/objects-owned-object-borrowed-method-headerless.rs +++ b/src/test/run-pass/objects-owned-object-borrowed-method-headerless.rs @@ -9,7 +9,7 @@ // except according to those terms. // Test invoked `&self` methods on owned objects where the values -// closed over do not contain managed values, and thus the ~ boxes do +// closed over do not contain managed values, and thus the boxes do // not have headers. @@ -28,10 +28,10 @@ impl FooTrait for BarStruct { } pub fn main() { - let foos: Vec<~FooTrait> = vec!( - ~BarStruct{ x: 0 } as ~FooTrait, - ~BarStruct{ x: 1 } as ~FooTrait, - ~BarStruct{ x: 2 } as ~FooTrait + let foos: Vec> = vec!( + box BarStruct{ x: 0 } as Box, + box BarStruct{ x: 1 } as Box, + box BarStruct{ x: 2 } as Box ); for i in range(0u, foos.len()) { diff --git a/src/test/run-pass/objects-owned-object-owned-method.rs b/src/test/run-pass/objects-owned-object-owned-method.rs index 0d675c16d1aad..cac132b8e3662 100644 --- a/src/test/run-pass/objects-owned-object-owned-method.rs +++ b/src/test/run-pass/objects-owned-object-owned-method.rs @@ -9,9 +9,10 @@ // except according to those terms. // Test invoked `&self` methods on owned objects where the values -// closed over contain managed values. This implies that the ~ boxes +// closed over contain managed values. This implies that the boxes // will have headers that must be skipped over. + trait FooTrait { fn foo(~self) -> uint; } @@ -27,6 +28,6 @@ impl FooTrait for BarStruct { } pub fn main() { - let foo = ~BarStruct{ x: 22 } as ~FooTrait; + let foo = box BarStruct{ x: 22 } as Box; assert_eq!(22, foo.foo()); } diff --git a/src/test/run-pass/overloaded-autoderef.rs b/src/test/run-pass/overloaded-autoderef.rs index 08cb2f57990d4..39566cbc6ed53 100644 --- a/src/test/run-pass/overloaded-autoderef.rs +++ b/src/test/run-pass/overloaded-autoderef.rs @@ -20,7 +20,7 @@ struct Point { pub fn main() { assert_eq!(Rc::new(5u).to_uint(), Some(5)); - assert_eq!((~&~&Rc::new(~~&~5u)).to_uint(), Some(5)); + assert_eq!((box &box &Rc::new(box box &box 5u)).to_uint(), Some(5)); let point = Rc::new(Point {x: 2, y: 4}); assert_eq!(point.x, 2); assert_eq!(point.y, 4); diff --git a/src/test/run-pass/overloaded-deref.rs b/src/test/run-pass/overloaded-deref.rs index 5328b213810ba..47cdc8d247af5 100644 --- a/src/test/run-pass/overloaded-deref.rs +++ b/src/test/run-pass/overloaded-deref.rs @@ -20,7 +20,7 @@ struct Point { pub fn main() { assert_eq!(*Rc::new(5), 5); - assert_eq!(***Rc::new(~~5), 5); + assert_eq!(***Rc::new(box box 5), 5); assert_eq!(*Rc::new(Point {x: 2, y: 4}), Point {x: 2, y: 4}); let i = Rc::new(RefCell::new(2)); diff --git a/src/test/run-pass/owned-implies-static.rs b/src/test/run-pass/owned-implies-static.rs index f327f6bc0dc75..d1e9fb270d7bd 100644 --- a/src/test/run-pass/owned-implies-static.rs +++ b/src/test/run-pass/owned-implies-static.rs @@ -11,5 +11,5 @@ fn f(_x: T) {} pub fn main() { - f(~5); + f(box 5); } diff --git a/src/test/run-pass/parameterized-trait-with-bounds.rs b/src/test/run-pass/parameterized-trait-with-bounds.rs index e22bc4247e096..6f33fb470e7ec 100644 --- a/src/test/run-pass/parameterized-trait-with-bounds.rs +++ b/src/test/run-pass/parameterized-trait-with-bounds.rs @@ -10,6 +10,7 @@ #![allow(dead_code)] + trait A {} trait B {} trait C<'a, U> {} @@ -19,9 +20,9 @@ mod foo { } fn foo1(_: &A: Send) {} -fn foo2(_: ~A: Send + Share) {} -fn foo3(_: ~B: 'static) {} -fn foo4<'a, T>(_: ~C<'a, T>: 'static + Send) {} -fn foo5<'a, T>(_: ~foo::D<'a, T>: 'static + Send) {} +fn foo2(_: Box: Send + Share>) {} +fn foo3(_: Box: 'static>) {} +fn foo4<'a, T>(_: Box: 'static + Send>) {} +fn foo5<'a, T>(_: Box: 'static + Send>) {} pub fn main() {} diff --git a/src/test/run-pass/privacy-ns.rs b/src/test/run-pass/privacy-ns.rs index 0756d8214a66a..5915b3e3a76db 100644 --- a/src/test/run-pass/privacy-ns.rs +++ b/src/test/run-pass/privacy-ns.rs @@ -16,6 +16,7 @@ #![allow(dead_code)] #![allow(unused_imports)] + // public type, private value pub mod foo1 { pub trait Bar { @@ -34,19 +35,19 @@ fn test_unused1() { fn test_single1() { use foo1::Bar; - let _x: ~Bar; + let _x: Box; } fn test_list1() { use foo1::{Bar,Baz}; - let _x: ~Bar; + let _x: Box; } fn test_glob1() { use foo1::*; - let _x: ~Bar; + let _x: Box; } // private type, public value @@ -101,21 +102,21 @@ fn test_single3() { use foo3::Bar; Bar(); - let _x: ~Bar; + let _x: Box; } fn test_list3() { use foo3::{Bar,Baz}; Bar(); - let _x: ~Bar; + let _x: Box; } fn test_glob3() { use foo3::*; Bar(); - let _x: ~Bar; + let _x: Box; } fn main() { diff --git a/src/test/run-pass/pure-sum.rs b/src/test/run-pass/pure-sum.rs index ef569af135044..60eb3f9debd25 100644 --- a/src/test/run-pass/pure-sum.rs +++ b/src/test/run-pass/pure-sum.rs @@ -23,7 +23,7 @@ fn sums_to(v: Vec , sum: int) -> bool { fn sums_to_using_uniq(v: Vec , sum: int) -> bool { let mut i = 0u; - let mut sum0 = ~0; + let mut sum0 = box 0; while i < v.len() { *sum0 += *v.get(i); i += 1u; @@ -45,7 +45,7 @@ struct F { f: T } fn sums_to_using_uniq_rec(v: Vec , sum: int) -> bool { let mut i = 0u; - let mut sum0 = F {f: ~0}; + let mut sum0 = F {f: box 0}; while i < v.len() { *sum0.f += *v.get(i); i += 1u; diff --git a/src/test/run-pass/rcvr-borrowed-to-region.rs b/src/test/run-pass/rcvr-borrowed-to-region.rs index 4b54c32fbd36a..eab5ba6108367 100644 --- a/src/test/run-pass/rcvr-borrowed-to-region.rs +++ b/src/test/run-pass/rcvr-borrowed-to-region.rs @@ -33,7 +33,7 @@ pub fn main() { println!("y={}", y); assert_eq!(y, 6); - let x = ~6; + let x = box 6; let y = x.get(); println!("y={}", y); assert_eq!(y, 6); diff --git a/src/test/run-pass/regions-addr-of-interior-of-unique-box.rs b/src/test/run-pass/regions-addr-of-interior-of-unique-box.rs index 7efe62236f35e..47ae5c13d28cb 100644 --- a/src/test/run-pass/regions-addr-of-interior-of-unique-box.rs +++ b/src/test/run-pass/regions-addr-of-interior-of-unique-box.rs @@ -8,13 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct Point { x: int, y: int } struct Character { - pos: ~Point + pos: Box, } fn get_x<'r>(x: &'r Character) -> &'r int { diff --git a/src/test/run-pass/regions-borrow-uniq.rs b/src/test/run-pass/regions-borrow-uniq.rs index 10037d9dfe43b..6b35c0768d79a 100644 --- a/src/test/run-pass/regions-borrow-uniq.rs +++ b/src/test/run-pass/regions-borrow-uniq.rs @@ -13,7 +13,7 @@ fn foo(x: &uint) -> uint { } pub fn main() { - let p = ~3u; + let p = box 3u; let r = foo(p); assert_eq!(r, 3u); } diff --git a/src/test/run-pass/regions-bound-lists-feature-gate.rs b/src/test/run-pass/regions-bound-lists-feature-gate.rs index 163e6670c9c5f..3e23c1d4d64ff 100644 --- a/src/test/run-pass/regions-bound-lists-feature-gate.rs +++ b/src/test/run-pass/regions-bound-lists-feature-gate.rs @@ -12,9 +12,10 @@ #![feature(issue_5723_bootstrap)] + trait Foo { } -fn foo<'a>(x: ~Foo:'a) { +fn foo<'a>(x: Box) { } fn bar<'a, T:'a>() { diff --git a/src/test/run-pass/regions-dependent-addr-of.rs b/src/test/run-pass/regions-dependent-addr-of.rs index 256d12ccddf78..400ab462f761f 100644 --- a/src/test/run-pass/regions-dependent-addr-of.rs +++ b/src/test/run-pass/regions-dependent-addr-of.rs @@ -21,7 +21,7 @@ struct B { v2: [int, ..3], v3: Vec , v4: C, - v5: ~C, + v5: Box, v6: Option } @@ -78,7 +78,7 @@ fn get_v6_c<'v>(a: &'v A, _i: uint) -> &'v int { fn get_v5_ref<'v>(a: &'v A, _i: uint) -> &'v int { match &a.value { - &B {v5: ~C {f: ref v}, ..} => v + &B {v5: box C {f: ref v}, ..} => v } } @@ -87,7 +87,7 @@ pub fn main() { v2: [23, 24, 25], v3: vec!(26, 27, 28), v4: C { f: 29 }, - v5: ~C { f: 30 }, + v5: box C { f: 30 }, v6: Some(C { f: 31 })}}; let p = get_v1(&a); diff --git a/src/test/run-pass/regions-early-bound-trait-param.rs b/src/test/run-pass/regions-early-bound-trait-param.rs index f3cfa0b9d3352..a7ba496dc4a27 100644 --- a/src/test/run-pass/regions-early-bound-trait-param.rs +++ b/src/test/run-pass/regions-early-bound-trait-param.rs @@ -11,6 +11,7 @@ // Tests that you can use an early-bound lifetime parameter as // on of the generic parameters in a trait. + trait Trait<'a> { fn long(&'a self) -> int; fn short<'b>(&'b self) -> int; @@ -77,8 +78,8 @@ impl<'s> Trait<'s> for (int,int) { } } -impl<'t> MakerTrait<'t> for ~Trait<'t> { - fn mk() -> ~Trait<'t> { ~(4,5) as ~Trait } +impl<'t> MakerTrait<'t> for Box> { + fn mk() -> Box> { box() (4,5) as Box } } enum List<'l> { @@ -118,7 +119,7 @@ pub fn main() { assert_eq!(object_invoke2(&t), 3); assert_eq!(field_invoke2(&s2), 3); - let m : ~Trait = make_val(); + let m : Box = make_val(); assert_eq!(object_invoke1(m), (4,5)); assert_eq!(object_invoke2(m), 5); diff --git a/src/test/run-pass/self-in-mut-slot-default-method.rs b/src/test/run-pass/self-in-mut-slot-default-method.rs index 08d10fd11703b..8ab27cfb4ee23 100644 --- a/src/test/run-pass/self-in-mut-slot-default-method.rs +++ b/src/test/run-pass/self-in-mut-slot-default-method.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct X { a: int } @@ -18,7 +19,7 @@ trait Changer { self } - fn change_again(mut ~self) -> ~Self { + fn change_again(mut ~self) -> Box { self.set_to(45); self } @@ -37,7 +38,7 @@ pub fn main() { let new_x = x.change(); assert_eq!(new_x.a, 55); - let x = ~new_x; + let x = box new_x; let new_x = x.change_again(); assert_eq!(new_x.a, 45); } diff --git a/src/test/run-pass/self-re-assign.rs b/src/test/run-pass/self-re-assign.rs index 4e1a9b665d045..e613a83737e4d 100644 --- a/src/test/run-pass/self-re-assign.rs +++ b/src/test/run-pass/self-re-assign.rs @@ -14,7 +14,7 @@ use std::rc::Rc; pub fn main() { - let mut x = ~3; + let mut x = box 3; x = x; assert!(*x == 3); diff --git a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs index a62c1ec33146b..c03094d4f1581 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -17,7 +17,7 @@ fn test05_start(f: proc(int)) { } fn test05() { - let three = ~3; + let three = box 3; let fn_to_send: proc(int):Send = proc(n) { println!("{}", *three + n); // will copy x into the closure assert_eq!(*three, 3); diff --git a/src/test/run-pass/sized-owned-pointer.rs b/src/test/run-pass/sized-owned-pointer.rs index 0c05fdd616ba6..e64917a97a637 100644 --- a/src/test/run-pass/sized-owned-pointer.rs +++ b/src/test/run-pass/sized-owned-pointer.rs @@ -10,6 +10,7 @@ // Possibly-dynamic size of typaram should be cleared at pointer boundary. + fn bar() { } -fn foo() { bar::<~T>() } +fn foo() { bar::>() } pub fn main() { } diff --git a/src/test/run-pass/task-spawn-move-and-copy.rs b/src/test/run-pass/task-spawn-move-and-copy.rs index 18d7839652a7c..cf6c275482932 100644 --- a/src/test/run-pass/task-spawn-move-and-copy.rs +++ b/src/test/run-pass/task-spawn-move-and-copy.rs @@ -13,7 +13,7 @@ use std::task; pub fn main() { let (tx, rx) = channel::(); - let x = ~1; + let x = box 1; let x_in_parent = &(*x) as *int as uint; task::spawn(proc() { diff --git a/src/test/run-pass/trait-bounds-basic.rs b/src/test/run-pass/trait-bounds-basic.rs index 6059e5e95ee5f..68ebf2c6382ca 100644 --- a/src/test/run-pass/trait-bounds-basic.rs +++ b/src/test/run-pass/trait-bounds-basic.rs @@ -8,24 +8,25 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Foo { } -fn a(_x: ~Foo:) { +fn a(_x: Box) { } -fn b(_x: ~Foo:Send) { +fn b(_x: Box) { } -fn c(x: ~Foo:Share+Send) { +fn c(x: Box) { a(x); } -fn d(x: ~Foo:Send) { +fn d(x: Box) { b(x); } -fn e(x: ~Foo) { // sugar for ~Foo:Owned +fn e(x: Box) { // sugar for Box a(x); } diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index 312978f00a02f..0a6e5ce0b6796 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -64,10 +64,10 @@ pub fn main() { let dogge1 = Dogge { bark_decibels: 100, tricks_known: 42, name: "alan_turing".to_owned() }; let dogge2 = Dogge { bark_decibels: 55, tricks_known: 11, name: "albert_einstein".to_owned() }; let fishe = Goldfyshe { swim_speed: 998, name: "alec_guinness".to_owned() }; - let arc = Arc::new(vec!(~catte as ~Pet:Share+Send, - ~dogge1 as ~Pet:Share+Send, - ~fishe as ~Pet:Share+Send, - ~dogge2 as ~Pet:Share+Send)); + let arc = Arc::new(vec!(box catte as Box, + box dogge1 as Box, + box fishe as Box, + box dogge2 as Box)); let (tx1, rx1) = channel(); let arc1 = arc.clone(); task::spawn(proc() { check_legs(arc1); tx1.send(()); }); @@ -82,21 +82,21 @@ pub fn main() { rx3.recv(); } -fn check_legs(arc: Arc>) { +fn check_legs(arc: Arc>>) { let mut legs = 0; for pet in arc.iter() { legs += pet.num_legs(); } assert!(legs == 12); } -fn check_names(arc: Arc>) { +fn check_names(arc: Arc>>) { for pet in arc.iter() { pet.name(|name| { assert!(name[0] == 'a' as u8 && name[1] == 'l' as u8); }) } } -fn check_pedigree(arc: Arc>) { +fn check_pedigree(arc: Arc>>) { for pet in arc.iter() { assert!(pet.of_good_pedigree()); } diff --git a/src/test/run-pass/trait-cast.rs b/src/test/run-pass/trait-cast.rs index 244459e22695d..3d303bf1e5b3b 100644 --- a/src/test/run-pass/trait-cast.rs +++ b/src/test/run-pass/trait-cast.rs @@ -18,7 +18,7 @@ struct Tree(@RefCell); struct TreeR { left: Option, right: Option, - val: ~to_str:Send + val: Box } trait to_str { @@ -53,10 +53,10 @@ fn foo(x: T) -> ~str { x.to_str_() } pub fn main() { let t1 = Tree(@RefCell::new(TreeR{left: None, right: None, - val: ~1 as ~to_str:Send})); + val: box 1 as Box})); let t2 = Tree(@RefCell::new(TreeR{left: Some(t1), right: Some(t1), - val: ~2 as ~to_str:Send})); + val: box 2 as Box})); let expected = "[2, some([1, none, none]), some([1, none, none])]".to_owned(); assert!(t2.to_str_() == expected); assert!(foo(t2) == expected); diff --git a/src/test/run-pass/trait-coercion-generic.rs b/src/test/run-pass/trait-coercion-generic.rs index 2d8a42005df4d..1e241ad22784e 100644 --- a/src/test/run-pass/trait-coercion-generic.rs +++ b/src/test/run-pass/trait-coercion-generic.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + trait Trait { fn f(&self, x: T); } @@ -25,7 +26,7 @@ impl Trait<&'static str> for Struct { pub fn main() { let a = Struct { x: 1, y: 2 }; - let b: ~Trait<&'static str> = ~a; + let b: Box> = box a; b.f("Mary"); let c: &Trait<&'static str> = &a; c.f("Joe"); diff --git a/src/test/run-pass/trait-coercion.rs b/src/test/run-pass/trait-coercion.rs index ea6d59a906809..1d229a8ae8361 100644 --- a/src/test/run-pass/trait-coercion.rs +++ b/src/test/run-pass/trait-coercion.rs @@ -25,18 +25,18 @@ impl Trait for Struct { } } -fn foo(mut a: ~Writer) { +fn foo(mut a: Box) { a.write(bytes!("Hello\n")); } pub fn main() { let a = Struct { x: 1, y: 2 }; - let b: ~Trait = ~a; + let b: Box = box a; b.f(); let c: &Trait = &a; c.f(); let out = io::stdout(); - foo(~out); + foo(box out); } diff --git a/src/test/run-pass/trait-default-method-xc.rs b/src/test/run-pass/trait-default-method-xc.rs index 25b5b7fbd5f87..27db6d2f3b84b 100644 --- a/src/test/run-pass/trait-default-method-xc.rs +++ b/src/test/run-pass/trait-default-method-xc.rs @@ -50,7 +50,7 @@ impl TestEquality for stuff::thing { } -pub fn main () { +pub fn main() { // Some tests of random things f(0); @@ -72,7 +72,7 @@ pub fn main () { assert_eq!(g(0i, 3.14, 1), (3.14, 1)); assert_eq!(g(false, 3.14, 1), (3.14, 1)); - let obj = ~0i as ~A; + let obj = box 0i as Box; assert_eq!(obj.h(), 11); diff --git a/src/test/run-pass/trait-object-generics.rs b/src/test/run-pass/trait-object-generics.rs index e2422a1dcf563..3c5ae6b57a3a9 100644 --- a/src/test/run-pass/trait-object-generics.rs +++ b/src/test/run-pass/trait-object-generics.rs @@ -10,6 +10,7 @@ // test for #8664 + pub trait Trait2 { fn doit(&self); } @@ -20,7 +21,7 @@ pub struct Impl { * task failed at 'index out of bounds: the len is 1 but the index is 1', * src/librustc/middle/subst.rs:58 */ - t: ~Trait2 + t: Box> } impl Impl { @@ -42,6 +43,6 @@ impl Trait for () { } pub fn main() { - let a = ~() as ~Trait; + let a = box() () as Box>; assert_eq!(a.method(Constant), 0); } diff --git a/src/test/run-pass/type-param-constraints.rs b/src/test/run-pass/type-param-constraints.rs index 408a727b6f1bd..0fcf9b92ce04c 100644 --- a/src/test/run-pass/type-param-constraints.rs +++ b/src/test/run-pass/type-param-constraints.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - #![feature(managed_boxes)] + fn p_foo(_pinned: T) { } fn s_foo(_shared: T) { } fn u_foo(_unique: T) { } @@ -33,16 +33,16 @@ pub fn main() { p_foo(r(10)); p_foo(@r(10)); - p_foo(~r(10)); + p_foo(box r(10)); p_foo(@10); - p_foo(~10); + p_foo(box 10); p_foo(10); s_foo(@r(10)); s_foo(@10); - s_foo(~10); + s_foo(box 10); s_foo(10); - u_foo(~10); + u_foo(box 10); u_foo(10); } diff --git a/src/test/run-pass/uniq-cc.rs b/src/test/run-pass/uniq-cc.rs index 1c7525f07545d..06e9771aae4fa 100644 --- a/src/test/run-pass/uniq-cc.rs +++ b/src/test/run-pass/uniq-cc.rs @@ -19,14 +19,14 @@ enum maybe_pointy { struct Pointy { a : maybe_pointy, - c : ~int, + c : Box, d : proc():Send->(), } fn empty_pointy() -> @RefCell { return @RefCell::new(Pointy { a : none, - c : ~22, + c : box 22, d : proc() {}, }) } diff --git a/src/test/run-pass/uniq-self-in-mut-slot.rs b/src/test/run-pass/uniq-self-in-mut-slot.rs index 7c2f52211761f..3700e02051a69 100644 --- a/src/test/run-pass/uniq-self-in-mut-slot.rs +++ b/src/test/run-pass/uniq-self-in-mut-slot.rs @@ -8,23 +8,24 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + struct X { a: int } trait Changer { - fn change(mut ~self) -> ~Self; + fn change(mut ~self) -> Box; } impl Changer for X { - fn change(mut ~self) -> ~X { + fn change(mut ~self) -> Box { self.a = 55; self } } pub fn main() { - let x = ~X { a: 32 }; + let x = box X { a: 32 }; let new_x = x.change(); assert_eq!(new_x.a, 55); } diff --git a/src/test/run-pass/unique-assign-copy.rs b/src/test/run-pass/unique-assign-copy.rs index e59fe469dec6f..b295701d186be 100644 --- a/src/test/run-pass/unique-assign-copy.rs +++ b/src/test/run-pass/unique-assign-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut i = ~1; + let mut i = box 1; // Should be a copy let mut j; j = i.clone(); diff --git a/src/test/run-pass/unique-assign-drop.rs b/src/test/run-pass/unique-assign-drop.rs index df8036451d80b..90e5e82f0d881 100644 --- a/src/test/run-pass/unique-assign-drop.rs +++ b/src/test/run-pass/unique-assign-drop.rs @@ -11,8 +11,8 @@ #![allow(dead_assignment)] pub fn main() { - let i = ~1; - let mut j = ~2; + let i = box 1; + let mut j = box 2; // Should drop the previous value of j j = i; assert_eq!(*j, 1); diff --git a/src/test/run-pass/unique-assign-generic.rs b/src/test/run-pass/unique-assign-generic.rs index 595c5fe82e721..94e3ea565d6b2 100644 --- a/src/test/run-pass/unique-assign-generic.rs +++ b/src/test/run-pass/unique-assign-generic.rs @@ -16,8 +16,8 @@ fn f(t: T) -> T { } pub fn main() { - let t = f(~100); - assert_eq!(t, ~100); - let t = f(~@vec!(100)); - assert_eq!(t, ~@vec!(100)); + let t = f(box 100); + assert_eq!(t, box 100); + let t = f(box @vec!(100)); + assert_eq!(t, box @vec!(100)); } diff --git a/src/test/run-pass/unique-assign.rs b/src/test/run-pass/unique-assign.rs index 43df53c78a8dd..d332e23580980 100644 --- a/src/test/run-pass/unique-assign.rs +++ b/src/test/run-pass/unique-assign.rs @@ -10,6 +10,6 @@ pub fn main() { let mut i; - i = ~1; + i = box 1; assert_eq!(*i, 1); } diff --git a/src/test/run-pass/unique-autoderef-field.rs b/src/test/run-pass/unique-autoderef-field.rs index 6836ba4e79b00..67f96decaa9da 100644 --- a/src/test/run-pass/unique-autoderef-field.rs +++ b/src/test/run-pass/unique-autoderef-field.rs @@ -11,7 +11,7 @@ struct J { j: int } pub fn main() { - let i = ~J { + let i = box J { j: 100 }; assert_eq!(i.j, 100); diff --git a/src/test/run-pass/unique-autoderef-index.rs b/src/test/run-pass/unique-autoderef-index.rs index 4971a42be3062..fc5bac249ba61 100644 --- a/src/test/run-pass/unique-autoderef-index.rs +++ b/src/test/run-pass/unique-autoderef-index.rs @@ -10,6 +10,6 @@ pub fn main() { - let i = ~vec!(100); + let i = box vec!(100); assert_eq!(*i.get(0), 100); } diff --git a/src/test/run-pass/unique-cmp.rs b/src/test/run-pass/unique-cmp.rs index b50d315483596..037faee95990f 100644 --- a/src/test/run-pass/unique-cmp.rs +++ b/src/test/run-pass/unique-cmp.rs @@ -9,10 +9,10 @@ // except according to those terms. pub fn main() { - let i = ~100; - assert!(i == ~100); - assert!(i < ~101); - assert!(i <= ~100); - assert!(i > ~99); - assert!(i >= ~99); + let i = box 100; + assert!(i == box 100); + assert!(i < box 101); + assert!(i <= box 100); + assert!(i > box 99); + assert!(i >= box 99); } diff --git a/src/test/run-pass/unique-containing-tag.rs b/src/test/run-pass/unique-containing-tag.rs index 1ebd584aa5fa7..762a74b24551c 100644 --- a/src/test/run-pass/unique-containing-tag.rs +++ b/src/test/run-pass/unique-containing-tag.rs @@ -11,7 +11,7 @@ pub fn main() { enum t { t1(int), t2(int), } - let _x = ~t1(10); + let _x = box t1(10); /*alt *x { t1(a) { @@ -21,7 +21,7 @@ pub fn main() { }*/ /*alt x { - ~t1(a) { + box t1(a) { assert_eq!(a, 10); } _ { fail!(); } diff --git a/src/test/run-pass/unique-create.rs b/src/test/run-pass/unique-create.rs index 023917ec2e948..834b549d4f413 100644 --- a/src/test/run-pass/unique-create.rs +++ b/src/test/run-pass/unique-create.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - ~100; + box 100; } fn vec() { diff --git a/src/test/run-pass/unique-decl-init-copy.rs b/src/test/run-pass/unique-decl-init-copy.rs index 13594d86f6764..a5cb19ebad7b6 100644 --- a/src/test/run-pass/unique-decl-init-copy.rs +++ b/src/test/run-pass/unique-decl-init-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut i = ~1; + let mut i = box 1; // Should be a copy let mut j = i.clone(); *i = 2; diff --git a/src/test/run-pass/unique-decl-init.rs b/src/test/run-pass/unique-decl-init.rs index c507d19fac16b..9cf28415481fa 100644 --- a/src/test/run-pass/unique-decl-init.rs +++ b/src/test/run-pass/unique-decl-init.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~1; + let i = box 1; let j = i; assert_eq!(*j, 1); } diff --git a/src/test/run-pass/unique-decl-move-temp.rs b/src/test/run-pass/unique-decl-move-temp.rs index 6cf781d735cfa..346b7d0bfcccb 100644 --- a/src/test/run-pass/unique-decl-move-temp.rs +++ b/src/test/run-pass/unique-decl-move-temp.rs @@ -9,6 +9,6 @@ // except according to those terms. pub fn main() { - let i = ~100; + let i = box 100; assert_eq!(*i, 100); } diff --git a/src/test/run-pass/unique-decl-move.rs b/src/test/run-pass/unique-decl-move.rs index 335275ff7c102..d2e8f991d21e2 100644 --- a/src/test/run-pass/unique-decl-move.rs +++ b/src/test/run-pass/unique-decl-move.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~100; + let i = box 100; let j = i; assert_eq!(*j, 100); } diff --git a/src/test/run-pass/unique-decl.rs b/src/test/run-pass/unique-decl.rs index 74b73d7736998..7f894a8c324b5 100644 --- a/src/test/run-pass/unique-decl.rs +++ b/src/test/run-pass/unique-decl.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + pub fn main() { - let _: ~int; + let _: Box; } -fn f(_i: ~int) -> ~int { +fn f(_i: Box) -> Box { fail!(); } diff --git a/src/test/run-pass/unique-deref.rs b/src/test/run-pass/unique-deref.rs index 6cf781d735cfa..346b7d0bfcccb 100644 --- a/src/test/run-pass/unique-deref.rs +++ b/src/test/run-pass/unique-deref.rs @@ -9,6 +9,6 @@ // except according to those terms. pub fn main() { - let i = ~100; + let i = box 100; assert_eq!(*i, 100); } diff --git a/src/test/run-pass/unique-destructure.rs b/src/test/run-pass/unique-destructure.rs index 6c35cb4dba77b..0b3041f2249e1 100644 --- a/src/test/run-pass/unique-destructure.rs +++ b/src/test/run-pass/unique-destructure.rs @@ -11,6 +11,6 @@ struct Foo { a: int, b: int } pub fn main() { - let ~Foo{a, b} = ~Foo{a: 100, b: 200}; + let box Foo{a, b} = box Foo{a: 100, b: 200}; assert_eq!(a + b, 300); } diff --git a/src/test/run-pass/unique-drop-complex.rs b/src/test/run-pass/unique-drop-complex.rs index eb8fa640a0fd9..01aac804bb64f 100644 --- a/src/test/run-pass/unique-drop-complex.rs +++ b/src/test/run-pass/unique-drop-complex.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - let _x = ~vec!(0,0,0,0,0); + let _x = box vec!(0,0,0,0,0); } diff --git a/src/test/run-pass/unique-fn-arg-move.rs b/src/test/run-pass/unique-fn-arg-move.rs index 503bbae8c55a9..762c2c7ea0c84 100644 --- a/src/test/run-pass/unique-fn-arg-move.rs +++ b/src/test/run-pass/unique-fn-arg-move.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(i: ~int) { + +fn f(i: Box) { assert_eq!(*i, 100); } pub fn main() { - let i = ~100; + let i = box 100; f(i); } diff --git a/src/test/run-pass/unique-fn-arg-mut.rs b/src/test/run-pass/unique-fn-arg-mut.rs index c2d78c3303902..ccf6a4fd7aeae 100644 --- a/src/test/run-pass/unique-fn-arg-mut.rs +++ b/src/test/run-pass/unique-fn-arg-mut.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(i: &mut ~int) { - *i = ~200; + +fn f(i: &mut Box) { + *i = box 200; } pub fn main() { - let mut i = ~100; + let mut i = box 100; f(&mut i); assert_eq!(*i, 200); } diff --git a/src/test/run-pass/unique-fn-arg.rs b/src/test/run-pass/unique-fn-arg.rs index 230131bae62bc..6769011cffef8 100644 --- a/src/test/run-pass/unique-fn-arg.rs +++ b/src/test/run-pass/unique-fn-arg.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(i: ~int) { + +fn f(i: Box) { assert_eq!(*i, 100); } pub fn main() { - f(~100); - let i = ~100; + f(box 100); + let i = box 100; f(i); } diff --git a/src/test/run-pass/unique-fn-ret.rs b/src/test/run-pass/unique-fn-ret.rs index dd39e136fc9bb..8493652cf8a08 100644 --- a/src/test/run-pass/unique-fn-ret.rs +++ b/src/test/run-pass/unique-fn-ret.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f() -> ~int { - ~100 + +fn f() -> Box { + box 100 } pub fn main() { - assert_eq!(f(), ~100); + assert_eq!(f(), box 100); } diff --git a/src/test/run-pass/unique-generic-assign.rs b/src/test/run-pass/unique-generic-assign.rs index 3805cbe47bf62..58470637a11e5 100644 --- a/src/test/run-pass/unique-generic-assign.rs +++ b/src/test/run-pass/unique-generic-assign.rs @@ -10,7 +10,8 @@ // Issue #976 -fn f(x: ~T) { + +fn f(x: Box) { let _x2 = x; } pub fn main() { } diff --git a/src/test/run-pass/unique-in-tag.rs b/src/test/run-pass/unique-in-tag.rs index c5d55ff0386ec..2045beb7f32dc 100644 --- a/src/test/run-pass/unique-in-tag.rs +++ b/src/test/run-pass/unique-in-tag.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + fn test1() { - enum bar { u(~int), w(int), } + enum bar { u(Box), w(int), } - let x = u(~10); + let x = u(box 10); assert!(match x { u(a) => { println!("{:?}", a); diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index c14af83ad87b2..f1f6a29dd223e 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -10,7 +10,7 @@ pub fn main() { - let mut a = vec!(~10); + let mut a = vec!(box 10); let b = a.clone(); assert_eq!(**a.get(0), 10); diff --git a/src/test/run-pass/unique-in-vec.rs b/src/test/run-pass/unique-in-vec.rs index 82d3a29d901ba..9b2b66231e560 100644 --- a/src/test/run-pass/unique-in-vec.rs +++ b/src/test/run-pass/unique-in-vec.rs @@ -9,6 +9,6 @@ // except according to those terms. pub fn main() { - let vect = vec!(~100); - assert!(*vect.get(0) == ~100); + let vect = vec!(box 100); + assert!(*vect.get(0) == box 100); } diff --git a/src/test/run-pass/unique-init.rs b/src/test/run-pass/unique-init.rs index 6a87dd30f7a78..d7105b472ccc5 100644 --- a/src/test/run-pass/unique-init.rs +++ b/src/test/run-pass/unique-init.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - let _i = ~100; + let _i = box 100; } diff --git a/src/test/run-pass/unique-kinds.rs b/src/test/run-pass/unique-kinds.rs index 118d0cd744d58..6d088a1f6d468 100644 --- a/src/test/run-pass/unique-kinds.rs +++ b/src/test/run-pass/unique-kinds.rs @@ -20,11 +20,11 @@ fn sendable() { assert!(i != j); } - let i = ~100; - let j = ~100; + let i = box 100; + let j = box 100; f(i, j); - let i = ~100; - let j = ~101; + let i = box 100; + let j = box 101; g(i, j); } @@ -38,11 +38,11 @@ fn copyable() { assert!(i != j); } - let i = ~100; - let j = ~100; + let i = box 100; + let j = box 100; f(i, j); - let i = ~100; - let j = ~101; + let i = box 100; + let j = box 101; g(i, j); } @@ -56,11 +56,11 @@ fn noncopyable() { assert!(i != j); } - let i = ~100; - let j = ~100; + let i = box 100; + let j = box 100; f(i, j); - let i = ~100; - let j = ~101; + let i = box 100; + let j = box 101; g(i, j); } diff --git a/src/test/run-pass/unique-log.rs b/src/test/run-pass/unique-log.rs index 06f73777032d9..e2de566090dc0 100644 --- a/src/test/run-pass/unique-log.rs +++ b/src/test/run-pass/unique-log.rs @@ -9,6 +9,6 @@ // except according to those terms. pub fn main() { - let i = ~100; + let i = box 100; println!("{:?}", i); } diff --git a/src/test/run-pass/unique-match-discrim.rs b/src/test/run-pass/unique-match-discrim.rs index 1f0b13dfd0193..68b46db3a947b 100644 --- a/src/test/run-pass/unique-match-discrim.rs +++ b/src/test/run-pass/unique-match-discrim.rs @@ -11,7 +11,7 @@ // Issue #961 fn altsimple() { - match ~true { + match box true { _ => { } } } diff --git a/src/test/run-pass/unique-move-drop.rs b/src/test/run-pass/unique-move-drop.rs index c757011f935c0..7ec0ce62329fb 100644 --- a/src/test/run-pass/unique-move-drop.rs +++ b/src/test/run-pass/unique-move-drop.rs @@ -11,8 +11,8 @@ #![allow(unused_variable)] pub fn main() { - let i = ~100; - let j = ~200; + let i = box 100; + let j = box 200; let j = i; assert_eq!(*j, 100); } diff --git a/src/test/run-pass/unique-move-temp.rs b/src/test/run-pass/unique-move-temp.rs index 7c7ca1379ea29..18cbbfa08df2f 100644 --- a/src/test/run-pass/unique-move-temp.rs +++ b/src/test/run-pass/unique-move-temp.rs @@ -10,6 +10,6 @@ pub fn main() { let mut i; - i = ~100; + i = box 100; assert_eq!(*i, 100); } diff --git a/src/test/run-pass/unique-move.rs b/src/test/run-pass/unique-move.rs index dbdfc5cb5bb5f..14f6077be7a2c 100644 --- a/src/test/run-pass/unique-move.rs +++ b/src/test/run-pass/unique-move.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~100; + let i = box 100; let mut j; j = i; assert_eq!(*j, 100); diff --git a/src/test/run-pass/unique-mutable.rs b/src/test/run-pass/unique-mutable.rs index 4f353c566717c..01a3ba6a3b45c 100644 --- a/src/test/run-pass/unique-mutable.rs +++ b/src/test/run-pass/unique-mutable.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut i = ~0; + let mut i = box 0; *i = 1; assert_eq!(*i, 1); } diff --git a/src/test/run-pass/unique-object-move.rs b/src/test/run-pass/unique-object-move.rs index f6a4674136671..6d0432faf5514 100644 --- a/src/test/run-pass/unique-object-move.rs +++ b/src/test/run-pass/unique-object-move.rs @@ -10,6 +10,7 @@ // Issue #5192 + pub trait EventLoop { } pub struct UvEventLoop { @@ -19,6 +20,6 @@ pub struct UvEventLoop { impl EventLoop for UvEventLoop { } pub fn main() { - let loop_: ~EventLoop = ~UvEventLoop { uvio: 0 } as ~EventLoop; + let loop_: Box = box UvEventLoop { uvio: 0 } as Box; let _loop2_ = loop_; } diff --git a/src/test/run-pass/unique-pat-2.rs b/src/test/run-pass/unique-pat-2.rs index 49a873e793a8d..3f7138006e510 100644 --- a/src/test/run-pass/unique-pat-2.rs +++ b/src/test/run-pass/unique-pat-2.rs @@ -11,11 +11,11 @@ struct Foo {a: int, b: uint} -enum bar { u(~Foo), w(int), } +enum bar { u(Box), w(int), } pub fn main() { - assert!(match u(~Foo{a: 10, b: 40u}) { - u(~Foo{a: a, b: b}) => { a + (b as int) } + assert!(match u(box Foo{a: 10, b: 40u}) { + u(box Foo{a: a, b: b}) => { a + (b as int) } _ => { 66 } } == 50); } diff --git a/src/test/run-pass/unique-pat-3.rs b/src/test/run-pass/unique-pat-3.rs index 7f11e7b7df5c8..55fda4c11069e 100644 --- a/src/test/run-pass/unique-pat-3.rs +++ b/src/test/run-pass/unique-pat-3.rs @@ -9,10 +9,10 @@ // except according to those terms. -enum bar { u(~int), w(int), } +enum bar { u(Box), w(int), } pub fn main() { - assert!(match u(~10) { + assert!(match u(box 10) { u(a) => { println!("{:?}", a); *a diff --git a/src/test/run-pass/unique-pat.rs b/src/test/run-pass/unique-pat.rs index 0b9ad6ee194e7..297ded0222d1f 100644 --- a/src/test/run-pass/unique-pat.rs +++ b/src/test/run-pass/unique-pat.rs @@ -9,8 +9,8 @@ // except according to those terms. fn simple() { - match ~true { - ~true => { } + match box true { + box true => { } _ => { fail!(); } } } diff --git a/src/test/run-pass/unique-rec.rs b/src/test/run-pass/unique-rec.rs index f740dd2a22cdb..ff7f009990da7 100644 --- a/src/test/run-pass/unique-rec.rs +++ b/src/test/run-pass/unique-rec.rs @@ -11,7 +11,7 @@ struct X { x: int } pub fn main() { - let x = ~X {x: 1}; + let x = box X {x: 1}; let bar = x; assert_eq!(bar.x, 1); } diff --git a/src/test/run-pass/unique-send-2.rs b/src/test/run-pass/unique-send-2.rs index eec68dae1082d..432a0527adaae 100644 --- a/src/test/run-pass/unique-send-2.rs +++ b/src/test/run-pass/unique-send-2.rs @@ -10,8 +10,8 @@ use std::task; -fn child(tx: &Sender<~uint>, i: uint) { - tx.send(~i); +fn child(tx: &Sender>, i: uint) { + tx.send(box i); } pub fn main() { diff --git a/src/test/run-pass/unique-send.rs b/src/test/run-pass/unique-send.rs index aced7a33da75f..5d622f5cfe8f4 100644 --- a/src/test/run-pass/unique-send.rs +++ b/src/test/run-pass/unique-send.rs @@ -10,7 +10,7 @@ pub fn main() { let (tx, rx) = channel(); - tx.send(~100); + tx.send(box 100); let v = rx.recv(); - assert_eq!(v, ~100); + assert_eq!(v, box 100); } diff --git a/src/test/run-pass/unique-swap.rs b/src/test/run-pass/unique-swap.rs index 779606dba0ccf..1299b28a67ec8 100644 --- a/src/test/run-pass/unique-swap.rs +++ b/src/test/run-pass/unique-swap.rs @@ -11,9 +11,9 @@ use std::mem::swap; pub fn main() { - let mut i = ~100; - let mut j = ~200; + let mut i = box 100; + let mut j = box 200; swap(&mut i, &mut j); - assert_eq!(i, ~200); - assert_eq!(j, ~100); + assert_eq!(i, box 200); + assert_eq!(j, box 100); } diff --git a/src/test/run-pass/unsized2.rs b/src/test/run-pass/unsized2.rs index 7883adad46a37..53db7f37e8d51 100644 --- a/src/test/run-pass/unsized2.rs +++ b/src/test/run-pass/unsized2.rs @@ -9,6 +9,7 @@ // except according to those terms. #![feature(struct_variant)] + // Test sized-ness checking in substitution. // Unbounded. @@ -32,33 +33,33 @@ fn f4(x: &X) { // Self type. trait T2 for type { - fn f() -> ~Self; + fn f() -> Box; } struct S; impl T2 for S { - fn f() -> ~S { - ~S + fn f() -> Box { + box S } } fn f5(x: &X) { - let _: ~X = T2::f(); + let _: Box = T2::f(); } fn f6(x: &X) { - let _: ~X = T2::f(); + let _: Box = T2::f(); } trait T3 for type { - fn f() -> ~Self; + fn f() -> Box; } impl T3 for S { - fn f() -> ~S { - ~S + fn f() -> Box { + box S } } fn f7(x: &X) { // This is valid, but the unsized bound on X is irrelevant because any type // which implements T3 must have statically known size. - let _: ~X = T3::f(); + let _: Box = T3::f(); } trait T4 { diff --git a/src/test/run-pass/unused-move-capture.rs b/src/test/run-pass/unused-move-capture.rs index ceb91d557f6ae..83795e64467e4 100644 --- a/src/test/run-pass/unused-move-capture.rs +++ b/src/test/run-pass/unused-move-capture.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let _x = ~1; + let _x = box 1; let lam_move: || = || {}; lam_move(); } diff --git a/src/test/run-pass/unused-move.rs b/src/test/run-pass/unused-move.rs index 163726fd06a1e..bac9ce814bc27 100644 --- a/src/test/run-pass/unused-move.rs +++ b/src/test/run-pass/unused-move.rs @@ -16,6 +16,6 @@ pub fn main() { - let y = ~1; + let y = box 1; y; } diff --git a/src/test/run-pass/unwind-unique.rs b/src/test/run-pass/unwind-unique.rs index 8bc95b233f1cd..ce2524396184e 100644 --- a/src/test/run-pass/unwind-unique.rs +++ b/src/test/run-pass/unwind-unique.rs @@ -11,7 +11,7 @@ use std::task; fn f() { - let _a = ~0; + let _a = box 0; fail!(); }