Test fixes and rebase conflicts
This commit is contained in:
parent
11e265c2e0
commit
0dc48b47a8
194 changed files with 386 additions and 309 deletions
|
@ -147,10 +147,10 @@ for all but the most trivial of situations.
|
||||||
Here's an example of using `Result`:
|
Here's an example of using `Result`:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#[deriving(Show)]
|
#[derive(Show)]
|
||||||
enum Version { Version1, Version2 }
|
enum Version { Version1, Version2 }
|
||||||
|
|
||||||
#[deriving(Show)]
|
#[derive(Show)]
|
||||||
enum ParseError { InvalidHeaderLength, InvalidVersion }
|
enum ParseError { InvalidHeaderLength, InvalidVersion }
|
||||||
|
|
||||||
fn parse_version(header: &[u8]) -> Result<Version, ParseError> {
|
fn parse_version(header: &[u8]) -> Result<Version, ParseError> {
|
||||||
|
|
|
@ -262,6 +262,7 @@ referenced Rust object.
|
||||||
Rust code:
|
Rust code:
|
||||||
|
|
||||||
~~~~no_run
|
~~~~no_run
|
||||||
|
# use std::boxed::Box;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct RustObject {
|
struct RustObject {
|
||||||
|
@ -286,7 +287,7 @@ extern {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Create the object that will be referenced in the callback
|
// Create the object that will be referenced in the callback
|
||||||
let mut rust_object = box RustObject { a: 5 };
|
let mut rust_object = Box::new(RustObject { a: 5 });
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
register_callback(&mut *rust_object, callback);
|
register_callback(&mut *rust_object, callback);
|
||||||
|
|
|
@ -81,27 +81,29 @@ therefore deallocates the memory for you. Here's the equivalent example in
|
||||||
Rust:
|
Rust:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
# use std::boxed::Box;
|
||||||
{
|
{
|
||||||
let x = box 5i;
|
let x = Box::new(5i);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `box` keyword creates a `Box<T>` (specifically `Box<int>` in this case) by
|
The `Box::new` function creates a `Box<T>` (specifically `Box<int>` in this
|
||||||
allocating a small segment of memory on the heap with enough space to fit an
|
case) by allocating a small segment of memory on the heap with enough space to
|
||||||
`int`. But where in the code is the box deallocated? We said before that we
|
fit an `int`. But where in the code is the box deallocated? We said before that
|
||||||
must have a deallocation for each allocation. Rust handles this for you. It
|
we must have a deallocation for each allocation. Rust handles this for you. It
|
||||||
knows that our handle, `x`, is the owning reference to our box. Rust knows that
|
knows that our handle, `x`, is the owning reference to our box. Rust knows that
|
||||||
`x` will go out of scope at the end of the block, and so it inserts a call to
|
`x` will go out of scope at the end of the block, and so it inserts a call to
|
||||||
deallocate the memory at the end of the scope. Because the compiler does this
|
deallocate the memory at the end of the scope. Because the compiler does this
|
||||||
for us, it's impossible to forget. We always have exactly one deallocation paired
|
for us, it's impossible to forget. We always have exactly one deallocation
|
||||||
with each of our allocations.
|
paired with each of our allocations.
|
||||||
|
|
||||||
This is pretty straightforward, but what happens when we want to pass our box
|
This is pretty straightforward, but what happens when we want to pass our box
|
||||||
to a function? Let's look at some code:
|
to a function? Let's look at some code:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
# use std::boxed::Box;
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 5i;
|
let x = Box::new(5i);
|
||||||
|
|
||||||
add_one(x);
|
add_one(x);
|
||||||
}
|
}
|
||||||
|
@ -115,8 +117,9 @@ This code works, but it's not ideal. For example, let's add one more line of
|
||||||
code, where we print out the value of `x`:
|
code, where we print out the value of `x`:
|
||||||
|
|
||||||
```{rust,ignore}
|
```{rust,ignore}
|
||||||
|
# use std::boxed::Box;
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 5i;
|
let x = Box::new(5i);
|
||||||
|
|
||||||
add_one(x);
|
add_one(x);
|
||||||
|
|
||||||
|
@ -148,8 +151,9 @@ To fix this, we can have `add_one` give ownership back when it's done with the
|
||||||
box:
|
box:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
# use std::boxed::Box;
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 5i;
|
let x = Box::new(5i);
|
||||||
|
|
||||||
let y = add_one(x);
|
let y = add_one(x);
|
||||||
|
|
||||||
|
|
|
@ -455,12 +455,13 @@ fn rc_succ(x: Rc<int>) -> int { *x + 1 }
|
||||||
Note that the caller of your function will have to modify their calls slightly:
|
Note that the caller of your function will have to modify their calls slightly:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
|
# use std::boxed::Box;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
fn succ(x: &int) -> int { *x + 1 }
|
fn succ(x: &int) -> int { *x + 1 }
|
||||||
|
|
||||||
let ref_x = &5i;
|
let ref_x = &5i;
|
||||||
let box_x = box 5i;
|
let box_x = Box::new(5i);
|
||||||
let rc_x = Rc::new(5i);
|
let rc_x = Rc::new(5i);
|
||||||
|
|
||||||
succ(ref_x);
|
succ(ref_x);
|
||||||
|
@ -477,24 +478,17 @@ those contents.
|
||||||
heap allocation in Rust. Creating a box looks like this:
|
heap allocation in Rust. Creating a box looks like this:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
let x = box(std::boxed::HEAP) 5i;
|
# use std::boxed::Box;
|
||||||
|
let x = Box::new(5i);
|
||||||
```
|
```
|
||||||
|
|
||||||
`box` is a keyword that does 'placement new,' which we'll talk about in a bit.
|
Boxes are heap allocated and they are deallocated automatically by Rust when
|
||||||
`box` will be useful for creating a number of heap-allocated types, but is not
|
they go out of scope:
|
||||||
quite finished yet. In the meantime, `box`'s type defaults to
|
|
||||||
`std::boxed::HEAP`, and so you can leave it off:
|
|
||||||
|
|
||||||
```{rust}
|
|
||||||
let x = box 5i;
|
|
||||||
```
|
|
||||||
|
|
||||||
As you might assume from the `HEAP`, boxes are heap allocated. They are
|
|
||||||
deallocated automatically by Rust when they go out of scope:
|
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
|
# use std::boxed::Box;
|
||||||
{
|
{
|
||||||
let x = box 5i;
|
let x = Box::new(5i);
|
||||||
|
|
||||||
// stuff happens
|
// stuff happens
|
||||||
|
|
||||||
|
@ -513,8 +507,9 @@ You don't need to fully grok the theory of affine types or regions to grok
|
||||||
boxes, though. As a rough approximation, you can treat this Rust code:
|
boxes, though. As a rough approximation, you can treat this Rust code:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
|
# use std::boxed::Box;
|
||||||
{
|
{
|
||||||
let x = box 5i;
|
let x = Box::new(5i);
|
||||||
|
|
||||||
// stuff happens
|
// stuff happens
|
||||||
}
|
}
|
||||||
|
@ -553,12 +548,13 @@ for more detail on how lifetimes work.
|
||||||
Using boxes and references together is very common. For example:
|
Using boxes and references together is very common. For example:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
|
# use std::boxed::Box;
|
||||||
fn add_one(x: &int) -> int {
|
fn add_one(x: &int) -> int {
|
||||||
*x + 1
|
*x + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 5i;
|
let x = Box::new(5i);
|
||||||
|
|
||||||
println!("{}", add_one(&*x));
|
println!("{}", add_one(&*x));
|
||||||
}
|
}
|
||||||
|
@ -570,12 +566,13 @@ function, and since it's only reading the value, allows it.
|
||||||
We can borrow `x` multiple times, as long as it's not simultaneous:
|
We can borrow `x` multiple times, as long as it's not simultaneous:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
|
# use std::boxed::Box;
|
||||||
fn add_one(x: &int) -> int {
|
fn add_one(x: &int) -> int {
|
||||||
*x + 1
|
*x + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 5i;
|
let x = Box::new(5i);
|
||||||
|
|
||||||
println!("{}", add_one(&*x));
|
println!("{}", add_one(&*x));
|
||||||
println!("{}", add_one(&*x));
|
println!("{}", add_one(&*x));
|
||||||
|
@ -586,12 +583,13 @@ fn main() {
|
||||||
Or as long as it's not a mutable borrow. This will error:
|
Or as long as it's not a mutable borrow. This will error:
|
||||||
|
|
||||||
```{rust,ignore}
|
```{rust,ignore}
|
||||||
|
# use std::boxed::Box;
|
||||||
fn add_one(x: &mut int) -> int {
|
fn add_one(x: &mut int) -> int {
|
||||||
*x + 1
|
*x + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 5i;
|
let x = Box::new(5i);
|
||||||
|
|
||||||
println!("{}", add_one(&*x)); // error: cannot borrow immutable dereference
|
println!("{}", add_one(&*x)); // error: cannot borrow immutable dereference
|
||||||
// of `&`-pointer as mutable
|
// of `&`-pointer as mutable
|
||||||
|
@ -612,14 +610,15 @@ Sometimes, you need a recursive data structure. The simplest is known as a
|
||||||
|
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
#[deriving(Show)]
|
# use std::boxed::Box;
|
||||||
|
#[derive(Show)]
|
||||||
enum List<T> {
|
enum List<T> {
|
||||||
Cons(T, Box<List<T>>),
|
Cons(T, Box<List<T>>),
|
||||||
Nil,
|
Nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let list: List<int> = List::Cons(1, box List::Cons(2, box List::Cons(3, box List::Nil)));
|
let list: List<int> = List::Cons(1, Box::new(List::Cons(2, Box::new(List::Cons(3, Box::new(List::Nil))))));
|
||||||
println!("{:?}", list);
|
println!("{:?}", list);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -627,7 +626,7 @@ fn main() {
|
||||||
This prints:
|
This prints:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Cons(1, box Cons(2, box Cons(3, box Nil)))
|
Cons(1, Box(Cons(2, Box(Cons(3, Box(Nil))))))
|
||||||
```
|
```
|
||||||
|
|
||||||
The reference to another `List` inside of the `Cons` enum variant must be a box,
|
The reference to another `List` inside of the `Cons` enum variant must be a box,
|
||||||
|
@ -667,6 +666,7 @@ In many languages with pointers, you'd return a pointer from a function
|
||||||
so as to avoid copying a large data structure. For example:
|
so as to avoid copying a large data structure. For example:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
|
# use std::boxed::Box;
|
||||||
struct BigStruct {
|
struct BigStruct {
|
||||||
one: int,
|
one: int,
|
||||||
two: int,
|
two: int,
|
||||||
|
@ -675,15 +675,15 @@ struct BigStruct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo(x: Box<BigStruct>) -> Box<BigStruct> {
|
fn foo(x: Box<BigStruct>) -> Box<BigStruct> {
|
||||||
return box *x;
|
return Box::new(*x);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box BigStruct {
|
let x = Box::new(BigStruct {
|
||||||
one: 1,
|
one: 1,
|
||||||
two: 2,
|
two: 2,
|
||||||
one_hundred: 100,
|
one_hundred: 100,
|
||||||
};
|
});
|
||||||
|
|
||||||
let y = foo(x);
|
let y = foo(x);
|
||||||
}
|
}
|
||||||
|
@ -695,6 +695,7 @@ than the hundred `int`s that make up the `BigStruct`.
|
||||||
This is an antipattern in Rust. Instead, write this:
|
This is an antipattern in Rust. Instead, write this:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
|
# use std::boxed::Box;
|
||||||
struct BigStruct {
|
struct BigStruct {
|
||||||
one: int,
|
one: int,
|
||||||
two: int,
|
two: int,
|
||||||
|
@ -707,13 +708,13 @@ fn foo(x: Box<BigStruct>) -> BigStruct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box BigStruct {
|
let x = Box::new(BigStruct {
|
||||||
one: 1,
|
one: 1,
|
||||||
two: 2,
|
two: 2,
|
||||||
one_hundred: 100,
|
one_hundred: 100,
|
||||||
};
|
});
|
||||||
|
|
||||||
let y = box foo(x);
|
let y = Box::new(foo(x));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,7 @@ extern crate libc;
|
||||||
use libc::{c_void, size_t, malloc, free};
|
use libc::{c_void, size_t, malloc, free};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
# use std::boxed::Box;
|
||||||
|
|
||||||
// Define a wrapper around the handle returned by the foreign code.
|
// Define a wrapper around the handle returned by the foreign code.
|
||||||
// Unique<T> has the same semantics as Box<T>
|
// Unique<T> has the same semantics as Box<T>
|
||||||
|
@ -265,7 +266,7 @@ impl<T: Send> Drop for Unique<T> {
|
||||||
// A comparison between the built-in `Box` and this reimplementation
|
// A comparison between the built-in `Box` and this reimplementation
|
||||||
fn main() {
|
fn main() {
|
||||||
{
|
{
|
||||||
let mut x = box 5i;
|
let mut x = Box::new(5i);
|
||||||
*x = 10;
|
*x = 10;
|
||||||
} // `x` is freed here
|
} // `x` is freed here
|
||||||
|
|
||||||
|
@ -653,7 +654,7 @@ sugar for dynamic allocations via `malloc` and `free`:
|
||||||
|
|
||||||
```
|
```
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![feature(lang_items)]
|
#![feature(lang_items, box_syntax)]
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
|
|
@ -3802,18 +3802,19 @@ enum List { // error: illegal recursive enum type
|
||||||
|
|
||||||
But the compiler complains that the type is recursive, that is, it could be
|
But the compiler complains that the type is recursive, that is, it could be
|
||||||
arbitrarily large. To remedy this, Rust provides a fixed-size container called
|
arbitrarily large. To remedy this, Rust provides a fixed-size container called
|
||||||
a **box** that can hold any type. You can box up any value with the `box`
|
a **Box** that can hold any type. You can box up any value with the `Box::new`
|
||||||
keyword. Our boxed List gets the type `Box<List>` (more on the notation when we
|
function. Our boxed List gets the type `Box<List>` (more on the notation when we
|
||||||
get to generics):
|
get to generics):
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
|
# use std::boxed::Box;
|
||||||
enum List {
|
enum List {
|
||||||
Node(u32, Box<List>),
|
Node(u32, Box<List>),
|
||||||
Nil
|
Nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let list = List::Node(0, box List::Node(1, box List::Nil));
|
let list = List::Node(0, Box::new(List::Node(1, Box::new(List::Nil))));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -3826,8 +3827,9 @@ just like regular references. This (rather silly) example dynamically allocates
|
||||||
an integer `5` and makes `x` a pointer to it:
|
an integer `5` and makes `x` a pointer to it:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
|
# use std::boxed::Box;
|
||||||
{
|
{
|
||||||
let x = box 5;
|
let x = Box::new(5);
|
||||||
println!("{}", *x); // Prints 5
|
println!("{}", *x); // Prints 5
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -3858,7 +3860,8 @@ Boxes are the sole owner of their contents, so you cannot take a mutable
|
||||||
reference to them and then use the original box:
|
reference to them and then use the original box:
|
||||||
|
|
||||||
```{rust,ignore}
|
```{rust,ignore}
|
||||||
let mut x = box 5;
|
# use std::boxed::Box;
|
||||||
|
let mut x = Box::new(5);
|
||||||
let y = &mut x;
|
let y = &mut x;
|
||||||
|
|
||||||
*x; // you might expect 5, but this is actually an error
|
*x; // you might expect 5, but this is actually an error
|
||||||
|
@ -3879,7 +3882,8 @@ As long as `y` is borrowing the contents, we cannot use `x`. After `y` is
|
||||||
done borrowing the value, we can use it again. This works fine:
|
done borrowing the value, we can use it again. This works fine:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
let mut x = box 5;
|
# use std::boxed::Box;
|
||||||
|
let mut x = Box::new(5);
|
||||||
|
|
||||||
{
|
{
|
||||||
let y = &mut x;
|
let y = &mut x;
|
||||||
|
|
|
@ -1588,10 +1588,11 @@ pointer values (pointing to a type for which an implementation of the given
|
||||||
trait is in scope) to pointers to the trait name, used as a type.
|
trait is in scope) to pointers to the trait name, used as a type.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
# use std::boxed::Box;
|
||||||
# trait Shape { }
|
# trait Shape { }
|
||||||
# impl Shape for int { }
|
# impl Shape for int { }
|
||||||
# let mycircle = 0i;
|
# let mycircle = 0i;
|
||||||
let myshape: Box<Shape> = box mycircle as Box<Shape>;
|
let myshape: Box<Shape> = Box::new(mycircle) as Box<Shape>;
|
||||||
```
|
```
|
||||||
|
|
||||||
The resulting value is a box containing the value that was cast, along with
|
The resulting value is a box containing the value that was cast, along with
|
||||||
|
@ -1646,12 +1647,13 @@ fn radius_times_area<T: Circle>(c: T) -> f64 {
|
||||||
Likewise, supertrait methods may also be called on trait objects.
|
Likewise, supertrait methods may also be called on trait objects.
|
||||||
|
|
||||||
```{.ignore}
|
```{.ignore}
|
||||||
|
# use std::boxed::Box;
|
||||||
# trait Shape { fn area(&self) -> f64; }
|
# trait Shape { fn area(&self) -> f64; }
|
||||||
# trait Circle : Shape { fn radius(&self) -> f64; }
|
# trait Circle : Shape { fn radius(&self) -> f64; }
|
||||||
# impl Shape for int { fn area(&self) -> f64 { 0.0 } }
|
# impl Shape for int { fn area(&self) -> f64 { 0.0 } }
|
||||||
# impl Circle for int { fn radius(&self) -> f64 { 0.0 } }
|
# impl Circle for int { fn radius(&self) -> f64 { 0.0 } }
|
||||||
# let mycircle = 0;
|
# let mycircle = 0;
|
||||||
let mycircle = box mycircle as Box<Circle>;
|
let mycircle = Box::new(mycircle) as Box<Circle>;
|
||||||
let nonsense = mycircle.radius() * mycircle.area();
|
let nonsense = mycircle.radius() * mycircle.area();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -3376,14 +3378,17 @@ stands for a *single* data field, whereas a wildcard `..` stands for *all* the
|
||||||
fields of a particular variant. For example:
|
fields of a particular variant. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
#![feature(box_syntax)]
|
||||||
enum List<X> { Nil, Cons(X, Box<List<X>>) }
|
enum List<X> { Nil, Cons(X, Box<List<X>>) }
|
||||||
|
|
||||||
let x: List<int> = List::Cons(10, box List::Cons(11, box List::Nil));
|
fn main() {
|
||||||
|
let x: List<int> = List::Cons(10, box List::Cons(11, box List::Nil));
|
||||||
|
|
||||||
match x {
|
match x {
|
||||||
List::Cons(_, box List::Nil) => panic!("singleton list"),
|
List::Cons(_, box List::Nil) => panic!("singleton list"),
|
||||||
List::Cons(..) => return,
|
List::Cons(..) => return,
|
||||||
List::Nil => panic!("empty list")
|
List::Nil => panic!("empty list")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -3436,25 +3441,28 @@ the inside of the match.
|
||||||
An example of a `match` expression:
|
An example of a `match` expression:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
#![feature(box_syntax)]
|
||||||
# fn process_pair(a: int, b: int) { }
|
# fn process_pair(a: int, b: int) { }
|
||||||
# fn process_ten() { }
|
# fn process_ten() { }
|
||||||
|
|
||||||
enum List<X> { Nil, Cons(X, Box<List<X>>) }
|
enum List<X> { Nil, Cons(X, Box<List<X>>) }
|
||||||
|
|
||||||
let x: List<int> = List::Cons(10, box List::Cons(11, box List::Nil));
|
fn main() {
|
||||||
|
let x: List<int> = List::Cons(10, box List::Cons(11, box List::Nil));
|
||||||
|
|
||||||
match x {
|
match x {
|
||||||
List::Cons(a, box List::Cons(b, _)) => {
|
List::Cons(a, box List::Cons(b, _)) => {
|
||||||
process_pair(a, b);
|
process_pair(a, b);
|
||||||
}
|
}
|
||||||
List::Cons(10, _) => {
|
List::Cons(10, _) => {
|
||||||
process_ten();
|
process_ten();
|
||||||
}
|
}
|
||||||
List::Nil => {
|
List::Nil => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
panic!();
|
panic!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -3468,6 +3476,8 @@ Subpatterns can also be bound to variables by the use of the syntax `variable @
|
||||||
subpattern`. For example:
|
subpattern`. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
enum List { Nil, Cons(uint, Box<List>) }
|
enum List { Nil, Cons(uint, Box<List>) }
|
||||||
|
|
||||||
fn is_sorted(list: &List) -> bool {
|
fn is_sorted(list: &List) -> bool {
|
||||||
|
@ -3781,12 +3791,13 @@ enclosing `enum` or `struct` type itself. Such recursion has restrictions:
|
||||||
An example of a *recursive* type and its use:
|
An example of a *recursive* type and its use:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
# use std::boxed::Box;
|
||||||
enum List<T> {
|
enum List<T> {
|
||||||
Nil,
|
Nil,
|
||||||
Cons(T, Box<List<T>>)
|
Cons(T, Box<List<T>>)
|
||||||
}
|
}
|
||||||
|
|
||||||
let a: List<int> = List::Cons(7, box List::Cons(13, box List::Nil));
|
let a: List<int> = List::Cons(7, Box::new(List::Cons(13, Box::new(List::Nil))));
|
||||||
```
|
```
|
||||||
|
|
||||||
### Pointer types
|
### Pointer types
|
||||||
|
@ -3893,6 +3904,7 @@ implementation of `R`, and the pointer value of `E`.
|
||||||
An example of an object type:
|
An example of an object type:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
# use std::boxed::Box;
|
||||||
trait Printable {
|
trait Printable {
|
||||||
fn stringify(&self) -> String;
|
fn stringify(&self) -> String;
|
||||||
}
|
}
|
||||||
|
@ -3906,7 +3918,7 @@ fn print(a: Box<Printable>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
print(box 10i as Box<Printable>);
|
print(Box::new(10i) as Box<Printable>);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -4100,7 +4112,8 @@ the type of a box is `std::owned::Box<T>`.
|
||||||
An example of a box type and value:
|
An example of a box type and value:
|
||||||
|
|
||||||
```
|
```
|
||||||
let x: Box<int> = box 10;
|
# use std::boxed::Box;
|
||||||
|
let x: Box<int> = Box::new(10);
|
||||||
```
|
```
|
||||||
|
|
||||||
Box values exist in 1:1 correspondence with their heap allocation, copying a
|
Box values exist in 1:1 correspondence with their heap allocation, copying a
|
||||||
|
@ -4109,7 +4122,8 @@ copy of a box to move ownership of the value. After a value has been moved,
|
||||||
the source location cannot be used unless it is reinitialized.
|
the source location cannot be used unless it is reinitialized.
|
||||||
|
|
||||||
```
|
```
|
||||||
let x: Box<int> = box 10;
|
# use std::boxed::Box;
|
||||||
|
let x: Box<int> = Box::new(10);
|
||||||
let y = x;
|
let y = x;
|
||||||
// attempting to use `x` will result in an error here
|
// attempting to use `x` will result in an error here
|
||||||
```
|
```
|
||||||
|
|
|
@ -33,12 +33,15 @@ use core::ops::{Deref, DerefMut};
|
||||||
/// The following two examples are equivalent:
|
/// The following two examples are equivalent:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// #![feature(box_syntax)]
|
||||||
/// use std::boxed::HEAP;
|
/// use std::boxed::HEAP;
|
||||||
///
|
///
|
||||||
|
/// fn main() {
|
||||||
/// # struct Bar;
|
/// # struct Bar;
|
||||||
/// # impl Bar { fn new(_a: int) { } }
|
/// # impl Bar { fn new(_a: int) { } }
|
||||||
/// let foo = box(HEAP) Bar::new(2);
|
/// let foo = box(HEAP) Bar::new(2);
|
||||||
/// let foo = box Bar::new(2);
|
/// let foo = box Bar::new(2);
|
||||||
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[lang = "exchange_heap"]
|
#[lang = "exchange_heap"]
|
||||||
#[experimental = "may be renamed; uncertain about custom allocator design"]
|
#[experimental = "may be renamed; uncertain about custom allocator design"]
|
||||||
|
@ -49,10 +52,9 @@ pub static HEAP: () = ();
|
||||||
#[stable]
|
#[stable]
|
||||||
pub struct Box<T>(Unique<T>);
|
pub struct Box<T>(Unique<T>);
|
||||||
|
|
||||||
#[unstable]
|
|
||||||
impl<T> Box<T> {
|
impl<T> Box<T> {
|
||||||
/// Moves `x` into a freshly allocated box on the global exchange heap.
|
/// Moves `x` into a freshly allocated box on the global exchange heap.
|
||||||
#[unstable]
|
#[stable]
|
||||||
pub fn new(x: T) -> Box<T> {
|
pub fn new(x: T) -> Box<T> {
|
||||||
box x
|
box x
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ const MIN_ALIGN: uint = 8;
|
||||||
not(feature = "external_crate"),
|
not(feature = "external_crate"),
|
||||||
any(target_arch = "x86",
|
any(target_arch = "x86",
|
||||||
target_arch = "x86_64",
|
target_arch = "x86_64",
|
||||||
target_arch = "aarch64"))]
|
target_arch = "aarch64")))]
|
||||||
const MIN_ALIGN: uint = 16;
|
const MIN_ALIGN: uint = 16;
|
||||||
|
|
||||||
#[cfg(feature = "external_funcs")]
|
#[cfg(feature = "external_funcs")]
|
||||||
|
|
|
@ -28,8 +28,10 @@
|
||||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||||
|
|
||||||
|
#![allow(unknown_features)]
|
||||||
#![feature(unsafe_destructor)]
|
#![feature(unsafe_destructor)]
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
|
#![feature(box_syntax)]
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#[stable]
|
#[stable]
|
||||||
macro_rules! vec {
|
macro_rules! vec {
|
||||||
($($x:expr),*) => ({
|
($($x:expr),*) => ({
|
||||||
let xs: $crate::boxed::Box<[_]> = box [$($x),*];
|
let xs: $crate::boxed::Box<[_]> = $crate::boxed::Box::new([$($x),*]);
|
||||||
$crate::slice::SliceExt::into_vec(xs)
|
$crate::slice::SliceExt::into_vec(xs)
|
||||||
});
|
});
|
||||||
($($x:expr,)*) => (vec![$($x),*])
|
($($x:expr,)*) => (vec![$($x),*])
|
||||||
|
|
|
@ -245,7 +245,7 @@ pub trait SliceExt {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// let v = &[1i, 2, 3, 4];
|
/// let v = &[1i, 2, 3, 4];
|
||||||
/// for win in v.windows(2) {
|
/// for win in v.windows(2) {
|
||||||
/// println!("{}", win);
|
/// println!("{:?}", win);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[stable]
|
#[stable]
|
||||||
|
@ -268,7 +268,7 @@ pub trait SliceExt {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// let v = &[1i, 2, 3, 4, 5];
|
/// let v = &[1i, 2, 3, 4, 5];
|
||||||
/// for win in v.chunks(2) {
|
/// for win in v.chunks(2) {
|
||||||
/// println!("{}", win);
|
/// println!("{:?}", win);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[stable]
|
#[stable]
|
||||||
|
@ -554,7 +554,7 @@ pub trait SliceExt {
|
||||||
/// let mut perms = v.permutations();
|
/// let mut perms = v.permutations();
|
||||||
///
|
///
|
||||||
/// for p in perms {
|
/// for p in perms {
|
||||||
/// println!("{}", p);
|
/// println!("{:?}", p);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#![experimental]
|
#![experimental]
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
use marker::Sized;
|
use marker::Sized;
|
||||||
|
|
||||||
pub type GlueFn = extern "Rust" fn(*const i8);
|
pub type GlueFn = extern "Rust" fn(*const i8);
|
||||||
|
|
|
@ -2804,7 +2804,7 @@ pub fn iterate<T, F>(seed: T, f: F) -> Iterate<T, F> where
|
||||||
T: Clone,
|
T: Clone,
|
||||||
F: FnMut(T) -> T,
|
F: FnMut(T) -> T,
|
||||||
{
|
{
|
||||||
let &(ref mut f, ref mut val, ref mut first) = st;
|
let &mut (ref mut f, ref mut val, ref mut first) = st;
|
||||||
if *first {
|
if *first {
|
||||||
*first = false;
|
*first = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![allow(unknown_features, raw_pointer_derive)]
|
#![allow(unknown_features, raw_pointer_derive)]
|
||||||
|
#![cfg_attr(stage0, allow(unused_attributes))]
|
||||||
#![feature(intrinsics, lang_items)]
|
#![feature(intrinsics, lang_items)]
|
||||||
#![feature(simd, unsafe_destructor, slicing_syntax)]
|
#![feature(simd, unsafe_destructor, slicing_syntax)]
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
|
|
|
@ -17,5 +17,9 @@
|
||||||
#![stable]
|
#![stable]
|
||||||
#![doc(primitive = "isize")]
|
#![doc(primitive = "isize")]
|
||||||
|
|
||||||
#[cfg(target_word_size = "32")] int_module! { isize, 32 }
|
#[cfg(any(all(stage0, target_word_size = "32"),
|
||||||
#[cfg(target_word_size = "64")] int_module! { isize, 64 }
|
all(not(stage0), target_pointer_width = "32")))]
|
||||||
|
int_module! { isize, 32 }
|
||||||
|
#[cfg(any(all(stage0, target_word_size = "64"),
|
||||||
|
all(not(stage0), target_pointer_width = "64")))]
|
||||||
|
int_module! { isize, 64 }
|
||||||
|
|
|
@ -66,10 +66,11 @@
|
||||||
//! not (`None`).
|
//! not (`None`).
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
//! # use std::boxed::Box;
|
||||||
//! let optional: Option<Box<int>> = None;
|
//! let optional: Option<Box<int>> = None;
|
||||||
//! check_optional(&optional);
|
//! check_optional(&optional);
|
||||||
//!
|
//!
|
||||||
//! let optional: Option<Box<int>> = Some(box 9000);
|
//! let optional: Option<Box<int>> = Some(Box::new(9000));
|
||||||
//! check_optional(&optional);
|
//! check_optional(&optional);
|
||||||
//!
|
//!
|
||||||
//! fn check_optional(optional: &Option<Box<int>>) {
|
//! fn check_optional(optional: &Option<Box<int>>) {
|
||||||
|
@ -148,7 +149,6 @@ use self::Option::*;
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
use cmp::{Eq, Ord};
|
use cmp::{Eq, Ord};
|
||||||
use default::Default;
|
use default::Default;
|
||||||
use fmt;
|
|
||||||
use iter::{ExactSizeIterator};
|
use iter::{ExactSizeIterator};
|
||||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator};
|
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator};
|
||||||
use mem;
|
use mem;
|
||||||
|
|
|
@ -46,12 +46,13 @@
|
||||||
//! though unsafely, transformed from one type to the other.
|
//! though unsafely, transformed from one type to the other.
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
//! # use std::boxed::Box;
|
||||||
//! use std::mem;
|
//! use std::mem;
|
||||||
//!
|
//!
|
||||||
//! unsafe {
|
//! unsafe {
|
||||||
//! let my_num: Box<int> = box 10;
|
//! let my_num: Box<int> = Box::new(10);
|
||||||
//! let my_num: *const int = mem::transmute(my_num);
|
//! let my_num: *const int = mem::transmute(my_num);
|
||||||
//! let my_speed: Box<int> = box 88;
|
//! let my_speed: Box<int> = Box::new(88);
|
||||||
//! let my_speed: *mut int = mem::transmute(my_speed);
|
//! let my_speed: *mut int = mem::transmute(my_speed);
|
||||||
//!
|
//!
|
||||||
//! // By taking ownership of the original `Box<T>` though
|
//! // By taking ownership of the original `Box<T>` though
|
||||||
|
|
|
@ -113,6 +113,5 @@ fn test_custom_state() {
|
||||||
::std::hash::hash::<_, CustomHasher>(t)
|
::std::hash::hash::<_, CustomHasher>(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
let custom = Custom { hash: 5 };
|
|
||||||
assert_eq!(hash(&Custom { hash: 5 }), 5);
|
assert_eq!(hash(&Custom { hash: 5 }), 5);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,10 @@
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
#![feature(globs, unsafe_destructor, slicing_syntax, default_type_params)]
|
|
||||||
|
#![feature(unsafe_destructor, slicing_syntax)]
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
extern crate core;
|
extern crate core;
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use core::iter::range;
|
|
||||||
|
|
||||||
pub fn op1() -> Result<int, &'static str> { Ok(666) }
|
pub fn op1() -> Result<int, &'static str> { Ok(666) }
|
||||||
pub fn op2() -> Result<int, &'static str> { Err("sadface") }
|
pub fn op2() -> Result<int, &'static str> { Err("sadface") }
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ pub trait Rng : Sized {
|
||||||
///
|
///
|
||||||
/// let mut rng = thread_rng();
|
/// let mut rng = thread_rng();
|
||||||
/// let x = rng.gen_iter::<uint>().take(10).collect::<Vec<uint>>();
|
/// let x = rng.gen_iter::<uint>().take(10).collect::<Vec<uint>>();
|
||||||
/// println!("{}", x);
|
/// println!("{:?}", x);
|
||||||
/// println!("{:?}", rng.gen_iter::<(f64, bool)>().take(5)
|
/// println!("{:?}", rng.gen_iter::<(f64, bool)>().take(5)
|
||||||
/// .collect::<Vec<(f64, bool)>>());
|
/// .collect::<Vec<(f64, bool)>>());
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -291,9 +291,9 @@ pub trait Rng : Sized {
|
||||||
/// let mut rng = thread_rng();
|
/// let mut rng = thread_rng();
|
||||||
/// let mut y = [1i, 2, 3];
|
/// let mut y = [1i, 2, 3];
|
||||||
/// rng.shuffle(&mut y);
|
/// rng.shuffle(&mut y);
|
||||||
/// println!("{}", y.as_slice());
|
/// println!("{:?}", y.as_slice());
|
||||||
/// rng.shuffle(&mut y);
|
/// rng.shuffle(&mut y);
|
||||||
/// println!("{}", y.as_slice());
|
/// println!("{:?}", y.as_slice());
|
||||||
/// ```
|
/// ```
|
||||||
fn shuffle<T>(&mut self, values: &mut [T]) {
|
fn shuffle<T>(&mut self, values: &mut [T]) {
|
||||||
let mut i = values.len();
|
let mut i = values.len();
|
||||||
|
|
|
@ -1918,7 +1918,7 @@ impl LintPass for HardwiredLints {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Forbids using the `#[feature(...)]` attribute
|
/// Forbids using the `#[feature(...)]` attribute
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
pub struct UnstableFeatures;
|
pub struct UnstableFeatures;
|
||||||
|
|
||||||
declare_lint!(UNSTABLE_FEATURES, Allow,
|
declare_lint!(UNSTABLE_FEATURES, Allow,
|
||||||
|
|
|
@ -443,7 +443,7 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
|
||||||
}
|
}
|
||||||
|
|
||||||
for note in note.into_iter() {
|
for note in note.into_iter() {
|
||||||
sess.note(note.index(&FullRange));
|
sess.note(¬e[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for span in def.into_iter() {
|
for span in def.into_iter() {
|
||||||
|
|
|
@ -116,7 +116,7 @@ pub struct Options {
|
||||||
pub unstable_features: UnstableFeatures
|
pub unstable_features: UnstableFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum UnstableFeatures {
|
pub enum UnstableFeatures {
|
||||||
/// Hard errors for unstable features are active, as on
|
/// Hard errors for unstable features are active, as on
|
||||||
/// beta/stable channels.
|
/// beta/stable channels.
|
||||||
|
|
|
@ -29,7 +29,8 @@
|
||||||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||||
#![feature(slicing_syntax)]
|
#![allow(unknown_features)]
|
||||||
|
#![feature(slicing_syntax, box_syntax)]
|
||||||
|
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
|
|
|
@ -61,7 +61,7 @@ fn remove_message(e: &mut ExpectErrorEmitter, msg: &str, lvl: Level) {
|
||||||
e.messages.remove(i);
|
e.messages.remove(i);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
panic!("Unexpected error: {} Expected: {}",
|
panic!("Unexpected error: {} Expected: {:?}",
|
||||||
msg, e.messages);
|
msg, e.messages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ use std::rc::Rc;
|
||||||
use llvm::{ValueRef, True, IntEQ, IntNE};
|
use llvm::{ValueRef, True, IntEQ, IntNE};
|
||||||
use back::abi::FAT_PTR_ADDR;
|
use back::abi::FAT_PTR_ADDR;
|
||||||
use middle::subst;
|
use middle::subst;
|
||||||
use middle::ty::{mod, Ty, UnboxedClosureTyper};
|
use middle::ty::{self, Ty, UnboxedClosureTyper};
|
||||||
use middle::ty::Disr;
|
use middle::ty::Disr;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
|
|
|
@ -1345,7 +1345,7 @@ pub fn with_field_tys<'tcx, R, F>(tcx: &ty::ctxt<'tcx>,
|
||||||
tcx, enum_id, variant_id);
|
tcx, enum_id, variant_id);
|
||||||
let fields = struct_fields(tcx, variant_id, substs);
|
let fields = struct_fields(tcx, variant_id, substs);
|
||||||
let fields = monomorphize::normalize_associated_type(tcx, &fields);
|
let fields = monomorphize::normalize_associated_type(tcx, &fields);
|
||||||
op(variant_info.disr_val, &fields.index[])
|
op(variant_info.disr_val, &fields[])
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
tcx.sess.bug("resolve didn't map this expr to a \
|
tcx.sess.bug("resolve didn't map this expr to a \
|
||||||
|
|
|
@ -68,9 +68,13 @@ fn get_base_type_def_id<'a, 'tcx>(inference_context: &InferCtxt<'a, 'tcx>,
|
||||||
Some(t.principal_def_id())
|
Some(t.principal_def_id())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ty_uniq(_) => {
|
||||||
|
inference_context.tcx.lang_items.owned_box()
|
||||||
|
}
|
||||||
|
|
||||||
ty_bool | ty_char | ty_int(..) | ty_uint(..) | ty_float(..) |
|
ty_bool | ty_char | ty_int(..) | ty_uint(..) | ty_float(..) |
|
||||||
ty_str(..) | ty_vec(..) | ty_bare_fn(..) | ty_tup(..) |
|
ty_str(..) | ty_vec(..) | ty_bare_fn(..) | ty_tup(..) |
|
||||||
ty_param(..) | ty_err | ty_open(..) | ty_uniq(_) |
|
ty_param(..) | ty_err | ty_open(..) |
|
||||||
ty_ptr(_) | ty_rptr(_, _) | ty_projection(..) => {
|
ty_ptr(_) | ty_rptr(_, _) | ty_projection(..) => {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -2454,7 +2454,7 @@ fn lang_struct(cx: &DocContext, did: Option<ast::DefId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An equality constraint on an associated type, e.g. `A=Bar` in `Foo<A=Bar>`
|
/// An equality constraint on an associated type, e.g. `A=Bar` in `Foo<A=Bar>`
|
||||||
#[derive(Clone, PartialEq, RustcDecodable, RustcEncodable)]
|
#[derive(Clone, PartialEq, RustcDecodable, RustcEncodable, Show)]
|
||||||
pub struct TypeBinding {
|
pub struct TypeBinding {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub ty: Type
|
pub ty: Type
|
||||||
|
|
|
@ -163,7 +163,7 @@ impl<K, V, S> Encodable for HashMap<K, V, S>
|
||||||
S: HashState,
|
S: HashState,
|
||||||
<S as HashState>::Hasher: Hasher<Output=u64>
|
<S as HashState>::Hasher: Hasher<Output=u64>
|
||||||
{
|
{
|
||||||
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
|
fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
|
||||||
e.emit_map(self.len(), |e| {
|
e.emit_map(self.len(), |e| {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for (key, val) in self.iter() {
|
for (key, val) in self.iter() {
|
||||||
|
@ -201,7 +201,7 @@ impl<T, S> Encodable for HashSet<T, S>
|
||||||
S: HashState,
|
S: HashState,
|
||||||
<S as HashState>::Hasher: Hasher<Output=u64>
|
<S as HashState>::Hasher: Hasher<Output=u64>
|
||||||
{
|
{
|
||||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> {
|
||||||
s.emit_seq(self.len(), |s| {
|
s.emit_seq(self.len(), |s| {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for e in self.iter() {
|
for e in self.iter() {
|
||||||
|
|
|
@ -175,7 +175,7 @@
|
||||||
//! use std::f64;
|
//! use std::f64;
|
||||||
//! use std::num::Float;
|
//! use std::num::Float;
|
||||||
//!
|
//!
|
||||||
//! #[deriving(Show)]
|
//! #[derive(Show)]
|
||||||
//! struct Vector2D {
|
//! struct Vector2D {
|
||||||
//! x: int,
|
//! x: int,
|
||||||
//! y: int,
|
//! y: int,
|
||||||
|
|
|
@ -1284,7 +1284,7 @@ impl<'a> Writer for &'a mut (Writer+'a) {
|
||||||
/// process_input(tee);
|
/// process_input(tee);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// println!("input processed: {}", output);
|
/// println!("input processed: {:?}", output);
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct RefWriter<'a, W:'a> {
|
pub struct RefWriter<'a, W:'a> {
|
||||||
|
|
|
@ -403,7 +403,7 @@ pub fn random<T: Rand>() -> T {
|
||||||
///
|
///
|
||||||
/// let mut rng = thread_rng();
|
/// let mut rng = thread_rng();
|
||||||
/// let sample = sample(&mut rng, range(1i, 100), 5);
|
/// let sample = sample(&mut rng, range(1i, 100), 5);
|
||||||
/// println!("{}", sample);
|
/// println!("{:?}", sample);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn sample<T, I: Iterator<Item=T>, R: Rng>(rng: &mut R,
|
pub fn sample<T, I: Iterator<Item=T>, R: Rng>(rng: &mut R,
|
||||||
mut iter: I,
|
mut iter: I,
|
||||||
|
|
|
@ -270,7 +270,7 @@ pub fn readdir(p: &Path) -> IoResult<Vec<Path>> {
|
||||||
return Err(IoError {
|
return Err(IoError {
|
||||||
kind: io::InvalidInput,
|
kind: io::InvalidInput,
|
||||||
desc: "path was not valid UTF-16",
|
desc: "path was not valid UTF-16",
|
||||||
detail: Some(format!("path was not valid UTF-16: {}", filename)),
|
detail: Some(format!("path was not valid UTF-16: {:?}", filename)),
|
||||||
})
|
})
|
||||||
}, // FIXME #12056: Convert the UCS-2 to invalid utf-8 instead of erroring
|
}, // FIXME #12056: Convert the UCS-2 to invalid utf-8 instead of erroring
|
||||||
}
|
}
|
||||||
|
|
|
@ -1730,11 +1730,8 @@ pub struct MacroDef {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use serialize::json;
|
|
||||||
use serialize;
|
use serialize;
|
||||||
use codemap::*;
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
// are ASTs encodable?
|
// are ASTs encodable?
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1295,7 +1295,7 @@ impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::{pattern_bindings, expand_crate, contains_macro_use};
|
use super::{pattern_bindings, expand_crate};
|
||||||
use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer, ExpansionConfig};
|
use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer, ExpansionConfig};
|
||||||
use ast;
|
use ast;
|
||||||
use ast::{Attribute_, AttrOuter, MetaWord, Name};
|
use ast::{Attribute_, AttrOuter, MetaWord, Name};
|
||||||
|
@ -1404,22 +1404,6 @@ mod test {
|
||||||
expand_crate(&sess, test_ecfg(), vec!(), vec!(), crate_ast);
|
expand_crate(&sess, test_ecfg(), vec!(), vec!(), crate_ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make a MetaWord outer attribute with the given name
|
|
||||||
fn make_dummy_attr(s: &str) -> ast::Attribute {
|
|
||||||
Spanned {
|
|
||||||
span:codemap::DUMMY_SP,
|
|
||||||
node: Attribute_ {
|
|
||||||
id: attr::mk_attr_id(),
|
|
||||||
style: AttrOuter,
|
|
||||||
value: P(Spanned {
|
|
||||||
node: MetaWord(token::intern_and_get_ident(s)),
|
|
||||||
span: codemap::DUMMY_SP,
|
|
||||||
}),
|
|
||||||
is_sugared_doc: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn expand_crate_str(crate_str: String) -> ast::Crate {
|
fn expand_crate_str(crate_str: String) -> ast::Crate {
|
||||||
let ps = parse::new_parse_sess();
|
let ps = parse::new_parse_sess();
|
||||||
let crate_ast = string_to_parser(&ps, crate_str).parse_crate_mod();
|
let crate_ast = string_to_parser(&ps, crate_str).parse_crate_mod();
|
||||||
|
@ -1655,7 +1639,7 @@ mod test {
|
||||||
let varref_idents : Vec<ast::Ident>
|
let varref_idents : Vec<ast::Ident>
|
||||||
= varref.segments.iter().map(|s| s.identifier)
|
= varref.segments.iter().map(|s| s.identifier)
|
||||||
.collect();
|
.collect();
|
||||||
println!("varref #{}: {}, resolves to {}",idx, varref_idents, varref_name);
|
println!("varref #{}: {:?}, resolves to {}",idx, varref_idents, varref_name);
|
||||||
let string = token::get_ident(final_varref_ident);
|
let string = token::get_ident(final_varref_ident);
|
||||||
println!("varref's first segment's string: \"{}\"", string.get());
|
println!("varref's first segment's string: \"{}\"", string.get());
|
||||||
println!("binding #{}: {}, resolves to {}",
|
println!("binding #{}: {}, resolves to {}",
|
||||||
|
|
|
@ -107,19 +107,6 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
|
||||||
// `#![no_implicit_prelude]` at the crate level.
|
// `#![no_implicit_prelude]` at the crate level.
|
||||||
// fold_mod() will insert glob path.
|
// fold_mod() will insert glob path.
|
||||||
if !no_prelude(&krate.attrs[]) {
|
if !no_prelude(&krate.attrs[]) {
|
||||||
// only add `use std::prelude::*;` if there wasn't a
|
|
||||||
// `#![no_implicit_prelude]` at the crate level.
|
|
||||||
// fold_mod() will insert glob path.
|
|
||||||
let globs_attr = attr::mk_attr_inner(attr::mk_attr_id(),
|
|
||||||
attr::mk_list_item(
|
|
||||||
InternedString::new("feature"),
|
|
||||||
vec!(
|
|
||||||
attr::mk_word_item(InternedString::new("globs")),
|
|
||||||
)));
|
|
||||||
// std_inject runs after feature checking so manually mark this attr
|
|
||||||
attr::mark_used(&globs_attr);
|
|
||||||
krate.attrs.push(globs_attr);
|
|
||||||
|
|
||||||
krate.module = self.fold_mod(krate.module);
|
krate.module = self.fold_mod(krate.module);
|
||||||
}
|
}
|
||||||
krate
|
krate
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// force-host
|
// force-host
|
||||||
|
|
||||||
#![feature(plugin_registrar)]
|
#![feature(plugin_registrar)]
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// force-host
|
// force-host
|
||||||
|
|
||||||
#![feature(plugin_registrar)]
|
#![feature(plugin_registrar)]
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// force-host
|
// force-host
|
||||||
|
|
||||||
#![feature(plugin_registrar, quote)]
|
#![feature(plugin_registrar, quote)]
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// force-host
|
// force-host
|
||||||
|
|
||||||
#![feature(plugin_registrar)]
|
#![feature(plugin_registrar)]
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// force-host
|
// force-host
|
||||||
|
|
||||||
#![feature(plugin_registrar)]
|
#![feature(plugin_registrar)]
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,6 @@ fn main() {
|
||||||
args.into_iter().map(|x| x.to_string()).collect()
|
args.into_iter().map(|x| x.to_string()).collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{}", args);
|
println!("{:?}", args);
|
||||||
run(args.as_slice());
|
run(args.as_slice());
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,6 @@ fn main() {
|
||||||
args.clone().into_iter().map(|x| x.to_string()).collect()
|
args.clone().into_iter().map(|x| x.to_string()).collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{}", args);
|
println!("{:?}", args);
|
||||||
run(args.as_slice());
|
run(args.as_slice());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
// multi tasking k-nucleotide
|
// multi tasking k-nucleotide
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
use std::ascii::{AsciiExt, OwnedAsciiExt};
|
use std::ascii::{AsciiExt, OwnedAsciiExt};
|
||||||
use std::cmp::Ordering::{self, Less, Greater, Equal};
|
use std::cmp::Ordering::{self, Less, Greater, Equal};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -62,7 +64,7 @@ fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> String {
|
||||||
|
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
for &(ref k, v) in pairs_sorted.iter() {
|
for &(ref k, v) in pairs_sorted.iter() {
|
||||||
buffer.push_str(format!("{} {:0.3}\n",
|
buffer.push_str(format!("{:?} {:0.3}\n",
|
||||||
k.to_ascii_uppercase(),
|
k.to_ascii_uppercase(),
|
||||||
v).as_slice());
|
v).as_slice());
|
||||||
}
|
}
|
||||||
|
@ -191,8 +193,8 @@ fn main() {
|
||||||
// start processing if this is the one
|
// start processing if this is the one
|
||||||
('>', false) => {
|
('>', false) => {
|
||||||
match line.as_slice().slice_from(1).find_str("THREE") {
|
match line.as_slice().slice_from(1).find_str("THREE") {
|
||||||
option::Option::Some(_) => { proc_mode = true; }
|
Some(_) => { proc_mode = true; }
|
||||||
option::Option::None => { }
|
None => { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +223,6 @@ fn main() {
|
||||||
|
|
||||||
// now fetch and print result messages
|
// now fetch and print result messages
|
||||||
for (ii, _sz) in sizes.iter().enumerate() {
|
for (ii, _sz) in sizes.iter().enumerate() {
|
||||||
println!("{}", from_child[ii].recv().unwrap());
|
println!("{:?}", from_child[ii].recv().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
|
|
||||||
// ignore-android see #10393 #13206
|
// ignore-android see #10393 #13206
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
use std::ascii::OwnedAsciiExt;
|
use std::ascii::OwnedAsciiExt;
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
// ignore-stage1
|
// ignore-stage1
|
||||||
// ignore-cross-compile #12102
|
// ignore-cross-compile #12102
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
// ignore-pretty very bad with line comments
|
// ignore-pretty very bad with line comments
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use std::io::BufferedReader;
|
use std::io::BufferedReader;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(unsafe_destructor)]
|
#![feature(unsafe_destructor, box_syntax)]
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::thread::Thread;
|
use std::thread::Thread;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// Test that we detect nested calls that could free pointers evaluated
|
// Test that we detect nested calls that could free pointers evaluated
|
||||||
// for earlier arguments.
|
// for earlier arguments.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn rewrite(v: &mut Box<uint>) -> uint {
|
fn rewrite(v: &mut Box<uint>) -> uint {
|
||||||
*v = box 22;
|
*v = box 22;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// Test that we detect nested calls that could free pointers evaluated
|
// Test that we detect nested calls that could free pointers evaluated
|
||||||
// for earlier arguments.
|
// for earlier arguments.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn rewrite(v: &mut Box<uint>) -> uint {
|
fn rewrite(v: &mut Box<uint>) -> uint {
|
||||||
*v = box 22;
|
*v = box 22;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct A;
|
struct A;
|
||||||
|
|
||||||
impl A {
|
impl A {
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
//buggy.rs
|
//buggy.rs
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
extern crate collections;
|
extern crate collections;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct A {
|
struct A {
|
||||||
x: Box<int>,
|
x: Box<int>,
|
||||||
y: int,
|
y: int,
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// Ensure that invoking a closure counts as a unique immutable borrow
|
// Ensure that invoking a closure counts as a unique immutable borrow
|
||||||
|
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
type Fn<'a> = Box<FnMut() + 'a>;
|
type Fn<'a> = Box<FnMut() + 'a>;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// Tests that two closures cannot simultaneously have mutable
|
// Tests that two closures cannot simultaneously have mutable
|
||||||
// and immutable access to the variable. Issue #6801.
|
// and immutable access to the variable. Issue #6801.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn get(x: &int) -> int {
|
fn get(x: &int) -> int {
|
||||||
*x
|
*x
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
// access to the variable, whether that mutable access be used
|
// access to the variable, whether that mutable access be used
|
||||||
// for direct assignment or for taking mutable ref. Issue #6801.
|
// for direct assignment or for taking mutable ref. Issue #6801.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn a() {
|
fn a() {
|
||||||
let mut x = 3i;
|
let mut x = 3i;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
// cannot also be supplied a borrowed version of that
|
// cannot also be supplied a borrowed version of that
|
||||||
// variable's contents. Issue #11192.
|
// variable's contents. Issue #11192.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
x: int
|
x: int
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct A { a: int, b: Box<int> }
|
struct A { a: int, b: Box<int> }
|
||||||
|
|
||||||
fn deref_after_move() {
|
fn deref_after_move() {
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
// Issue #16205.
|
// Issue #16205.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
a: [Box<int>; 3],
|
a: [Box<int>; 3],
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
// This tests that we can't modify Box<&mut T> contents while they
|
// This tests that we can't modify Box<&mut T> contents while they
|
||||||
// are borrowed.
|
// are borrowed.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct A { a: int }
|
struct A { a: int }
|
||||||
struct B<'a> { a: Box<&'a mut int> }
|
struct B<'a> { a: Box<&'a mut int> }
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = Some(box 1i);
|
let x = Some(box 1i);
|
||||||
match x {
|
match x {
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = Some(box 1i);
|
let x = Some(box 1i);
|
||||||
match x {
|
match x {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
// either genuine or would require more advanced changes. The latter
|
// either genuine or would require more advanced changes. The latter
|
||||||
// cases are noted.
|
// cases are noted.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn borrow(_v: &int) {}
|
fn borrow(_v: &int) {}
|
||||||
fn borrow_mut(_v: &mut int) {}
|
fn borrow_mut(_v: &mut int) {}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
// either genuine or would require more advanced changes. The latter
|
// either genuine or would require more advanced changes. The latter
|
||||||
// cases are noted.
|
// cases are noted.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn borrow(_v: &int) {}
|
fn borrow(_v: &int) {}
|
||||||
fn borrow_mut(_v: &mut int) {}
|
fn borrow_mut(_v: &mut int) {}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
// either genuine or would require more advanced changes. The latter
|
// either genuine or would require more advanced changes. The latter
|
||||||
// cases are noted.
|
// cases are noted.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn borrow(_v: &int) {}
|
fn borrow(_v: &int) {}
|
||||||
fn borrow_mut(_v: &mut int) {}
|
fn borrow_mut(_v: &mut int) {}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
use std::thread::Thread;
|
use std::thread::Thread;
|
||||||
|
|
||||||
fn borrow<F>(v: &int, f: F) where F: FnOnce(&int) {
|
fn borrow<F>(v: &int, f: F) where F: FnOnce(&int) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn take(_v: Box<int>) {
|
fn take(_v: Box<int>) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn borrow<F>(v: &int, f: F) where F: FnOnce(&int) {
|
fn borrow<F>(v: &int, f: F) where F: FnOnce(&int) {
|
||||||
f(v);
|
f(v);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let bar = box 3;
|
let bar = box 3;
|
||||||
let _g = |&mut:| {
|
let _g = |&mut:| {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
enum Foo {
|
enum Foo {
|
||||||
Foo1(Box<u32>, Box<u32>),
|
Foo1(Box<u32>, Box<u32>),
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
// verify that an error is raised when trying to move out of a
|
// verify that an error is raised when trying to move out of a
|
||||||
// borrowed path.
|
// borrowed path.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = box box 2i;
|
let a = box box 2i;
|
||||||
let b = &a;
|
let b = &a;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn call_f<F:FnOnce() -> int>(f: F) -> int {
|
fn call_f<F:FnOnce() -> int>(f: F) -> int {
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// Tests that the borrow checker checks all components of a path when moving
|
// Tests that the borrow checker checks all components of a path when moving
|
||||||
// out.
|
// out.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct S {
|
struct S {
|
||||||
x : Box<int>
|
x : Box<int>
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
use std::thread::Thread;
|
use std::thread::Thread;
|
||||||
|
|
||||||
fn borrow<T>(_: &T) { }
|
fn borrow<T>(_: &T) { }
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct node_ {
|
struct node_ {
|
||||||
a: Box<cycle>
|
a: Box<cycle>
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
|
|
||||||
struct MyVec<T> {
|
struct MyVec<T> {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn borrow(_v: &int) {}
|
fn borrow(_v: &int) {}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct A { a: int, b: int }
|
struct A { a: int, b: int }
|
||||||
|
|
||||||
impl Copy for A {}
|
impl Copy for A {}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
// Verifies all possible restrictions for statics values.
|
// Verifies all possible restrictions for statics values.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
use std::marker;
|
use std::marker;
|
||||||
|
|
||||||
struct WithDtor;
|
struct WithDtor;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
trait noisy {
|
trait noisy {
|
||||||
fn speak(&self);
|
fn speak(&self);
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
|
// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
|
||||||
// forbidden when `T` is a trait.
|
// forbidden when `T` is a trait.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct Foo;
|
struct Foo;
|
||||||
trait Trait {}
|
trait Trait {}
|
||||||
impl Trait for Foo {}
|
impl Trait for Foo {}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
// Forbid assignment into a dynamically sized type.
|
// Forbid assignment into a dynamically sized type.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct Fat<T: ?Sized> {
|
struct Fat<T: ?Sized> {
|
||||||
f1: int,
|
f1: int,
|
||||||
f2: &'static str,
|
f2: &'static str,
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
// Forbid assignment into a dynamically sized type.
|
// Forbid assignment into a dynamically sized type.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct Fat<T: ?Sized> {
|
struct Fat<T: ?Sized> {
|
||||||
f1: int,
|
f1: int,
|
||||||
f2: &'static str,
|
f2: &'static str,
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
// Check that dynamically sized rvalues are forbidden
|
// Check that dynamically sized rvalues are forbidden
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let _x: Box<str> = box *"hello world";
|
let _x: Box<str> = box *"hello world";
|
||||||
//~^ ERROR E0161
|
//~^ ERROR E0161
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn needs_fn<F>(x: F) where F: Fn(isize) -> isize {}
|
fn needs_fn<F>(x: F) where F: Fn(isize) -> isize {}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
// error-pattern: reached the recursion limit while auto-dereferencing
|
// error-pattern: reached the recursion limit while auto-dereferencing
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn test<'x>(x: &'x int) {
|
fn test<'x>(x: &'x int) {
|
||||||
drop::<Box<for<'z> FnMut(&'z int) -> &'z int>>(box |z| {
|
drop::<Box<for<'z> FnMut(&'z int) -> &'z int>>(box |z| {
|
||||||
x
|
x
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 1i;
|
let x = box 1i;
|
||||||
let f = move|:| {
|
let f = move|:| {
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
x: int
|
x: int
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct Test<'s> {
|
struct Test<'s> {
|
||||||
func: Box<FnMut()+'static>
|
func: Box<FnMut()+'static>
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = Some(box 1);
|
let a = Some(box 1);
|
||||||
match a {
|
match a {
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let r = {
|
let r = {
|
||||||
let x = box 42i;
|
let x = box 42i;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn do_it(x: &int) { }
|
fn do_it(x: &int) { }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
trait X {
|
trait X {
|
||||||
fn get_i(&self) -> int;
|
fn get_i(&self) -> int;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: Box<isize> = box 0;
|
let x: Box<isize> = box 0;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
struct Foo { a: int, b: int }
|
struct Foo { a: int, b: int }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _foo = &[1u, 2] as [usize];
|
let _foo = &[1u, 2] as [usize];
|
||||||
//~^ ERROR cast to unsized type: `&[usize; 2]` as `[usize]`
|
//~^ ERROR cast to unsized type: `&[usize; 2]` as `[usize]`
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue