~~~~~~~~ {.keyword}
as
break
-copy
do
else enum extern
false fn for
~~~~
# 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
# }
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
`const`
: Cannot be mutated.
-`copy`
- : Can be implicitly copied.
`owned`
: Are uniquely owned.
`durable`
`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`.
#### 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.
### 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.
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
}
~~~~
-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,
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
}
impl Printable for ~str {
- fn make_string(&self) -> ~str { copy *self }
+ fn make_string(&self) -> ~str {
+ (*self).clone()
+ }
}
~~~~~~~~
`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,
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
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:
# 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];
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.
-
-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,
+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,
and if you try to run the following code the compiler will complain.
~~~~ {.xfail-test}
}
~~~~
-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.)
-
-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:
+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`.
-* `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.
+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:
-* `Owned` - Owned types. Types are owned unless they contain managed
- boxes, managed closures, or borrowed pointers. Owned types may or
- may not be copyable.
+* `Send` - Sendable types.
+Types are sendable
+unless they contain managed boxes, managed closures, or borrowed pointers.
-* `Const` - Constant (immutable) types. These are types that do not contain
- mutable fields.
+* `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.
-> ***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
## 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 {
~~~~
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.
~~~
# 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;
}
// 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,
mode_codegen
}
+#[deriving(Clone)]
pub struct config {
// The library paths required for running the compiler
compile_lib_path: ~str,
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);
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)),
// 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();
}
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();
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);
}
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);
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 = ~"";
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);
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 = ~[];
-#[deriving(Eq)]
+#[deriving(Clone, Eq)]
pub enum List<T> {
Cons(T, @List<T>),
Nil,
use ll = uv_ll;
/// An IP address
+#[deriving(Clone)]
pub enum IpAddr {
/// An IPv4 address
Ipv4(sockaddr_in),
}
/// 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
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
#[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],
}
use std::rand;
use std::vec;
+ #[deriving(Clone)]
struct CVal {
val: float,
}
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 }
ignore: false,
should_fail: false
},
- testfn: DynTestFn(testfn.clone()),
+ testfn: DynTestFn(testfn),
};
tests.push(test);
}
}
// unix size: 16
+#[deriving(Clone)]
pub struct sockaddr_in {
sin_family: u16,
sin_port: u16,
a0: *u8, a1: *u8,
a2: *u8, a3: *u8,
}
+
#[cfg(target_arch="x86")]
#[cfg(target_arch="arm")]
#[cfg(target_arch="mips")]
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;
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);
}
}
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); } }");
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);
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
}
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([]);
}
// 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);
}
// 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);
}
// 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);
}
// 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);
}
// 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);
}
// 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)
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);
}
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);
}
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| {
}
#[cfg(test)]
-#[allow(non_implicitly_copyable_typarams)]
mod tests {
use hashmap::HashMap;
use hashmap::HashSet;
#[test]
#[ignore(windows)]
#[should_fail]
- #[allow(non_implicitly_copyable_typarams)]
fn test_grow_fn_fail() {
let mut v = ~[];
do v.grow_fn(100) |i| {
#[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;
// 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)
.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();
}
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.
*
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)
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 {
};
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()
};
// 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()
};
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() {}
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);
}
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:) {
// 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
impl methods for () {
fn to_bytes(&self) -> ~[u8] {
- vec::from_elem(0, 0)
+ vec::from_elem(0, 0u8)
}
}
extern mod extra;
use extra::list;
+#[deriving(Clone)]
enum foo {
a(uint),
b(~str),
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);
}
// 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);
}