test: Fix tests.
This commit is contained in:
172
doc/rust.md
172
doc/rust.md
@@ -206,7 +206,6 @@ The keywords are the following strings:
|
|||||||
~~~~~~~~ {.keyword}
|
~~~~~~~~ {.keyword}
|
||||||
as
|
as
|
||||||
break
|
break
|
||||||
copy
|
|
||||||
do
|
do
|
||||||
else enum extern
|
else enum extern
|
||||||
false fn for
|
false fn for
|
||||||
@@ -443,7 +442,7 @@ Two examples of paths with type arguments:
|
|||||||
~~~~
|
~~~~
|
||||||
# use std::hashmap::HashMap;
|
# use std::hashmap::HashMap;
|
||||||
# fn f() {
|
# fn f() {
|
||||||
# fn id<T:Copy>(t: T) -> T { t }
|
# fn id<T>(t: T) -> T { t }
|
||||||
type t = HashMap<int,~str>; // Type arguments used in a type expression
|
type t = HashMap<int,~str>; // Type arguments used in a type expression
|
||||||
let x = id::<int>(10); // Type arguments used in a call expression
|
let x = id::<int>(10); // Type arguments used in a call expression
|
||||||
# }
|
# }
|
||||||
@@ -907,11 +906,10 @@ example, `sys::size_of::<u32>() == 4`.
|
|||||||
|
|
||||||
Since a parameter type is opaque to the generic function, the set of
|
Since a parameter type is opaque to the generic function, the set of
|
||||||
operations that can be performed on it is limited. Values of parameter
|
operations that can be performed on it is limited. Values of parameter
|
||||||
type can always be moved, but they can only be copied when the
|
type can only be moved, not copied.
|
||||||
parameter is given a [`Copy` bound](#type-kinds).
|
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
fn id<T: Copy>(x: T) -> T { x }
|
fn id<T>(x: T) -> T { x }
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
Similarly, [trait](#traits) bounds can be specified for type
|
Similarly, [trait](#traits) bounds can be specified for type
|
||||||
@@ -1519,8 +1517,6 @@ A complete list of the built-in language items follows:
|
|||||||
|
|
||||||
`const`
|
`const`
|
||||||
: Cannot be mutated.
|
: Cannot be mutated.
|
||||||
`copy`
|
|
||||||
: Can be implicitly copied.
|
|
||||||
`owned`
|
`owned`
|
||||||
: Are uniquely owned.
|
: Are uniquely owned.
|
||||||
`durable`
|
`durable`
|
||||||
@@ -1587,7 +1583,8 @@ A complete list of the built-in language items follows:
|
|||||||
`check_not_borrowed`
|
`check_not_borrowed`
|
||||||
: Fail if a value has existing borrowed pointers to it.
|
: Fail if a value has existing borrowed pointers to it.
|
||||||
`strdup_uniq`
|
`strdup_uniq`
|
||||||
: Return a new unique string containing a copy of the contents of a unique string.
|
: Return a new unique string
|
||||||
|
containing a copy of the contents of a unique string.
|
||||||
|
|
||||||
> **Note:** This list is likely to become out of date. We should auto-generate it
|
> **Note:** This list is likely to become out of date. We should auto-generate it
|
||||||
> from `librustc/middle/lang_items.rs`.
|
> from `librustc/middle/lang_items.rs`.
|
||||||
@@ -1736,10 +1733,13 @@ A temporary's lifetime equals the largest lifetime of any borrowed pointer that
|
|||||||
|
|
||||||
#### Moved and copied types
|
#### Moved and copied types
|
||||||
|
|
||||||
When a [local variable](#memory-slots) is used as an [rvalue](#lvalues-rvalues-and-temporaries)
|
When a [local variable](#memory-slots) is used
|
||||||
the variable will either be [moved](#move-expressions) or [copied](#copy-expressions),
|
as an [rvalue](#lvalues-rvalues-and-temporaries)
|
||||||
|
the variable will either be [moved](#move-expressions) or copied,
|
||||||
depending on its type.
|
depending on its type.
|
||||||
For types that contain mutable fields or [owning pointers](#owning-pointers), the variable is moved.
|
For types that contain [owning pointers](#owning-pointers)
|
||||||
|
or values that implement the special trait `Drop`,
|
||||||
|
the variable is moved.
|
||||||
All other types are copied.
|
All other types are copied.
|
||||||
|
|
||||||
|
|
||||||
@@ -1918,9 +1918,9 @@ task in a _failing state_.
|
|||||||
|
|
||||||
### Unary operator expressions
|
### Unary operator expressions
|
||||||
|
|
||||||
Rust defines six symbolic unary operators,
|
Rust defines six symbolic unary operators.
|
||||||
in addition to the unary [copy](#unary-copy-expressions) and [move](#unary-move-expressions) operators.
|
They are all written as prefix operators,
|
||||||
They are all written as prefix operators, before the expression they apply to.
|
before the expression they apply to.
|
||||||
|
|
||||||
`-`
|
`-`
|
||||||
: Negation. May only be applied to numeric types.
|
: Negation. May only be applied to numeric types.
|
||||||
@@ -2119,60 +2119,6 @@ An example of a parenthesized expression:
|
|||||||
let x = (2 + 3) * 4;
|
let x = (2 + 3) * 4;
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
### Unary copy expressions
|
|
||||||
|
|
||||||
~~~~~~~~{.ebnf .gram}
|
|
||||||
copy_expr : "copy" expr ;
|
|
||||||
~~~~~~~~
|
|
||||||
|
|
||||||
> **Note:** `copy` expressions are deprecated. It's preferable to use
|
|
||||||
> the `Clone` trait and `clone()` method.
|
|
||||||
|
|
||||||
A _unary copy expression_ consists of the unary `copy` operator applied to
|
|
||||||
some argument expression.
|
|
||||||
|
|
||||||
Evaluating a copy expression first evaluates the argument expression, then
|
|
||||||
copies the resulting value, allocating any memory necessary to hold the new
|
|
||||||
copy.
|
|
||||||
|
|
||||||
[Managed boxes](#pointer-types) (type `@`) are, as usual, shallow-copied,
|
|
||||||
as are raw and borrowed pointers.
|
|
||||||
[Owned boxes](#pointer-types), [owned vectors](#vector-types) and similar owned types are deep-copied.
|
|
||||||
|
|
||||||
Since the binary [assignment operator](#assignment-expressions) `=` performs a copy or move implicitly,
|
|
||||||
the unary copy operator is typically only used to cause an argument to a function to be copied and passed by value.
|
|
||||||
|
|
||||||
An example of a copy expression:
|
|
||||||
|
|
||||||
~~~~
|
|
||||||
fn mutate(mut vec: ~[int]) {
|
|
||||||
vec[0] = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
let v = ~[1,2,3];
|
|
||||||
|
|
||||||
mutate(copy v); // Pass a copy
|
|
||||||
|
|
||||||
assert!(v[0] == 1); // Original was not modified
|
|
||||||
~~~~
|
|
||||||
|
|
||||||
### Unary move expressions
|
|
||||||
|
|
||||||
~~~~~~~~{.ebnf .gram}
|
|
||||||
move_expr : "move" expr ;
|
|
||||||
~~~~~~~~
|
|
||||||
|
|
||||||
A _unary move expression_ is similar to a [unary copy](#unary-copy-expressions) expression,
|
|
||||||
except that it can only be applied to a [local variable](#memory-slots),
|
|
||||||
and it performs a _move_ on its operand, rather than a copy.
|
|
||||||
That is, the memory location denoted by its operand is de-initialized after evaluation,
|
|
||||||
and the resulting value is a shallow copy of the operand,
|
|
||||||
even if the operand is an [owning type](#type-kinds).
|
|
||||||
|
|
||||||
|
|
||||||
> **Note:** In future versions of Rust, `move` may be removed as a separate operator;
|
|
||||||
> moves are now [automatically performed](#moved-and-copied-types) for most cases `move` would be appropriate.
|
|
||||||
|
|
||||||
|
|
||||||
### Call expressions
|
### Call expressions
|
||||||
|
|
||||||
@@ -2507,10 +2453,11 @@ match x {
|
|||||||
}
|
}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
Patterns that bind variables default to binding to a copy or move of the matched value
|
Patterns that bind variables
|
||||||
|
default to binding to a copy or move of the matched value
|
||||||
(depending on the matched value's type).
|
(depending on the matched value's type).
|
||||||
This can be made explicit using the ```copy``` keyword,
|
This can be changed to bind to a borrowed pointer by
|
||||||
changed to bind to a borrowed pointer by using the ```ref``` keyword,
|
using the ```ref``` keyword,
|
||||||
or to a mutable borrowed pointer using ```ref mut```.
|
or to a mutable borrowed pointer using ```ref mut```.
|
||||||
|
|
||||||
A pattern that's just an identifier,
|
A pattern that's just an identifier,
|
||||||
@@ -2896,16 +2843,18 @@ and the cast expression in `main`.
|
|||||||
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
|
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
|
||||||
|
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
fn map<A: Copy, B: Copy>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
|
fn map<A: Clone, B: Clone>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
|
||||||
if xs.len() == 0 { return ~[]; }
|
if xs.len() == 0 {
|
||||||
let first: B = f(copy xs[0]);
|
return ~[];
|
||||||
|
}
|
||||||
|
let first: B = f(xs[0].clone());
|
||||||
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
|
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
|
||||||
return ~[first] + rest;
|
return ~[first] + rest;
|
||||||
}
|
}
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
|
||||||
Here, `first` has type `B`, referring to `map`'s `B` type parameter; and `rest` has
|
Here, `first` has type `B`, referring to `map`'s `B` type parameter;
|
||||||
type `~[B]`, a vector type with element type `B`.
|
and `rest` has type `~[B]`, a vector type with element type `B`.
|
||||||
|
|
||||||
### Self types
|
### Self types
|
||||||
|
|
||||||
@@ -2919,7 +2868,9 @@ trait Printable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Printable for ~str {
|
impl Printable for ~str {
|
||||||
fn make_string(&self) -> ~str { copy *self }
|
fn make_string(&self) -> ~str {
|
||||||
|
(*self).clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
@@ -2933,23 +2884,29 @@ The kinds are:
|
|||||||
|
|
||||||
`Freeze`
|
`Freeze`
|
||||||
: Types of this kind are deeply immutable;
|
: Types of this kind are deeply immutable;
|
||||||
they contain no mutable memory locations directly or indirectly via pointers.
|
they contain no mutable memory locations
|
||||||
|
directly or indirectly via pointers.
|
||||||
`Send`
|
`Send`
|
||||||
: Types of this kind can be safely sent between tasks.
|
: Types of this kind can be safely sent between tasks.
|
||||||
This kind includes scalars, owning pointers, owned closures, and
|
This kind includes scalars, owning pointers, owned closures, and
|
||||||
structural types containing only other owned types. All `Send` types are `Static`.
|
structural types containing only other owned types.
|
||||||
`Copy`
|
All `Send` types are `'static`.
|
||||||
: This kind includes all types that can be copied. All types with
|
`'static`
|
||||||
sendable kind are copyable, as are managed boxes, managed closures,
|
: Types of this kind do not contain any borrowed pointers;
|
||||||
trait types, and structural types built out of these.
|
this can be a useful guarantee for code
|
||||||
Types with destructors (types that implement `Drop`) can not implement `Copy`.
|
that breaks borrowing assumptions
|
||||||
|
using [`unsafe` operations](#unsafe-functions).
|
||||||
`Drop`
|
`Drop`
|
||||||
: This is not strictly a kind, but its presence interacts with kinds: the `Drop`
|
: This is not strictly a kind,
|
||||||
trait provides a single method `drop` that takes no parameters, and is run
|
but its presence interacts with kinds:
|
||||||
when values of the type are dropped. Such a method is called a "destructor",
|
the `Drop` trait provides a single method `drop`
|
||||||
and are always executed in "top-down" order: a value is completely destroyed
|
that takes no parameters,
|
||||||
before any of the values it owns run their destructors. Only `Send` types
|
and is run when values of the type are dropped.
|
||||||
that do not implement `Copy` can implement `Drop`.
|
Such a method is called a "destructor",
|
||||||
|
and are always executed in "top-down" order:
|
||||||
|
a value is completely destroyed
|
||||||
|
before any of the values it owns run their destructors.
|
||||||
|
Only `Send` types can implement `Drop`.
|
||||||
|
|
||||||
_Default_
|
_Default_
|
||||||
: Types with destructors, closure environments,
|
: Types with destructors, closure environments,
|
||||||
@@ -2962,30 +2919,15 @@ Kinds can be supplied as _bounds_ on type parameters, like traits,
|
|||||||
in which case the parameter is constrained to types satisfying that kind.
|
in which case the parameter is constrained to types satisfying that kind.
|
||||||
|
|
||||||
By default, type parameters do not carry any assumed kind-bounds at all.
|
By default, type parameters do not carry any assumed kind-bounds at all.
|
||||||
|
When instantiating a type parameter,
|
||||||
|
the kind bounds on the parameter are checked
|
||||||
|
to be the same or narrower than the kind
|
||||||
|
of the type that it is instantiated with.
|
||||||
|
|
||||||
Any operation that causes a value to be copied requires the type of that value to be of copyable kind,
|
Sending operations are not part of the Rust language,
|
||||||
so the `Copy` bound is frequently required on function type parameters.
|
but are implemented in the library.
|
||||||
For example, this is not a valid program:
|
Generic functions that send values
|
||||||
|
bound the kind of these values to sendable.
|
||||||
~~~~{.xfail-test}
|
|
||||||
fn box<T>(x: T) -> @T { @x }
|
|
||||||
~~~~
|
|
||||||
|
|
||||||
Putting `x` into a managed box involves copying, and the `T` parameter has the default (non-copyable) kind.
|
|
||||||
To change that, a bound is declared:
|
|
||||||
|
|
||||||
~~~~
|
|
||||||
fn box<T: Copy>(x: T) -> @T { @x }
|
|
||||||
~~~~
|
|
||||||
|
|
||||||
Calling this second version of `box` on a noncopyable type is not
|
|
||||||
allowed. When instantiating a type parameter, the kind bounds on the
|
|
||||||
parameter are checked to be the same or narrower than the kind of the
|
|
||||||
type that it is instantiated with.
|
|
||||||
|
|
||||||
Sending operations are not part of the Rust language, but are
|
|
||||||
implemented in the library. Generic functions that send values bound
|
|
||||||
the kind of these values to sendable.
|
|
||||||
|
|
||||||
# Memory and concurrency models
|
# Memory and concurrency models
|
||||||
|
|
||||||
@@ -3093,9 +3035,7 @@ managed box value makes a shallow copy of the pointer (optionally incrementing
|
|||||||
a reference count, if the managed box is implemented through
|
a reference count, if the managed box is implemented through
|
||||||
reference-counting).
|
reference-counting).
|
||||||
|
|
||||||
Owned box values exist in 1:1 correspondence with their heap allocation;
|
Owned box values exist in 1:1 correspondence with their heap allocation.
|
||||||
copying an owned box value makes a deep copy of the heap allocation and
|
|
||||||
produces a pointer to the new allocation.
|
|
||||||
|
|
||||||
An example of constructing one managed box type and value, and one owned box
|
An example of constructing one managed box type and value, and one owned box
|
||||||
type and value:
|
type and value:
|
||||||
|
|||||||
@@ -1275,6 +1275,11 @@ The `+` operator means concatenation when applied to vector types.
|
|||||||
# enum Crayon { Almond, AntiqueBrass, Apricot,
|
# enum Crayon { Almond, AntiqueBrass, Apricot,
|
||||||
# Aquamarine, Asparagus, AtomicTangerine,
|
# Aquamarine, Asparagus, AtomicTangerine,
|
||||||
# BananaMania, Beaver, Bittersweet };
|
# BananaMania, Beaver, Bittersweet };
|
||||||
|
# impl Clone for Crayon {
|
||||||
|
# fn clone(&self) -> Crayon {
|
||||||
|
# *self
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
let my_crayons = ~[Almond, AntiqueBrass, Apricot];
|
let my_crayons = ~[Almond, AntiqueBrass, Apricot];
|
||||||
let your_crayons = ~[BananaMania, Beaver, Bittersweet];
|
let your_crayons = ~[BananaMania, Beaver, Bittersweet];
|
||||||
@@ -1827,15 +1832,17 @@ similarities to type classes. Rust's traits are a form of *bounded
|
|||||||
polymorphism*: a trait is a way of limiting the set of possible types
|
polymorphism*: a trait is a way of limiting the set of possible types
|
||||||
that a type parameter could refer to.
|
that a type parameter could refer to.
|
||||||
|
|
||||||
As motivation, let us consider copying in Rust. The `copy` operation
|
As motivation, let us consider copying in Rust.
|
||||||
is not defined for all Rust types. One reason is user-defined
|
The `clone` method is not defined for all Rust types.
|
||||||
destructors: copying a type that has a destructor could result in the
|
One reason is user-defined destructors:
|
||||||
destructor running multiple times. Therefore, types with user-defined
|
copying a type that has a destructor
|
||||||
destructors cannot be copied, either implicitly or explicitly, and
|
could result in the destructor running multiple times.
|
||||||
neither can types that own other types containing destructors.
|
Therefore, types with destructors cannot be copied
|
||||||
|
unless you explicitly implement `Clone` for them.
|
||||||
|
|
||||||
This complicates handling of generic functions. If you have a type
|
This complicates handling of generic functions.
|
||||||
parameter `T`, can you copy values of that type? In Rust, you can't,
|
If you have a type parameter `T`, can you copy values of that type?
|
||||||
|
In Rust, you can't,
|
||||||
and if you try to run the following code the compiler will complain.
|
and if you try to run the following code the compiler will complain.
|
||||||
|
|
||||||
~~~~ {.xfail-test}
|
~~~~ {.xfail-test}
|
||||||
@@ -1845,42 +1852,43 @@ fn head_bad<T>(v: &[T]) -> T {
|
|||||||
}
|
}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
However, we can tell the compiler that the `head` function is only for
|
However, we can tell the compiler
|
||||||
copyable types: that is, those that have the `Copy` trait. In that
|
that the `head` function is only for copyable types:
|
||||||
case, we can explicitly create a second copy of the value we are
|
that is, those that implement the `Clone` trait.
|
||||||
returning using the `copy` keyword:
|
In that case,
|
||||||
|
we can explicitly create a second copy of the value we are returning
|
||||||
|
using the `clone` keyword:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
// This does
|
// This does
|
||||||
fn head<T: Copy>(v: &[T]) -> T {
|
fn head<T: Clone>(v: &[T]) -> T {
|
||||||
copy v[0]
|
v[0].clone()
|
||||||
}
|
}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
This says that we can call `head` on any type `T` as long as that type
|
This says that we can call `head` on any type `T`
|
||||||
implements the `Copy` trait. When instantiating a generic function,
|
as long as that type implements the `Clone` trait.
|
||||||
you can only instantiate it with types that implement the correct
|
When instantiating a generic function,
|
||||||
trait, so you could not apply `head` to a type with a
|
you can only instantiate it with types
|
||||||
destructor. (`Copy` is a special trait that is built in to the
|
that implement the correct trait,
|
||||||
compiler, making it possible for the compiler to enforce this
|
so you could not apply `head` to a type
|
||||||
restriction.)
|
that does not implement `Clone`.
|
||||||
|
|
||||||
While most traits can be defined and implemented by user code, three
|
While most traits can be defined and implemented by user code,
|
||||||
traits are automatically derived and implemented for all applicable
|
two traits are automatically derived and implemented
|
||||||
types by the compiler, and may not be overridden:
|
for all applicable types by the compiler,
|
||||||
|
and may not be overridden:
|
||||||
|
|
||||||
* `Copy` - Types that can be copied, either implicitly, or explicitly with the
|
* `Send` - Sendable types.
|
||||||
`copy` operator. All types are copyable unless they have destructors or
|
Types are sendable
|
||||||
contain types with destructors.
|
unless they contain managed boxes, managed closures, or borrowed pointers.
|
||||||
|
|
||||||
* `Owned` - Owned types. Types are owned unless they contain managed
|
* `Freeze` - Constant (immutable) types.
|
||||||
boxes, managed closures, or borrowed pointers. Owned types may or
|
These are types that do not contain anything intrinsically mutable.
|
||||||
may not be copyable.
|
Intrinsically mutable values include `@mut`
|
||||||
|
and `Cell` in the standard library.
|
||||||
|
|
||||||
* `Const` - Constant (immutable) types. These are types that do not contain
|
> ***Note:*** These two traits were referred to as 'kinds' in earlier
|
||||||
mutable fields.
|
|
||||||
|
|
||||||
> ***Note:*** These three traits were referred to as 'kinds' in earlier
|
|
||||||
> iterations of the language, and often still are.
|
> iterations of the language, and often still are.
|
||||||
|
|
||||||
Additionally, the `Drop` trait is used to define destructors. This
|
Additionally, the `Drop` trait is used to define destructors. This
|
||||||
@@ -1908,10 +1916,11 @@ may call it.
|
|||||||
|
|
||||||
## Declaring and implementing traits
|
## Declaring and implementing traits
|
||||||
|
|
||||||
A trait consists of a set of methods, without bodies, or may be empty,
|
A trait consists of a set of methods without bodies,
|
||||||
as is the case with `Copy`, `Owned`, and `Const`. For example, we could
|
or may be empty, as is the case with `Send` and `Freeze`.
|
||||||
declare the trait `Printable` for things that can be printed to the
|
For example, we could declare the trait
|
||||||
console, with a single method:
|
`Printable` for things that can be printed to the console,
|
||||||
|
with a single method:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
trait Printable {
|
trait Printable {
|
||||||
@@ -2030,7 +2039,7 @@ fn print_all<T: Printable>(printable_things: ~[T]) {
|
|||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
Declaring `T` as conforming to the `Printable` trait (as we earlier
|
Declaring `T` as conforming to the `Printable` trait (as we earlier
|
||||||
did with `Copy`) makes it possible to call methods from that trait
|
did with `Clone`) makes it possible to call methods from that trait
|
||||||
on values of type `T` inside the function. It will also cause a
|
on values of type `T` inside the function. It will also cause a
|
||||||
compile-time error when anyone tries to call `print_all` on an array
|
compile-time error when anyone tries to call `print_all` on an array
|
||||||
whose element type does not have a `Printable` implementation.
|
whose element type does not have a `Printable` implementation.
|
||||||
@@ -2040,10 +2049,10 @@ as in this version of `print_all` that copies elements.
|
|||||||
|
|
||||||
~~~
|
~~~
|
||||||
# trait Printable { fn print(&self); }
|
# trait Printable { fn print(&self); }
|
||||||
fn print_all<T: Printable + Copy>(printable_things: ~[T]) {
|
fn print_all<T: Printable + Clone>(printable_things: ~[T]) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < printable_things.len() {
|
while i < printable_things.len() {
|
||||||
let copy_of_thing = copy printable_things[i];
|
let copy_of_thing = printable_things[i].clone();
|
||||||
copy_of_thing.print();
|
copy_of_thing.print();
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Clone, Eq)]
|
||||||
pub enum mode {
|
pub enum mode {
|
||||||
mode_compile_fail,
|
mode_compile_fail,
|
||||||
mode_run_fail,
|
mode_run_fail,
|
||||||
@@ -18,6 +18,7 @@ pub enum mode {
|
|||||||
mode_codegen
|
mode_codegen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Clone)]
|
||||||
pub struct config {
|
pub struct config {
|
||||||
// The library paths required for running the compiler
|
// The library paths required for running the compiler
|
||||||
compile_lib_path: ~str,
|
compile_lib_path: ~str,
|
||||||
|
|||||||
@@ -40,6 +40,17 @@ pub mod runtest;
|
|||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
mod std {
|
||||||
|
pub use core::clone;
|
||||||
|
pub use core::cmp;
|
||||||
|
pub use core::str;
|
||||||
|
pub use core::sys;
|
||||||
|
pub use core::unstable;
|
||||||
|
}
|
||||||
|
|
||||||
|
>>>>>>> test: Fix tests.
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
let config = parse_config(args);
|
let config = parse_config(args);
|
||||||
@@ -117,10 +128,17 @@ pub fn parse_config(args: ~[~str]) -> config {
|
|||||||
mode: str_mode(getopts::opt_str(matches, "mode")),
|
mode: str_mode(getopts::opt_str(matches, "mode")),
|
||||||
run_ignored: getopts::opt_present(matches, "ignored"),
|
run_ignored: getopts::opt_present(matches, "ignored"),
|
||||||
filter:
|
filter:
|
||||||
|
<<<<<<< HEAD
|
||||||
if !matches.free.is_empty() {
|
if !matches.free.is_empty() {
|
||||||
Some(matches.free[0].clone())
|
Some(matches.free[0].clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
=======
|
||||||
|
if !matches.free.is_empty() {
|
||||||
|
option::Some(matches.free[0].clone())
|
||||||
|
} else {
|
||||||
|
option::None
|
||||||
|
>>>>>>> test: Fix tests.
|
||||||
},
|
},
|
||||||
logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)),
|
logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)),
|
||||||
save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map(|s| Path(*s)),
|
save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map(|s| Path(*s)),
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
|
|||||||
// Load any test directives embedded in the file
|
// Load any test directives embedded in the file
|
||||||
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
|
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
|
||||||
let mut error_patterns = ~[];
|
let mut error_patterns = ~[];
|
||||||
let rdr = io::file_reader(testfile).get();
|
let rdr = io::file_reader(testfile).unwrap();
|
||||||
let mut line_num = 1u;
|
let mut line_num = 1u;
|
||||||
while !rdr.eof() {
|
while !rdr.eof() {
|
||||||
let ln = rdr.read_line();
|
let ln = rdr.read_line();
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
|
fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
|
||||||
let rdr = io::file_reader(testfile).get();
|
let rdr = io::file_reader(testfile).unwrap();
|
||||||
while !rdr.eof() {
|
while !rdr.eof() {
|
||||||
let ln = rdr.read_line();
|
let ln = rdr.read_line();
|
||||||
|
|
||||||
|
|||||||
@@ -672,7 +672,7 @@ fn dump_output_file(config: &config, testfile: &Path,
|
|||||||
out: &str, extension: &str) {
|
out: &str, extension: &str) {
|
||||||
let outfile = make_out_name(config, testfile, extension);
|
let outfile = make_out_name(config, testfile, extension);
|
||||||
let writer =
|
let writer =
|
||||||
io::file_writer(&outfile, [io::Create, io::Truncate]).get();
|
io::file_writer(&outfile, [io::Create, io::Truncate]).unwrap();
|
||||||
writer.write_str(out);
|
writer.write_str(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1453,7 +1453,7 @@ mod tests {
|
|||||||
fn bench_big_bitv_big(b: &mut BenchHarness) {
|
fn bench_big_bitv_big(b: &mut BenchHarness) {
|
||||||
let mut r = rng();
|
let mut r = rng();
|
||||||
let mut storage = ~[];
|
let mut storage = ~[];
|
||||||
storage.grow(BENCH_BITS / uint::bits, &0);
|
storage.grow(BENCH_BITS / uint::bits, &0u);
|
||||||
let mut bitv = BigBitv::new(storage);
|
let mut bitv = BigBitv::new(storage);
|
||||||
do b.iter {
|
do b.iter {
|
||||||
bitv.set((r.next() as uint) % BENCH_BITS, true);
|
bitv.set((r.next() as uint) % BENCH_BITS, true);
|
||||||
|
|||||||
@@ -244,14 +244,15 @@ mod tests {
|
|||||||
use digest::{Digest, DigestUtil};
|
use digest::{Digest, DigestUtil};
|
||||||
use sha1::Sha1;
|
use sha1::Sha1;
|
||||||
|
|
||||||
#[test]
|
#[deriving(Clone)]
|
||||||
fn test() {
|
|
||||||
struct Test {
|
struct Test {
|
||||||
input: ~str,
|
input: ~str,
|
||||||
output: ~[u8],
|
output: ~[u8],
|
||||||
output_str: ~str,
|
output_str: ~str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test() {
|
||||||
fn a_million_letter_a() -> ~str {
|
fn a_million_letter_a() -> ~str {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut rs = ~"";
|
let mut rs = ~"";
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ mod test {
|
|||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
fn make_file(path : &Path, contents: &[~str]) {
|
fn make_file(path : &Path, contents: &[~str]) {
|
||||||
let file = io::file_writer(path, [io::Create, io::Truncate]).get();
|
let file = io::file_writer(path, [io::Create, io::Truncate]).unwrap();
|
||||||
|
|
||||||
for contents.iter().advance |str| {
|
for contents.iter().advance |str| {
|
||||||
file.write_str(*str);
|
file.write_str(*str);
|
||||||
@@ -562,9 +562,11 @@ mod test {
|
|||||||
let f2 =
|
let f2 =
|
||||||
Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
|
Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
|
||||||
|
|
||||||
let wr = io::file_writer(f1.get_ref(), [io::Create, io::Truncate]).get();
|
let wr = io::file_writer(f1.get_ref(),
|
||||||
|
[io::Create, io::Truncate]).unwrap();
|
||||||
wr.write_str("1\n2");
|
wr.write_str("1\n2");
|
||||||
let wr = io::file_writer(f2.get_ref(), [io::Create, io::Truncate]).get();
|
let wr = io::file_writer(f2.get_ref(),
|
||||||
|
[io::Create, io::Truncate]).unwrap();
|
||||||
wr.write_str("3\n4");
|
wr.write_str("3\n4");
|
||||||
|
|
||||||
let mut lines = ~[];
|
let mut lines = ~[];
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Clone, Eq)]
|
||||||
pub enum List<T> {
|
pub enum List<T> {
|
||||||
Cons(T, @List<T>),
|
Cons(T, @List<T>),
|
||||||
Nil,
|
Nil,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ use get_data_for_req = uv_ll::get_data_for_req;
|
|||||||
use ll = uv_ll;
|
use ll = uv_ll;
|
||||||
|
|
||||||
/// An IP address
|
/// An IP address
|
||||||
|
#[deriving(Clone)]
|
||||||
pub enum IpAddr {
|
pub enum IpAddr {
|
||||||
/// An IPv4 address
|
/// An IPv4 address
|
||||||
Ipv4(sockaddr_in),
|
Ipv4(sockaddr_in),
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ pub struct TcpErrData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Details returned as part of a `Result::Err` result from `tcp::listen`
|
/// Details returned as part of a `Result::Err` result from `tcp::listen`
|
||||||
|
#[deriving(Clone)]
|
||||||
pub enum TcpListenErrData {
|
pub enum TcpListenErrData {
|
||||||
/**
|
/**
|
||||||
* Some unplanned-for error. The first and second fields correspond
|
* Some unplanned-for error. The first and second fields correspond
|
||||||
@@ -120,6 +121,7 @@ pub enum TcpListenErrData {
|
|||||||
AccessDenied
|
AccessDenied
|
||||||
}
|
}
|
||||||
/// Details returned as part of a `Result::Err` result from `tcp::connect`
|
/// Details returned as part of a `Result::Err` result from `tcp::connect`
|
||||||
|
#[deriving(Clone)]
|
||||||
pub enum TcpConnectErrData {
|
pub enum TcpConnectErrData {
|
||||||
/**
|
/**
|
||||||
* Some unplanned-for error. The first and second fields correspond
|
* Some unplanned-for error. The first and second fields correspond
|
||||||
|
|||||||
@@ -12,13 +12,14 @@
|
|||||||
|
|
||||||
#[allow(missing_doc)];
|
#[allow(missing_doc)];
|
||||||
|
|
||||||
|
use std::clone::Clone;
|
||||||
use std::unstable::intrinsics::{move_val_init, init};
|
use std::unstable::intrinsics::{move_val_init, init};
|
||||||
use std::util::{replace, swap};
|
use std::util::{replace, swap};
|
||||||
use std::vec;
|
use std::vec;
|
||||||
use std::iterator::FromIterator;
|
use std::iterator::FromIterator;
|
||||||
|
|
||||||
/// A priority queue implemented with a binary heap
|
/// A priority queue implemented with a binary heap
|
||||||
|
#[deriving(Clone)]
|
||||||
pub struct PriorityQueue<T> {
|
pub struct PriorityQueue<T> {
|
||||||
priv data: ~[T],
|
priv data: ~[T],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -926,6 +926,7 @@ mod test_tim_sort {
|
|||||||
use std::rand;
|
use std::rand;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
|
#[deriving(Clone)]
|
||||||
struct CVal {
|
struct CVal {
|
||||||
val: float,
|
val: float,
|
||||||
}
|
}
|
||||||
@@ -992,7 +993,10 @@ mod test_tim_sort {
|
|||||||
fail!("Guarantee the fail");
|
fail!("Guarantee the fail");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DVal { val: uint }
|
#[deriving(Clone)]
|
||||||
|
struct DVal {
|
||||||
|
val: uint,
|
||||||
|
}
|
||||||
|
|
||||||
impl Ord for DVal {
|
impl Ord for DVal {
|
||||||
fn lt(&self, _x: &DVal) -> bool { true }
|
fn lt(&self, _x: &DVal) -> bool { true }
|
||||||
|
|||||||
@@ -1245,7 +1245,7 @@ mod tests {
|
|||||||
ignore: false,
|
ignore: false,
|
||||||
should_fail: false
|
should_fail: false
|
||||||
},
|
},
|
||||||
testfn: DynTestFn(testfn.clone()),
|
testfn: DynTestFn(testfn),
|
||||||
};
|
};
|
||||||
tests.push(test);
|
tests.push(test);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ pub struct uv_timer_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// unix size: 16
|
// unix size: 16
|
||||||
|
#[deriving(Clone)]
|
||||||
pub struct sockaddr_in {
|
pub struct sockaddr_in {
|
||||||
sin_family: u16,
|
sin_family: u16,
|
||||||
sin_port: u16,
|
sin_port: u16,
|
||||||
@@ -280,6 +281,7 @@ pub struct sockaddr_in6 {
|
|||||||
a0: *u8, a1: *u8,
|
a0: *u8, a1: *u8,
|
||||||
a2: *u8, a3: *u8,
|
a2: *u8, a3: *u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch="x86")]
|
#[cfg(target_arch="x86")]
|
||||||
#[cfg(target_arch="arm")]
|
#[cfg(target_arch="arm")]
|
||||||
#[cfg(target_arch="mips")]
|
#[cfg(target_arch="mips")]
|
||||||
@@ -290,6 +292,12 @@ pub struct sockaddr_in6 {
|
|||||||
a6: *u8, a7: *u8,
|
a6: *u8, a7: *u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Clone for sockaddr_in6 {
|
||||||
|
fn clone(&self) -> sockaddr_in6 {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// unix size: 28 .. FIXME #1645
|
// unix size: 28 .. FIXME #1645
|
||||||
// stuck with 32 because of rust padding structs?
|
// stuck with 32 because of rust padding structs?
|
||||||
pub type addr_in = addr_in_impl::addr_in;
|
pub type addr_in = addr_in_impl::addr_in;
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ fn git_repo_pkg() -> PkgId {
|
|||||||
|
|
||||||
fn writeFile(file_path: &Path, contents: &str) {
|
fn writeFile(file_path: &Path, contents: &str) {
|
||||||
let out: @io::Writer =
|
let out: @io::Writer =
|
||||||
result::get(&io::file_writer(file_path,
|
result::unwrap(io::file_writer(file_path,
|
||||||
[io::Create, io::Truncate]));
|
[io::Create, io::Truncate]));
|
||||||
out.write_line(contents);
|
out.write_line(contents);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let file = io::file_writer(&out_path.push("generated.rs"),
|
let file = io::file_writer(&out_path.push("generated.rs"),
|
||||||
[io::Create]).get();
|
[io::Create]).unwrap();
|
||||||
file.write_str("pub fn wheeeee() { for [1, 2, 3].each() |_| { assert!(true); } }");
|
file.write_str("pub fn wheeeee() { for [1, 2, 3].each() |_| { assert!(true); } }");
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1856,11 +1856,11 @@ mod tests {
|
|||||||
debug!(frood.clone());
|
debug!(frood.clone());
|
||||||
{
|
{
|
||||||
let out: @io::Writer =
|
let out: @io::Writer =
|
||||||
result::get(
|
result::unwrap(
|
||||||
&io::file_writer(tmpfile, [io::Create, io::Truncate]));
|
io::file_writer(tmpfile, [io::Create, io::Truncate]));
|
||||||
out.write_str(frood);
|
out.write_str(frood);
|
||||||
}
|
}
|
||||||
let inp: @io::Reader = result::get(&io::file_reader(tmpfile));
|
let inp: @io::Reader = result::unwrap(io::file_reader(tmpfile));
|
||||||
let frood2: ~str = inp.read_c_str();
|
let frood2: ~str = inp.read_c_str();
|
||||||
debug!(frood2.clone());
|
debug!(frood2.clone());
|
||||||
assert_eq!(frood, frood2);
|
assert_eq!(frood, frood2);
|
||||||
@@ -1958,10 +1958,10 @@ mod tests {
|
|||||||
fn test_read_buffer_too_small() {
|
fn test_read_buffer_too_small() {
|
||||||
let path = &Path("tmp/lib-io-test-read-buffer-too-small.tmp");
|
let path = &Path("tmp/lib-io-test-read-buffer-too-small.tmp");
|
||||||
// ensure the file exists
|
// ensure the file exists
|
||||||
io::file_writer(path, [io::Create]).get();
|
io::file_writer(path, [io::Create]).unwrap();
|
||||||
|
|
||||||
let file = io::file_reader(path).get();
|
let file = io::file_reader(path).unwrap();
|
||||||
let mut buf = vec::from_elem(5, 0);
|
let mut buf = vec::from_elem(5, 0u8);
|
||||||
file.read(buf, 6); // this should fail because buf is too small
|
file.read(buf, 6); // this should fail because buf is too small
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1969,17 +1969,17 @@ mod tests {
|
|||||||
fn test_read_buffer_big_enough() {
|
fn test_read_buffer_big_enough() {
|
||||||
let path = &Path("tmp/lib-io-test-read-buffer-big-enough.tmp");
|
let path = &Path("tmp/lib-io-test-read-buffer-big-enough.tmp");
|
||||||
// ensure the file exists
|
// ensure the file exists
|
||||||
io::file_writer(path, [io::Create]).get();
|
io::file_writer(path, [io::Create]).unwrap();
|
||||||
|
|
||||||
let file = io::file_reader(path).get();
|
let file = io::file_reader(path).unwrap();
|
||||||
let mut buf = vec::from_elem(5, 0);
|
let mut buf = vec::from_elem(5, 0u8);
|
||||||
file.read(buf, 4); // this should succeed because buf is big enough
|
file.read(buf, 4); // this should succeed because buf is big enough
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_write_empty() {
|
fn test_write_empty() {
|
||||||
let file = io::file_writer(&Path("tmp/lib-io-test-write-empty.tmp"),
|
let file = io::file_writer(&Path("tmp/lib-io-test-write-empty.tmp"),
|
||||||
[io::Create]).get();
|
[io::Create]).unwrap();
|
||||||
file.write([]);
|
file.write([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2025,7 +2025,7 @@ mod tests {
|
|||||||
|
|
||||||
// write the ints to the file
|
// write the ints to the file
|
||||||
{
|
{
|
||||||
let file = io::file_writer(&path, [io::Create]).get();
|
let file = io::file_writer(&path, [io::Create]).unwrap();
|
||||||
for uints.iter().advance |i| {
|
for uints.iter().advance |i| {
|
||||||
file.write_le_u64(*i);
|
file.write_le_u64(*i);
|
||||||
}
|
}
|
||||||
@@ -2033,7 +2033,7 @@ mod tests {
|
|||||||
|
|
||||||
// then read them back and check that they are the same
|
// then read them back and check that they are the same
|
||||||
{
|
{
|
||||||
let file = io::file_reader(&path).get();
|
let file = io::file_reader(&path).unwrap();
|
||||||
for uints.iter().advance |i| {
|
for uints.iter().advance |i| {
|
||||||
assert_eq!(file.read_le_u64(), *i);
|
assert_eq!(file.read_le_u64(), *i);
|
||||||
}
|
}
|
||||||
@@ -2047,7 +2047,7 @@ mod tests {
|
|||||||
|
|
||||||
// write the ints to the file
|
// write the ints to the file
|
||||||
{
|
{
|
||||||
let file = io::file_writer(&path, [io::Create]).get();
|
let file = io::file_writer(&path, [io::Create]).unwrap();
|
||||||
for uints.iter().advance |i| {
|
for uints.iter().advance |i| {
|
||||||
file.write_be_u64(*i);
|
file.write_be_u64(*i);
|
||||||
}
|
}
|
||||||
@@ -2055,7 +2055,7 @@ mod tests {
|
|||||||
|
|
||||||
// then read them back and check that they are the same
|
// then read them back and check that they are the same
|
||||||
{
|
{
|
||||||
let file = io::file_reader(&path).get();
|
let file = io::file_reader(&path).unwrap();
|
||||||
for uints.iter().advance |i| {
|
for uints.iter().advance |i| {
|
||||||
assert_eq!(file.read_be_u64(), *i);
|
assert_eq!(file.read_be_u64(), *i);
|
||||||
}
|
}
|
||||||
@@ -2069,7 +2069,7 @@ mod tests {
|
|||||||
|
|
||||||
// write the ints to the file
|
// write the ints to the file
|
||||||
{
|
{
|
||||||
let file = io::file_writer(&path, [io::Create]).get();
|
let file = io::file_writer(&path, [io::Create]).unwrap();
|
||||||
for ints.iter().advance |i| {
|
for ints.iter().advance |i| {
|
||||||
file.write_be_i32(*i);
|
file.write_be_i32(*i);
|
||||||
}
|
}
|
||||||
@@ -2077,7 +2077,7 @@ mod tests {
|
|||||||
|
|
||||||
// then read them back and check that they are the same
|
// then read them back and check that they are the same
|
||||||
{
|
{
|
||||||
let file = io::file_reader(&path).get();
|
let file = io::file_reader(&path).unwrap();
|
||||||
for ints.iter().advance |i| {
|
for ints.iter().advance |i| {
|
||||||
// this tests that the sign extension is working
|
// this tests that the sign extension is working
|
||||||
// (comparing the values as i32 would not test this)
|
// (comparing the values as i32 would not test this)
|
||||||
@@ -2093,12 +2093,12 @@ mod tests {
|
|||||||
let buf = ~[0x41, 0x02, 0x00, 0x00];
|
let buf = ~[0x41, 0x02, 0x00, 0x00];
|
||||||
|
|
||||||
{
|
{
|
||||||
let file = io::file_writer(&path, [io::Create]).get();
|
let file = io::file_writer(&path, [io::Create]).unwrap();
|
||||||
file.write(buf);
|
file.write(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let file = io::file_reader(&path).get();
|
let file = io::file_reader(&path).unwrap();
|
||||||
let f = file.read_be_f32();
|
let f = file.read_be_f32();
|
||||||
assert_eq!(f, 8.1250);
|
assert_eq!(f, 8.1250);
|
||||||
}
|
}
|
||||||
@@ -2110,13 +2110,13 @@ mod tests {
|
|||||||
let f:f32 = 8.1250;
|
let f:f32 = 8.1250;
|
||||||
|
|
||||||
{
|
{
|
||||||
let file = io::file_writer(&path, [io::Create]).get();
|
let file = io::file_writer(&path, [io::Create]).unwrap();
|
||||||
file.write_be_f32(f);
|
file.write_be_f32(f);
|
||||||
file.write_le_f32(f);
|
file.write_le_f32(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let file = io::file_reader(&path).get();
|
let file = io::file_reader(&path).unwrap();
|
||||||
assert_eq!(file.read_be_f32(), 8.1250);
|
assert_eq!(file.read_be_f32(), 8.1250);
|
||||||
assert_eq!(file.read_le_f32(), 8.1250);
|
assert_eq!(file.read_le_f32(), 8.1250);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -736,7 +736,7 @@ mod test {
|
|||||||
let server_stream_watcher = server_stream_watcher;
|
let server_stream_watcher = server_stream_watcher;
|
||||||
rtdebug!("starting read");
|
rtdebug!("starting read");
|
||||||
let alloc: AllocCallback = |size| {
|
let alloc: AllocCallback = |size| {
|
||||||
vec_to_uv_buf(vec::from_elem(size, 0))
|
vec_to_uv_buf(vec::from_elem(size, 0u8))
|
||||||
};
|
};
|
||||||
do client_tcp_watcher.read_start(alloc)
|
do client_tcp_watcher.read_start(alloc)
|
||||||
|stream_watcher, nread, buf, status| {
|
|stream_watcher, nread, buf, status| {
|
||||||
|
|||||||
@@ -178,7 +178,6 @@ impl<A:ToStr> ToStr for @[A] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
use hashmap::HashMap;
|
use hashmap::HashMap;
|
||||||
use hashmap::HashSet;
|
use hashmap::HashSet;
|
||||||
|
|||||||
@@ -3049,7 +3049,6 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore(windows)]
|
#[ignore(windows)]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
|
||||||
fn test_grow_fn_fail() {
|
fn test_grow_fn_fail() {
|
||||||
let mut v = ~[];
|
let mut v = ~[];
|
||||||
do v.grow_fn(100) |i| {
|
do v.grow_fn(100) |i| {
|
||||||
@@ -3108,7 +3107,6 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore(windows)]
|
#[ignore(windows)]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
|
||||||
fn test_permute_fail() {
|
fn test_permute_fail() {
|
||||||
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|||||||
@@ -835,7 +835,7 @@ mod test {
|
|||||||
|
|
||||||
// because of the SCTable, I now need a tidy way of
|
// because of the SCTable, I now need a tidy way of
|
||||||
// creating syntax objects. Sigh.
|
// creating syntax objects. Sigh.
|
||||||
#[deriving(Eq)]
|
#[deriving(Clone, Eq)]
|
||||||
enum TestSC {
|
enum TestSC {
|
||||||
M(Mrk),
|
M(Mrk),
|
||||||
R(ident,Name)
|
R(ident,Name)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ fn read_line() {
|
|||||||
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
||||||
|
|
||||||
for int::range(0, 3) |_i| {
|
for int::range(0, 3) |_i| {
|
||||||
let reader = result::get(&io::file_reader(&path));
|
let reader = result::unwrap(io::file_reader(&path));
|
||||||
while !reader.eof() {
|
while !reader.eof() {
|
||||||
reader.read_line();
|
reader.read_line();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,6 +154,15 @@ fn bfs(graph: graph, key: node_id) -> bfs_result {
|
|||||||
marks
|
marks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Clone)]
|
||||||
|
enum color {
|
||||||
|
white,
|
||||||
|
// node_id marks which node turned this gray/black.
|
||||||
|
// the node id later becomes the parent.
|
||||||
|
gray(node_id),
|
||||||
|
black(node_id)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Another version of the bfs function.
|
* Another version of the bfs function.
|
||||||
*
|
*
|
||||||
@@ -163,14 +172,6 @@ fn bfs(graph: graph, key: node_id) -> bfs_result {
|
|||||||
fn bfs2(graph: graph, key: node_id) -> bfs_result {
|
fn bfs2(graph: graph, key: node_id) -> bfs_result {
|
||||||
// This works by doing functional updates of a color vector.
|
// This works by doing functional updates of a color vector.
|
||||||
|
|
||||||
enum color {
|
|
||||||
white,
|
|
||||||
// node_id marks which node turned this gray/black.
|
|
||||||
// the node id later becomes the parent.
|
|
||||||
gray(node_id),
|
|
||||||
black(node_id)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut colors = do vec::from_fn(graph.len()) |i| {
|
let mut colors = do vec::from_fn(graph.len()) |i| {
|
||||||
if i as node_id == key {
|
if i as node_id == key {
|
||||||
gray(key)
|
gray(key)
|
||||||
@@ -236,14 +237,6 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result {
|
|||||||
fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
|
fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
|
||||||
// This works by doing functional updates of a color vector.
|
// This works by doing functional updates of a color vector.
|
||||||
|
|
||||||
enum color {
|
|
||||||
white,
|
|
||||||
// node_id marks which node turned this gray/black.
|
|
||||||
// the node id later becomes the parent.
|
|
||||||
gray(node_id),
|
|
||||||
black(node_id)
|
|
||||||
};
|
|
||||||
|
|
||||||
let graph_vec = graph.get(); // FIXME #3387 requires this temp
|
let graph_vec = graph.get(); // FIXME #3387 requires this temp
|
||||||
let mut colors = do vec::from_fn(graph_vec.len()) |i| {
|
let mut colors = do vec::from_fn(graph_vec.len()) |i| {
|
||||||
if i as node_id == key {
|
if i as node_id == key {
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let writer = if os::getenv("RUST_BENCH").is_some() {
|
let writer = if os::getenv("RUST_BENCH").is_some() {
|
||||||
result::get(&io::file_writer(&Path("./shootout-fasta.data"),
|
result::unwrap(io::file_writer(&Path("./shootout-fasta.data"),
|
||||||
[io::Truncate, io::Create]))
|
[io::Truncate, io::Create]))
|
||||||
} else {
|
} else {
|
||||||
io::stdout()
|
io::stdout()
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ fn main() {
|
|||||||
// get to this massive data set, but include_bin! chokes on it (#2598)
|
// get to this massive data set, but include_bin! chokes on it (#2598)
|
||||||
let path = Path(env!("CFG_SRC_DIR"))
|
let path = Path(env!("CFG_SRC_DIR"))
|
||||||
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
||||||
result::get(&io::file_reader(&path))
|
result::unwrap(io::file_reader(&path))
|
||||||
} else {
|
} else {
|
||||||
io::stdin()
|
io::stdin()
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ fn give_any(f: &fn:()) {
|
|||||||
|
|
||||||
fn give_owned(f: &fn:Send()) {
|
fn give_owned(f: &fn:Send()) {
|
||||||
take_any(f);
|
take_any(f);
|
||||||
take_const_owned(f); //~ ERROR expected bounds `Freeze+Send` but found bounds `Send`
|
take_const_owned(f); //~ ERROR expected bounds `Send+Freeze` but found bounds `Send`
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ fn main() {
|
|||||||
let mut res = foo(x);
|
let mut res = foo(x);
|
||||||
|
|
||||||
let mut v = ~[];
|
let mut v = ~[];
|
||||||
v = ~[(res)] + v; //~ instantiating a type parameter with an incompatible type `foo`, which does not fulfill `Clone`
|
v = ~[(res)] + v; //~ failed to find an implementation of trait
|
||||||
assert_eq!(v.len(), 2);
|
assert_eq!(v.len(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,8 @@ trait Foo {
|
|||||||
fn a(_x: ~Foo:Send) {
|
fn a(_x: ~Foo:Send) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn b(_x: ~Foo:Send+Clone) {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn c(x: ~Foo:Freeze+Send) {
|
fn c(x: ~Foo:Freeze+Send) {
|
||||||
b(x); //~ ERROR expected bounds `Clone+Send`
|
a(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn d(x: ~Foo:) {
|
fn d(x: ~Foo:) {
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|
||||||
// error-pattern: instantiating a type parameter with an incompatible type
|
// error-pattern: failed to find an implementation
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
i:int
|
i:int
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ trait methods {
|
|||||||
|
|
||||||
impl methods for () {
|
impl methods for () {
|
||||||
fn to_bytes(&self) -> ~[u8] {
|
fn to_bytes(&self) -> ~[u8] {
|
||||||
vec::from_elem(0, 0)
|
vec::from_elem(0, 0u8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
extern mod extra;
|
extern mod extra;
|
||||||
use extra::list;
|
use extra::list;
|
||||||
|
|
||||||
|
#[deriving(Clone)]
|
||||||
enum foo {
|
enum foo {
|
||||||
a(uint),
|
a(uint),
|
||||||
b(~str),
|
b(~str),
|
||||||
|
|||||||
@@ -14,15 +14,15 @@ extern mod extra;
|
|||||||
|
|
||||||
use extra::list::*;
|
use extra::list::*;
|
||||||
|
|
||||||
fn pure_length_go<T>(ls: @List<T>, acc: uint) -> uint {
|
fn pure_length_go<T:Clone>(ls: @List<T>, acc: uint) -> uint {
|
||||||
match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
|
match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pure_length<T>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
|
fn pure_length<T:Clone>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
|
||||||
|
|
||||||
fn nonempty_list<T>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
|
fn nonempty_list<T:Clone>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
|
||||||
|
|
||||||
fn safe_head<T>(ls: @List<T>) -> T {
|
fn safe_head<T:Clone>(ls: @List<T>) -> T {
|
||||||
assert!(!is_empty(ls));
|
assert!(!is_empty(ls));
|
||||||
return head(ls);
|
return head(ls);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,16 +8,15 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
pub fn main() {
|
#[deriving(Clone)]
|
||||||
struct Foo { a: ~str }
|
struct Foo {
|
||||||
|
a: ~str,
|
||||||
|
}
|
||||||
|
|
||||||
let v = [ ~Foo { a: ~"Hello!" }, ..129 ];
|
pub fn main() {
|
||||||
let w = [ ~"Hello!", ..129 ];
|
|
||||||
let x = [ @[true], ..512 ];
|
let x = [ @[true], ..512 ];
|
||||||
let y = [ 0, ..1 ];
|
let y = [ 0, ..1 ];
|
||||||
|
|
||||||
error!("%?", v);
|
|
||||||
error!("%?", w);
|
|
||||||
error!("%?", x);
|
error!("%?", x);
|
||||||
error!("%?", y);
|
error!("%?", y);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user