Skip to content

Commit 2dbb3c3

Browse files
committed
test: Fix tests.
1 parent e20549f commit 2dbb3c3

36 files changed

+218
-244
lines changed

doc/rust.md

Lines changed: 58 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ The keywords are the following strings:
206206
~~~~~~~~ {.keyword}
207207
as
208208
break
209-
copy
210209
do
211210
else enum extern
212211
false fn for
@@ -443,7 +442,7 @@ Two examples of paths with type arguments:
443442
~~~~
444443
# use std::hashmap::HashMap;
445444
# fn f() {
446-
# fn id<T:Copy>(t: T) -> T { t }
445+
# fn id<T>(t: T) -> T { t }
447446
type t = HashMap<int,~str>; // Type arguments used in a type expression
448447
let x = id::<int>(10); // Type arguments used in a call expression
449448
# }
@@ -907,11 +906,10 @@ example, `sys::size_of::<u32>() == 4`.
907906

908907
Since a parameter type is opaque to the generic function, the set of
909908
operations that can be performed on it is limited. Values of parameter
910-
type can always be moved, but they can only be copied when the
911-
parameter is given a [`Copy` bound](#type-kinds).
909+
type can only be moved, not copied.
912910

913911
~~~~
914-
fn id<T: Copy>(x: T) -> T { x }
912+
fn id<T>(x: T) -> T { x }
915913
~~~~
916914

917915
Similarly, [trait](#traits) bounds can be specified for type
@@ -1519,8 +1517,6 @@ A complete list of the built-in language items follows:
15191517

15201518
`const`
15211519
: Cannot be mutated.
1522-
`copy`
1523-
: Can be implicitly copied.
15241520
`owned`
15251521
: Are uniquely owned.
15261522
`durable`
@@ -1587,7 +1583,8 @@ A complete list of the built-in language items follows:
15871583
`check_not_borrowed`
15881584
: Fail if a value has existing borrowed pointers to it.
15891585
`strdup_uniq`
1590-
: Return a new unique string containing a copy of the contents of a unique string.
1586+
: Return a new unique string
1587+
containing a copy of the contents of a unique string.
15911588

15921589
> **Note:** This list is likely to become out of date. We should auto-generate it
15931590
> from `librustc/middle/lang_items.rs`.
@@ -1736,10 +1733,13 @@ A temporary's lifetime equals the largest lifetime of any borrowed pointer that
17361733

17371734
#### Moved and copied types
17381735

1739-
When a [local variable](#memory-slots) is used as an [rvalue](#lvalues-rvalues-and-temporaries)
1740-
the variable will either be [moved](#move-expressions) or [copied](#copy-expressions),
1736+
When a [local variable](#memory-slots) is used
1737+
as an [rvalue](#lvalues-rvalues-and-temporaries)
1738+
the variable will either be [moved](#move-expressions) or copied,
17411739
depending on its type.
1742-
For types that contain mutable fields or [owning pointers](#owning-pointers), the variable is moved.
1740+
For types that contain [owning pointers](#owning-pointers)
1741+
or values that implement the special trait `Drop`,
1742+
the variable is moved.
17431743
All other types are copied.
17441744

17451745

@@ -1918,9 +1918,9 @@ task in a _failing state_.
19181918

19191919
### Unary operator expressions
19201920

1921-
Rust defines six symbolic unary operators,
1922-
in addition to the unary [copy](#unary-copy-expressions) and [move](#unary-move-expressions) operators.
1923-
They are all written as prefix operators, before the expression they apply to.
1921+
Rust defines six symbolic unary operators.
1922+
They are all written as prefix operators,
1923+
before the expression they apply to.
19241924

19251925
`-`
19261926
: Negation. May only be applied to numeric types.
@@ -2119,60 +2119,6 @@ An example of a parenthesized expression:
21192119
let x = (2 + 3) * 4;
21202120
~~~~
21212121

2122-
### Unary copy expressions
2123-
2124-
~~~~~~~~{.ebnf .gram}
2125-
copy_expr : "copy" expr ;
2126-
~~~~~~~~
2127-
2128-
> **Note:** `copy` expressions are deprecated. It's preferable to use
2129-
> the `Clone` trait and `clone()` method.
2130-
2131-
A _unary copy expression_ consists of the unary `copy` operator applied to
2132-
some argument expression.
2133-
2134-
Evaluating a copy expression first evaluates the argument expression, then
2135-
copies the resulting value, allocating any memory necessary to hold the new
2136-
copy.
2137-
2138-
[Managed boxes](#pointer-types) (type `@`) are, as usual, shallow-copied,
2139-
as are raw and borrowed pointers.
2140-
[Owned boxes](#pointer-types), [owned vectors](#vector-types) and similar owned types are deep-copied.
2141-
2142-
Since the binary [assignment operator](#assignment-expressions) `=` performs a copy or move implicitly,
2143-
the unary copy operator is typically only used to cause an argument to a function to be copied and passed by value.
2144-
2145-
An example of a copy expression:
2146-
2147-
~~~~
2148-
fn mutate(mut vec: ~[int]) {
2149-
vec[0] = 10;
2150-
}
2151-
2152-
let v = ~[1,2,3];
2153-
2154-
mutate(copy v); // Pass a copy
2155-
2156-
assert!(v[0] == 1); // Original was not modified
2157-
~~~~
2158-
2159-
### Unary move expressions
2160-
2161-
~~~~~~~~{.ebnf .gram}
2162-
move_expr : "move" expr ;
2163-
~~~~~~~~
2164-
2165-
A _unary move expression_ is similar to a [unary copy](#unary-copy-expressions) expression,
2166-
except that it can only be applied to a [local variable](#memory-slots),
2167-
and it performs a _move_ on its operand, rather than a copy.
2168-
That is, the memory location denoted by its operand is de-initialized after evaluation,
2169-
and the resulting value is a shallow copy of the operand,
2170-
even if the operand is an [owning type](#type-kinds).
2171-
2172-
2173-
> **Note:** In future versions of Rust, `move` may be removed as a separate operator;
2174-
> moves are now [automatically performed](#moved-and-copied-types) for most cases `move` would be appropriate.
2175-
21762122

21772123
### Call expressions
21782124

@@ -2507,10 +2453,11 @@ match x {
25072453
}
25082454
~~~~
25092455

2510-
Patterns that bind variables default to binding to a copy or move of the matched value
2456+
Patterns that bind variables
2457+
default to binding to a copy or move of the matched value
25112458
(depending on the matched value's type).
2512-
This can be made explicit using the ```copy``` keyword,
2513-
changed to bind to a borrowed pointer by using the ```ref``` keyword,
2459+
This can be changed to bind to a borrowed pointer by
2460+
using the ```ref``` keyword,
25142461
or to a mutable borrowed pointer using ```ref mut```.
25152462

25162463
A pattern that's just an identifier,
@@ -2896,16 +2843,18 @@ and the cast expression in `main`.
28962843
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
28972844

28982845
~~~~~~~
2899-
fn map<A: Copy, B: Copy>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
2900-
if xs.len() == 0 { return ~[]; }
2901-
let first: B = f(copy xs[0]);
2902-
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
2903-
return ~[first] + rest;
2846+
fn map<A: Clone, B: Clone>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
2847+
if xs.len() == 0 {
2848+
return ~[];
2849+
}
2850+
let first: B = f(xs[0].clone());
2851+
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
2852+
return ~[first] + rest;
29042853
}
29052854
~~~~~~~
29062855

2907-
Here, `first` has type `B`, referring to `map`'s `B` type parameter; and `rest` has
2908-
type `~[B]`, a vector type with element type `B`.
2856+
Here, `first` has type `B`, referring to `map`'s `B` type parameter;
2857+
and `rest` has type `~[B]`, a vector type with element type `B`.
29092858

29102859
### Self types
29112860

@@ -2919,7 +2868,9 @@ trait Printable {
29192868
}
29202869
29212870
impl Printable for ~str {
2922-
fn make_string(&self) -> ~str { copy *self }
2871+
fn make_string(&self) -> ~str {
2872+
(*self).clone()
2873+
}
29232874
}
29242875
~~~~~~~~
29252876

@@ -2933,23 +2884,29 @@ The kinds are:
29332884

29342885
`Freeze`
29352886
: Types of this kind are deeply immutable;
2936-
they contain no mutable memory locations directly or indirectly via pointers.
2887+
they contain no mutable memory locations
2888+
directly or indirectly via pointers.
29372889
`Send`
29382890
: Types of this kind can be safely sent between tasks.
29392891
This kind includes scalars, owning pointers, owned closures, and
2940-
structural types containing only other owned types. All `Send` types are `Static`.
2941-
`Copy`
2942-
: This kind includes all types that can be copied. All types with
2943-
sendable kind are copyable, as are managed boxes, managed closures,
2944-
trait types, and structural types built out of these.
2945-
Types with destructors (types that implement `Drop`) can not implement `Copy`.
2892+
structural types containing only other owned types.
2893+
All `Send` types are `'static`.
2894+
`'static`
2895+
: Types of this kind do not contain any borrowed pointers;
2896+
this can be a useful guarantee for code
2897+
that breaks borrowing assumptions
2898+
using [`unsafe` operations](#unsafe-functions).
29462899
`Drop`
2947-
: This is not strictly a kind, but its presence interacts with kinds: the `Drop`
2948-
trait provides a single method `drop` that takes no parameters, and is run
2949-
when values of the type are dropped. Such a method is called a "destructor",
2950-
and are always executed in "top-down" order: a value is completely destroyed
2951-
before any of the values it owns run their destructors. Only `Send` types
2952-
that do not implement `Copy` can implement `Drop`.
2900+
: This is not strictly a kind,
2901+
but its presence interacts with kinds:
2902+
the `Drop` trait provides a single method `drop`
2903+
that takes no parameters,
2904+
and is run when values of the type are dropped.
2905+
Such a method is called a "destructor",
2906+
and are always executed in "top-down" order:
2907+
a value is completely destroyed
2908+
before any of the values it owns run their destructors.
2909+
Only `Send` types can implement `Drop`.
29532910

29542911
_Default_
29552912
: Types with destructors, closure environments,
@@ -2962,30 +2919,15 @@ Kinds can be supplied as _bounds_ on type parameters, like traits,
29622919
in which case the parameter is constrained to types satisfying that kind.
29632920

29642921
By default, type parameters do not carry any assumed kind-bounds at all.
2922+
When instantiating a type parameter,
2923+
the kind bounds on the parameter are checked
2924+
to be the same or narrower than the kind
2925+
of the type that it is instantiated with.
29652926

2966-
Any operation that causes a value to be copied requires the type of that value to be of copyable kind,
2967-
so the `Copy` bound is frequently required on function type parameters.
2968-
For example, this is not a valid program:
2969-
2970-
~~~~{.xfail-test}
2971-
fn box<T>(x: T) -> @T { @x }
2972-
~~~~
2973-
2974-
Putting `x` into a managed box involves copying, and the `T` parameter has the default (non-copyable) kind.
2975-
To change that, a bound is declared:
2976-
2977-
~~~~
2978-
fn box<T: Copy>(x: T) -> @T { @x }
2979-
~~~~
2980-
2981-
Calling this second version of `box` on a noncopyable type is not
2982-
allowed. When instantiating a type parameter, the kind bounds on the
2983-
parameter are checked to be the same or narrower than the kind of the
2984-
type that it is instantiated with.
2985-
2986-
Sending operations are not part of the Rust language, but are
2987-
implemented in the library. Generic functions that send values bound
2988-
the kind of these values to sendable.
2927+
Sending operations are not part of the Rust language,
2928+
but are implemented in the library.
2929+
Generic functions that send values
2930+
bound the kind of these values to sendable.
29892931

29902932
# Memory and concurrency models
29912933

@@ -3093,9 +3035,7 @@ managed box value makes a shallow copy of the pointer (optionally incrementing
30933035
a reference count, if the managed box is implemented through
30943036
reference-counting).
30953037

3096-
Owned box values exist in 1:1 correspondence with their heap allocation;
3097-
copying an owned box value makes a deep copy of the heap allocation and
3098-
produces a pointer to the new allocation.
3038+
Owned box values exist in 1:1 correspondence with their heap allocation.
30993039

31003040
An example of constructing one managed box type and value, and one owned box
31013041
type and value:

0 commit comments

Comments
 (0)