Skip to content

Commit de7d558

Browse files
committed
auto merge of #5553 : pnkfelix/rust/doc-fixes-for-0.6-incoming, r=sanxiyn
2 parents 74fb263 + e1dccf9 commit de7d558

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

doc/rust.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,10 @@ vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]
16711671
A [_vector_](#vector-types) _expression_ is written by enclosing zero or
16721672
more comma-separated expressions of uniform type in square brackets.
16731673

1674+
In the `[expr ',' ".." expr]` form, the expression after the `".."`
1675+
must be a constant expression that can be evaluated at compile time, such
1676+
as a [literal](#literals) or a [static item](#static-items).
1677+
16741678
~~~~
16751679
[1, 2, 3, 4];
16761680
["a", "b", "c", "d"];
@@ -2156,6 +2160,19 @@ do f |j| {
21562160
}
21572161
~~~~
21582162

2163+
In this example, both calls to the (binary) function `k` are equivalent:
2164+
2165+
~~~~
2166+
# fn k(x:int, f: &fn(int)) { }
2167+
# fn l(i: int) { }
2168+
2169+
k(3, |j| l(j));
2170+
2171+
do k(3) |j| {
2172+
l(j);
2173+
}
2174+
~~~~
2175+
21592176

21602177
### For expressions
21612178

@@ -2184,7 +2201,7 @@ and early boolean-valued returns from the `block` function,
21842201
such that the meaning of `break` and `loop` is preserved in a primitive loop
21852202
when rewritten as a `for` loop controlled by a higher order function.
21862203

2187-
An example a for loop:
2204+
An example of a for loop over the contents of a vector:
21882205

21892206
~~~~
21902207
# type foo = int;
@@ -2198,6 +2215,14 @@ for v.each |e| {
21982215
}
21992216
~~~~
22002217

2218+
An example of a for loop over a series of integers:
2219+
2220+
~~~~
2221+
# fn bar(b:uint) { }
2222+
for uint::range(0, 256) |i| {
2223+
bar(i);
2224+
}
2225+
~~~~
22012226

22022227
### If expressions
22032228

@@ -2474,6 +2499,7 @@ fail_unless!(b != "world");
24742499

24752500
The vector type constructor represents a homogeneous array of values of a given type.
24762501
A vector has a fixed size.
2502+
(Operations like `vec::push` operate solely on owned vectors.)
24772503
A vector type can be annotated with a _definite_ size,
24782504
written with a trailing asterisk and integer literal, such as `[int * 10]`.
24792505
Such a definite-sized vector type is a first-class type, since its size is known statically.
@@ -2484,6 +2510,10 @@ such as `&[T]`, `@[T]` or `~[T]`.
24842510
The kind of a vector type depends on the kind of its element type,
24852511
as with other simple structural types.
24862512

2513+
Expressions producing vectors of definite size cannot be evaluated in a
2514+
context expecting a vector of indefinite size; one must copy the
2515+
definite-sized vector contents into a distinct vector of indefinite size.
2516+
24872517
An example of a vector type and its use:
24882518

24892519
~~~~

src/libcore/iter.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ pub fn build_sized_opt<A,B: Buildable<A>>(size: Option<uint>,
284284

285285
// Functions that combine iteration and building
286286

287-
/// Applies a function to each element of an iterable and returns the results.
287+
/// Applies a function to each element of an iterable and returns the results
288+
/// in a sequence built via `BU`. See also `map_to_vec`.
288289
#[inline(always)]
289290
pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
290291
-> BU {

src/libcore/vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ pub fn with_capacity<T>(capacity: uint) -> ~[T] {
172172
/**
173173
* Builds a vector by calling a provided function with an argument
174174
* function that pushes an element to the back of a vector.
175-
* This version takes an initial size for the vector.
175+
* This version takes an initial capacity for the vector.
176176
*
177177
* # Arguments
178178
*
179179
* * size - An initial size of the vector to reserve
180-
* * builder - A function that will construct the vector. It recieves
180+
* * builder - A function that will construct the vector. It receives
181181
* as an argument a function that will push an element
182182
* onto the vector being constructed.
183183
*/
@@ -194,7 +194,7 @@ pub fn build_sized<A>(size: uint, builder: &fn(push: &fn(v: A))) -> ~[A] {
194194
*
195195
* # Arguments
196196
*
197-
* * builder - A function that will construct the vector. It recieves
197+
* * builder - A function that will construct the vector. It receives
198198
* as an argument a function that will push an element
199199
* onto the vector being constructed.
200200
*/

src/librustc/README.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ lib/ - bindings to LLVM
3232
The files concerned purely with syntax -- that is, the AST, parser,
3333
pretty-printer, lexer, macro expander, and utilities for traversing
3434
ASTs -- are in a separate crate called "syntax", whose files are in
35-
./../libsyntax if the parent directory of front/, middle/, back/, and
36-
so on is . .
35+
./../libsyntax, where . is the current directory (that is, the parent
36+
directory of front/, middle/, back/, and so on).
3737

3838
The entry-point for the compiler is main() in driver/rustc.rs, and
3939
this file sequences the various parts together.

0 commit comments

Comments
 (0)