test: Fix tests.

This commit is contained in:
Patrick Walton 2013-07-11 12:05:17 -07:00
parent e20549ff19
commit 2dbb3c3887
36 changed files with 217 additions and 243 deletions

View File

@ -206,7 +206,6 @@ The keywords are the following strings:
~~~~~~~~ {.keyword}
as
break
copy
do
else enum extern
false fn for
@ -443,7 +442,7 @@ Two examples of paths with type arguments:
~~~~
# use std::hashmap::HashMap;
# 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
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
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
parameter is given a [`Copy` bound](#type-kinds).
type can only be moved, not copied.
~~~~
fn id<T: Copy>(x: T) -> T { x }
fn id<T>(x: T) -> T { x }
~~~~
Similarly, [trait](#traits) bounds can be specified for type
@ -1519,8 +1517,6 @@ A complete list of the built-in language items follows:
`const`
: Cannot be mutated.
`copy`
: Can be implicitly copied.
`owned`
: Are uniquely owned.
`durable`
@ -1587,7 +1583,8 @@ A complete list of the built-in language items follows:
`check_not_borrowed`
: Fail if a value has existing borrowed pointers to it.
`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
> 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
When a [local variable](#memory-slots) is used as an [rvalue](#lvalues-rvalues-and-temporaries)
the variable will either be [moved](#move-expressions) or [copied](#copy-expressions),
When a [local variable](#memory-slots) is used
as an [rvalue](#lvalues-rvalues-and-temporaries)
the variable will either be [moved](#move-expressions) or copied,
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.
@ -1918,9 +1918,9 @@ task in a _failing state_.
### Unary operator expressions
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, before the expression they apply to.
Rust defines six symbolic unary operators.
They are all written as prefix operators,
before the expression they apply to.
`-`
: Negation. May only be applied to numeric types.
@ -2119,60 +2119,6 @@ An example of a parenthesized expression:
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
@ -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).
This can be made explicit using the ```copy``` keyword,
changed to bind to a borrowed pointer by using the ```ref``` keyword,
This can be changed to bind to a borrowed pointer by
using the ```ref``` keyword,
or to a mutable borrowed pointer using ```ref mut```.
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:
~~~~~~~
fn map<A: Copy, B: Copy>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
if xs.len() == 0 { return ~[]; }
let first: B = f(copy xs[0]);
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
return ~[first] + rest;
fn map<A: Clone, B: Clone>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
if xs.len() == 0 {
return ~[];
}
let first: B = f(xs[0].clone());
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
return ~[first] + rest;
}
~~~~~~~
Here, `first` has type `B`, referring to `map`'s `B` type parameter; and `rest` has
type `~[B]`, a vector type with element type `B`.
Here, `first` has type `B`, referring to `map`'s `B` type parameter;
and `rest` has type `~[B]`, a vector type with element type `B`.
### Self types
@ -2919,7 +2868,9 @@ trait Printable {
}
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`
: 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`
: Types of this kind can be safely sent between tasks.
This kind includes scalars, owning pointers, owned closures, and
structural types containing only other owned types. All `Send` types are `Static`.
`Copy`
: This kind includes all types that can be copied. All types with
sendable kind are copyable, as are managed boxes, managed closures,
trait types, and structural types built out of these.
Types with destructors (types that implement `Drop`) can not implement `Copy`.
structural types containing only other owned types.
All `Send` types are `'static`.
`'static`
: Types of this kind do not contain any borrowed pointers;
this can be a useful guarantee for code
that breaks borrowing assumptions
using [`unsafe` operations](#unsafe-functions).
`Drop`
: This is not strictly a kind, but its presence interacts with kinds: the `Drop`
trait provides a single method `drop` that takes no parameters, and is run
when values of the type are dropped. 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
that do not implement `Copy` can implement `Drop`.
: This is not strictly a kind,
but its presence interacts with kinds:
the `Drop` trait provides a single method `drop`
that takes no parameters,
and is run when values of the type are dropped.
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_
: 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.
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,
so the `Copy` bound is frequently required on function type parameters.
For example, this is not a valid program:
~~~~{.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.
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
@ -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
reference-counting).
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.
Owned box values exist in 1:1 correspondence with their heap allocation.
An example of constructing one managed box type and value, and one owned box
type and value:

View File

@ -1275,6 +1275,11 @@ The `+` operator means concatenation when applied to vector types.
# enum Crayon { Almond, AntiqueBrass, Apricot,
# Aquamarine, Asparagus, AtomicTangerine,
# BananaMania, Beaver, Bittersweet };
# impl Clone for Crayon {
# fn clone(&self) -> Crayon {
# *self
# }
# }
let my_crayons = ~[Almond, AntiqueBrass, Apricot];
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
that a type parameter could refer to.
As motivation, let us consider copying in Rust. The `copy` operation
is not defined for all Rust types. One reason is user-defined
destructors: copying a type that has a destructor could result in the
destructor running multiple times. Therefore, types with user-defined
destructors cannot be copied, either implicitly or explicitly, and
neither can types that own other types containing destructors.
As motivation, let us consider copying in Rust.
The `clone` method is not defined for all Rust types.
One reason is user-defined destructors:
copying a type that has a destructor
could result in the destructor running multiple times.
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
parameter `T`, can you copy values of that type? In Rust, you can't,
This complicates handling of generic functions.
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.
~~~~ {.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
copyable types: that is, those that have the `Copy` trait. In that
case, we can explicitly create a second copy of the value we are
returning using the `copy` keyword:
However, we can tell the compiler
that the `head` function is only for copyable types:
that is, those that implement the `Clone` trait.
In that case,
we can explicitly create a second copy of the value we are returning
using the `clone` keyword:
~~~~
// This does
fn head<T: Copy>(v: &[T]) -> T {
copy v[0]
fn head<T: Clone>(v: &[T]) -> T {
v[0].clone()
}
~~~~
This says that we can call `head` on any type `T` as long as that type
implements the `Copy` trait. When instantiating a generic function,
you can only instantiate it with types that implement the correct
trait, so you could not apply `head` to a type with a
destructor. (`Copy` is a special trait that is built in to the
compiler, making it possible for the compiler to enforce this
restriction.)
This says that we can call `head` on any type `T`
as long as that type implements the `Clone` trait.
When instantiating a generic function,
you can only instantiate it with types
that implement the correct trait,
so you could not apply `head` to a type
that does not implement `Clone`.
While most traits can be defined and implemented by user code, three
traits are automatically derived and implemented for all applicable
types by the compiler, and may not be overridden:
While most traits can be defined and implemented by user code,
two traits are automatically derived and implemented
for all applicable types by the compiler,
and may not be overridden:
* `Copy` - Types that can be copied, either implicitly, or explicitly with the
`copy` operator. All types are copyable unless they have destructors or
contain types with destructors.
* `Send` - Sendable types.
Types are sendable
unless they contain managed boxes, managed closures, or borrowed pointers.
* `Owned` - Owned types. Types are owned unless they contain managed
boxes, managed closures, or borrowed pointers. Owned types may or
may not be copyable.
* `Freeze` - Constant (immutable) types.
These are types that do not contain anything intrinsically mutable.
Intrinsically mutable values include `@mut`
and `Cell` in the standard library.
* `Const` - Constant (immutable) types. These are types that do not contain
mutable fields.
> ***Note:*** These three traits were referred to as 'kinds' in earlier
> ***Note:*** These two traits were referred to as 'kinds' in earlier
> iterations of the language, and often still are.
Additionally, the `Drop` trait is used to define destructors. This
@ -1908,10 +1916,11 @@ may call it.
## Declaring and implementing traits
A trait consists of a set of methods, without bodies, or may be empty,
as is the case with `Copy`, `Owned`, and `Const`. For example, we could
declare the trait `Printable` for things that can be printed to the
console, with a single method:
A trait consists of a set of methods without bodies,
or may be empty, as is the case with `Send` and `Freeze`.
For example, we could declare the trait
`Printable` for things that can be printed to the console,
with a single method:
~~~~
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
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
compile-time error when anyone tries to call `print_all` on an array
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); }
fn print_all<T: Printable + Copy>(printable_things: ~[T]) {
fn print_all<T: Printable + Clone>(printable_things: ~[T]) {
let mut i = 0;
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();
i += 1;
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[deriving(Eq)]
#[deriving(Clone, Eq)]
pub enum mode {
mode_compile_fail,
mode_run_fail,
@ -18,6 +18,7 @@ pub enum mode {
mode_codegen
}
#[deriving(Clone)]
pub struct config {
// The library paths required for running the compiler
compile_lib_path: ~str,

View File

@ -40,6 +40,17 @@ pub mod runtest;
pub mod common;
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() {
let args = os::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")),
run_ignored: getopts::opt_present(matches, "ignored"),
filter:
<<<<<<< HEAD
if !matches.free.is_empty() {
Some(matches.free[0].clone())
} else {
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)),
save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map(|s| Path(*s)),

View File

@ -15,7 +15,7 @@ pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
// Load any test directives embedded in the file
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
let mut error_patterns = ~[];
let rdr = io::file_reader(testfile).get();
let rdr = io::file_reader(testfile).unwrap();
let mut line_num = 1u;
while !rdr.eof() {
let ln = rdr.read_line();

View File

@ -101,7 +101,7 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> 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() {
let ln = rdr.read_line();

View File

@ -672,7 +672,7 @@ fn dump_output_file(config: &config, testfile: &Path,
out: &str, extension: &str) {
let outfile = make_out_name(config, testfile, extension);
let writer =
io::file_writer(&outfile, [io::Create, io::Truncate]).get();
io::file_writer(&outfile, [io::Create, io::Truncate]).unwrap();
writer.write_str(out);
}

View File

@ -1453,7 +1453,7 @@ mod tests {
fn bench_big_bitv_big(b: &mut BenchHarness) {
let mut r = rng();
let mut storage = ~[];
storage.grow(BENCH_BITS / uint::bits, &0);
storage.grow(BENCH_BITS / uint::bits, &0u);
let mut bitv = BigBitv::new(storage);
do b.iter {
bitv.set((r.next() as uint) % BENCH_BITS, true);

View File

@ -244,14 +244,15 @@ mod tests {
use digest::{Digest, DigestUtil};
use sha1::Sha1;
#[deriving(Clone)]
struct Test {
input: ~str,
output: ~[u8],
output_str: ~str,
}
#[test]
fn test() {
struct Test {
input: ~str,
output: ~[u8],
output_str: ~str,
}
fn a_million_letter_a() -> ~str {
let mut i = 0;
let mut rs = ~"";

View File

@ -417,7 +417,7 @@ mod test {
use std::vec;
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| {
file.write_str(*str);
@ -562,9 +562,11 @@ mod test {
let f2 =
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");
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");
let mut lines = ~[];

View File

@ -12,7 +12,7 @@
#[deriving(Eq)]
#[deriving(Clone, Eq)]
pub enum List<T> {
Cons(T, @List<T>),
Nil,

View File

@ -38,6 +38,7 @@ use get_data_for_req = uv_ll::get_data_for_req;
use ll = uv_ll;
/// An IP address
#[deriving(Clone)]
pub enum IpAddr {
/// An IPv4 address
Ipv4(sockaddr_in),

View File

@ -93,6 +93,7 @@ pub struct TcpErrData {
}
/// Details returned as part of a `Result::Err` result from `tcp::listen`
#[deriving(Clone)]
pub enum TcpListenErrData {
/**
* Some unplanned-for error. The first and second fields correspond
@ -120,6 +121,7 @@ pub enum TcpListenErrData {
AccessDenied
}
/// Details returned as part of a `Result::Err` result from `tcp::connect`
#[deriving(Clone)]
pub enum TcpConnectErrData {
/**
* Some unplanned-for error. The first and second fields correspond

View File

@ -12,13 +12,14 @@
#[allow(missing_doc)];
use std::clone::Clone;
use std::unstable::intrinsics::{move_val_init, init};
use std::util::{replace, swap};
use std::vec;
use std::iterator::FromIterator;
/// A priority queue implemented with a binary heap
#[deriving(Clone)]
pub struct PriorityQueue<T> {
priv data: ~[T],
}

View File

@ -926,6 +926,7 @@ mod test_tim_sort {
use std::rand;
use std::vec;
#[deriving(Clone)]
struct CVal {
val: float,
}
@ -992,7 +993,10 @@ mod test_tim_sort {
fail!("Guarantee the fail");
}
struct DVal { val: uint }
#[deriving(Clone)]
struct DVal {
val: uint,
}
impl Ord for DVal {
fn lt(&self, _x: &DVal) -> bool { true }

View File

@ -1245,7 +1245,7 @@ mod tests {
ignore: false,
should_fail: false
},
testfn: DynTestFn(testfn.clone()),
testfn: DynTestFn(testfn),
};
tests.push(test);
}

View File

@ -266,6 +266,7 @@ pub struct uv_timer_t {
}
// unix size: 16
#[deriving(Clone)]
pub struct sockaddr_in {
sin_family: u16,
sin_port: u16,
@ -280,6 +281,7 @@ pub struct sockaddr_in6 {
a0: *u8, a1: *u8,
a2: *u8, a3: *u8,
}
#[cfg(target_arch="x86")]
#[cfg(target_arch="arm")]
#[cfg(target_arch="mips")]
@ -290,6 +292,12 @@ pub struct sockaddr_in6 {
a6: *u8, a7: *u8,
}
impl Clone for sockaddr_in6 {
fn clone(&self) -> sockaddr_in6 {
*self
}
}
// unix size: 28 .. FIXME #1645
// stuck with 32 because of rust padding structs?
pub type addr_in = addr_in_impl::addr_in;

View File

@ -63,8 +63,8 @@ fn git_repo_pkg() -> PkgId {
fn writeFile(file_path: &Path, contents: &str) {
let out: @io::Writer =
result::get(&io::file_writer(file_path,
[io::Create, io::Truncate]));
result::unwrap(io::file_writer(file_path,
[io::Create, io::Truncate]));
out.write_line(contents);
}

View File

@ -44,7 +44,7 @@ pub fn main() {
}
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); } }");

View File

@ -1856,11 +1856,11 @@ mod tests {
debug!(frood.clone());
{
let out: @io::Writer =
result::get(
&io::file_writer(tmpfile, [io::Create, io::Truncate]));
result::unwrap(
io::file_writer(tmpfile, [io::Create, io::Truncate]));
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();
debug!(frood2.clone());
assert_eq!(frood, frood2);
@ -1958,10 +1958,10 @@ mod tests {
fn test_read_buffer_too_small() {
let path = &Path("tmp/lib-io-test-read-buffer-too-small.tmp");
// 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 mut buf = vec::from_elem(5, 0);
let file = io::file_reader(path).unwrap();
let mut buf = vec::from_elem(5, 0u8);
file.read(buf, 6); // this should fail because buf is too small
}
@ -1969,17 +1969,17 @@ mod tests {
fn test_read_buffer_big_enough() {
let path = &Path("tmp/lib-io-test-read-buffer-big-enough.tmp");
// 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 mut buf = vec::from_elem(5, 0);
let file = io::file_reader(path).unwrap();
let mut buf = vec::from_elem(5, 0u8);
file.read(buf, 4); // this should succeed because buf is big enough
}
#[test]
fn test_write_empty() {
let file = io::file_writer(&Path("tmp/lib-io-test-write-empty.tmp"),
[io::Create]).get();
[io::Create]).unwrap();
file.write([]);
}
@ -2025,7 +2025,7 @@ mod tests {
// 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| {
file.write_le_u64(*i);
}
@ -2033,7 +2033,7 @@ mod tests {
// 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| {
assert_eq!(file.read_le_u64(), *i);
}
@ -2047,7 +2047,7 @@ mod tests {
// 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| {
file.write_be_u64(*i);
}
@ -2055,7 +2055,7 @@ mod tests {
// 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| {
assert_eq!(file.read_be_u64(), *i);
}
@ -2069,7 +2069,7 @@ mod tests {
// 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| {
file.write_be_i32(*i);
}
@ -2077,7 +2077,7 @@ mod tests {
// 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| {
// this tests that the sign extension is working
// (comparing the values as i32 would not test this)
@ -2093,12 +2093,12 @@ mod tests {
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);
}
{
let file = io::file_reader(&path).get();
let file = io::file_reader(&path).unwrap();
let f = file.read_be_f32();
assert_eq!(f, 8.1250);
}
@ -2110,13 +2110,13 @@ mod tests {
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_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_le_f32(), 8.1250);
}

View File

@ -736,7 +736,7 @@ mod test {
let server_stream_watcher = server_stream_watcher;
rtdebug!("starting read");
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)
|stream_watcher, nread, buf, status| {

View File

@ -178,7 +178,6 @@ impl<A:ToStr> ToStr for @[A] {
}
#[cfg(test)]
#[allow(non_implicitly_copyable_typarams)]
mod tests {
use hashmap::HashMap;
use hashmap::HashSet;

View File

@ -3049,7 +3049,6 @@ mod tests {
#[test]
#[ignore(windows)]
#[should_fail]
#[allow(non_implicitly_copyable_typarams)]
fn test_grow_fn_fail() {
let mut v = ~[];
do v.grow_fn(100) |i| {
@ -3108,7 +3107,6 @@ mod tests {
#[test]
#[ignore(windows)]
#[should_fail]
#[allow(non_implicitly_copyable_typarams)]
fn test_permute_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;

View File

@ -835,7 +835,7 @@ mod test {
// because of the SCTable, I now need a tidy way of
// creating syntax objects. Sigh.
#[deriving(Eq)]
#[deriving(Clone, Eq)]
enum TestSC {
M(Mrk),
R(ident,Name)

View File

@ -75,7 +75,7 @@ fn read_line() {
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
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() {
reader.read_line();
}

View File

@ -154,6 +154,15 @@ fn bfs(graph: graph, key: node_id) -> bfs_result {
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.
*
@ -163,14 +172,6 @@ fn bfs(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.
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| {
if i as node_id == 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 {
// 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 mut colors = do vec::from_fn(graph_vec.len()) |i| {
if i as node_id == key {

View File

@ -124,8 +124,8 @@ fn main() {
};
let writer = if os::getenv("RUST_BENCH").is_some() {
result::get(&io::file_writer(&Path("./shootout-fasta.data"),
[io::Truncate, io::Create]))
result::unwrap(io::file_writer(&Path("./shootout-fasta.data"),
[io::Truncate, io::Create]))
} else {
io::stdout()
};

View File

@ -162,7 +162,7 @@ fn main() {
// get to this massive data set, but include_bin! chokes on it (#2598)
let path = Path(env!("CFG_SRC_DIR"))
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
result::get(&io::file_reader(&path))
result::unwrap(io::file_reader(&path))
} else {
io::stdin()
};

View File

@ -11,7 +11,7 @@ fn give_any(f: &fn:()) {
fn give_owned(f: &fn:Send()) {
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() {}

View File

@ -37,7 +37,7 @@ fn main() {
let mut res = foo(x);
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);
}

View File

@ -14,11 +14,8 @@ trait Foo {
fn a(_x: ~Foo:Send) {
}
fn b(_x: ~Foo:Send+Clone) {
}
fn c(x: ~Foo:Freeze+Send) {
b(x); //~ ERROR expected bounds `Clone+Send`
a(x);
}
fn d(x: ~Foo:) {

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: instantiating a type parameter with an incompatible type
// error-pattern: failed to find an implementation
struct r {
i:int

View File

@ -20,7 +20,7 @@ trait methods {
impl methods for () {
fn to_bytes(&self) -> ~[u8] {
vec::from_elem(0, 0)
vec::from_elem(0, 0u8)
}
}

View File

@ -13,6 +13,7 @@
extern mod extra;
use extra::list;
#[deriving(Clone)]
enum foo {
a(uint),
b(~str),

View File

@ -14,15 +14,15 @@ extern mod extra;
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) } }
}
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));
return head(ls);
}

View File

@ -8,16 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub fn main() {
struct Foo { a: ~str }
#[deriving(Clone)]
struct Foo {
a: ~str,
}
let v = [ ~Foo { a: ~"Hello!" }, ..129 ];
let w = [ ~"Hello!", ..129 ];
pub fn main() {
let x = [ @[true], ..512 ];
let y = [ 0, ..1 ];
error!("%?", v);
error!("%?", w);
error!("%?", x);
error!("%?", y);
}