Skip to content

Commit a6ad600

Browse files
committed
---
yaml --- r: 209840 b: refs/heads/try c: a33b5d3 h: refs/heads/master v: v3
1 parent 1e5c480 commit a6ad600

File tree

5 files changed

+159
-72
lines changed

5 files changed

+159
-72
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: 4c2274e1abea48c62a17e95e13fca02310ee1bab
5+
refs/heads/try: a33b5d3460343bdbe9e1c21d596397dc3e416bde
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/doc/reference.md

Lines changed: 94 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ sequence (`/**`), are interpreted as a special syntax for `doc`
149149
`#[doc="..."]` around the body of the comment (this includes the comment
150150
characters themselves, i.e. `/// Foo` turns into `#[doc="/// Foo"]`).
151151

152-
`//!` comments apply to the parent of the comment, rather than the item that
153-
follows. `//!` comments are usually used to display information on the crate
154-
index page.
152+
Line comments beginning with `//!` and block comments beginning with `/*!` are
153+
doc comments that apply to the parent of the comment, rather than the item
154+
that follows. That is, they are equivalent to writing `#![doc="..."]` around
155+
the body of the comment. `//!` comments are usually used to display
156+
information on the crate index page.
155157

156158
Non-doc comments are interpreted as a form of whitespace.
157159

@@ -196,10 +198,11 @@ grammar as double-quoted strings. Other tokens have exact rules given.
196198
| fn | for | if | impl | in |
197199
| let | loop | macro | match | mod |
198200
| move | mut | offsetof | override | priv |
199-
| pub | pure | ref | return | sizeof |
200-
| static | self | struct | super | true |
201-
| trait | type | typeof | unsafe | unsized |
202-
| use | virtual | where | while | yield |
201+
| proc | pub | pure | ref | return |
202+
| Self | self | sizeof | static | struct |
203+
| super | trait | true | type | typeof |
204+
| unsafe | unsized | use | virtual | where |
205+
| while | yield | | | |
203206

204207

205208
Each of these keywords has special meaning in its grammar, and all of them are
@@ -1099,40 +1102,31 @@ signature. Each type parameter must be explicitly declared, in an
10991102
angle-bracket-enclosed, comma-separated list following the function name.
11001103

11011104
```{.ignore}
1102-
fn iter<T>(seq: &[T], f: |T|) {
1103-
for elt in seq.iter() { f(elt); }
1105+
fn iter<T, F>(seq: &[T], f: F) where T: Copy, F: Fn(T) {
1106+
for elt in seq { f(*elt); }
11041107
}
1105-
fn map<T, U>(seq: &[T], f: |T| -> U) -> Vec<U> {
1108+
fn map<T, U, F>(seq: &[T], f: F) -> Vec<U> where T: Copy, U: Copy, F: Fn(T) -> U {
11061109
let mut acc = vec![];
1107-
for elt in seq.iter() { acc.push(f(elt)); }
1110+
for elt in seq { acc.push(f(*elt)); }
11081111
acc
11091112
}
11101113
```
11111114

11121115
Inside the function signature and body, the name of the type parameter can be
1113-
used as a type name.
1116+
used as a type name. [Trait](#traits) bounds can be specified for type parameters
1117+
to allow methods with that trait to be called on values of that type. This is
1118+
specified using the `where` syntax, as in the above example.
11141119

11151120
When a generic function is referenced, its type is instantiated based on the
11161121
context of the reference. For example, calling the `iter` function defined
11171122
above on `[1, 2]` will instantiate type parameter `T` with `i32`, and require
1118-
the closure parameter to have type `fn(i32)`.
1123+
the closure parameter to have type `Fn(i32)`.
11191124

11201125
The type parameters can also be explicitly supplied in a trailing
11211126
[path](#paths) component after the function name. This might be necessary if
11221127
there is not sufficient context to determine the type parameters. For example,
11231128
`mem::size_of::<u32>() == 4`.
11241129

1125-
Since a parameter type is opaque to the generic function, the set of operations
1126-
that can be performed on it is limited. Values of parameter type can only be
1127-
moved, not copied.
1128-
1129-
```
1130-
fn id<T>(x: T) -> T { x }
1131-
```
1132-
1133-
Similarly, [trait](#traits) bounds can be specified for type parameters to
1134-
allow methods with that trait to be called on values of that type.
1135-
11361130
#### Unsafety
11371131

11381132
Unsafe operations are those that potentially violate the memory-safety
@@ -1555,7 +1549,7 @@ fn draw_twice<T: Shape>(surface: Surface, sh: T) {
15551549
}
15561550
```
15571551

1558-
Traits also define an [object type](#object-types) with the same name as the
1552+
Traits also define an [trait object](#trait-objects) with the same name as the
15591553
trait. Values of this type are created by [casting](#type-cast-expressions)
15601554
pointer values (pointing to a type for which an implementation of the given
15611555
trait is in scope) to pointers to the trait name, used as a type.
@@ -2146,7 +2140,7 @@ The following configurations must be defined by the implementation:
21462140
`"unix"` or `"windows"`. The value of this configuration option is defined
21472141
as a configuration itself, like `unix` or `windows`.
21482142
* `target_os = "..."`. Operating system of the target, examples include
2149-
`"win32"`, `"macos"`, `"linux"`, `"android"`, `"freebsd"`, `"dragonfly"`,
2143+
`"windows"`, `"macos"`, `"ios"`, `"linux"`, `"android"`, `"freebsd"`, `"dragonfly"`,
21502144
`"bitrig"` or `"openbsd"`.
21512145
* `target_pointer_width = "..."`. Target pointer width in bits. This is set
21522146
to `"32"` for targets with 32-bit pointers, and likewise set to `"64"` for
@@ -2744,7 +2738,7 @@ A _method call_ consists of an expression followed by a single dot, an
27442738
identifier, and a parenthesized expression-list. Method calls are resolved to
27452739
methods on specific traits, either statically dispatching to a method if the
27462740
exact `self`-type of the left-hand-side is known, or dynamically dispatching if
2747-
the left-hand-side expression is an indirect [object type](#object-types).
2741+
the left-hand-side expression is an indirect [trait object](#trait-objects).
27482742

27492743
### Field expressions
27502744

@@ -2812,6 +2806,33 @@ _panicked state_.
28122806
(["a", "b"])[10]; // panics
28132807
```
28142808

2809+
### Range expressions
2810+
2811+
```{.ebnf .gram}
2812+
range_expr : expr ".." expr |
2813+
expr ".." |
2814+
".." expr |
2815+
".." ;
2816+
```
2817+
2818+
The `..` operator will construct an object of one of the `std::ops::Range` variants.
2819+
2820+
```
2821+
1..2; // std::ops::Range
2822+
3..; // std::ops::RangeFrom
2823+
..4; // std::ops::RangeTo
2824+
..; // std::ops::RangeFull
2825+
```
2826+
2827+
The following expressions are equivalent.
2828+
2829+
```
2830+
let x = std::ops::Range {start: 0, end: 10};
2831+
let y = 0..10;
2832+
2833+
assert_eq!(x,y);
2834+
```
2835+
28152836
### Unary operator expressions
28162837

28172838
Rust defines three unary operators. They are all written as prefix operators,
@@ -3078,28 +3099,6 @@ fn ten_times<F>(f: F) where F: Fn(i32) {
30783099
ten_times(|j| println!("hello, {}", j));
30793100
```
30803101

3081-
### While loops
3082-
3083-
```{.ebnf .gram}
3084-
while_expr : [ lifetime ':' ] "while" no_struct_literal_expr '{' block '}' ;
3085-
```
3086-
3087-
A `while` loop begins by evaluating the boolean loop conditional expression.
3088-
If the loop conditional expression evaluates to `true`, the loop body block
3089-
executes and control returns to the loop conditional expression. If the loop
3090-
conditional expression evaluates to `false`, the `while` expression completes.
3091-
3092-
An example:
3093-
3094-
```
3095-
let mut i = 0;
3096-
3097-
while i < 10 {
3098-
println!("hello");
3099-
i = i + 1;
3100-
}
3101-
```
3102-
31033102
### Infinite loops
31043103

31053104
A `loop` expression denotes an infinite loop.
@@ -3108,10 +3107,11 @@ A `loop` expression denotes an infinite loop.
31083107
loop_expr : [ lifetime ':' ] "loop" '{' block '}';
31093108
```
31103109

3111-
A `loop` expression may optionally have a _label_. If a label is present, then
3112-
labeled `break` and `continue` expressions nested within this loop may exit out
3113-
of this loop or return control to its head. See [Break
3114-
expressions](#break-expressions) and [Continue
3110+
A `loop` expression may optionally have a _label_. The label is written as
3111+
a lifetime preceding the loop expression, as in `'foo: loop{ }`. If a
3112+
label is present, then labeled `break` and `continue` expressions nested
3113+
within this loop may exit out of this loop or return control to its head.
3114+
See [Break expressions](#break-expressions) and [Continue
31153115
expressions](#continue-expressions).
31163116

31173117
### Break expressions
@@ -3123,7 +3123,7 @@ break_expr : "break" [ lifetime ];
31233123
A `break` expression has an optional _label_. If the label is absent, then
31243124
executing a `break` expression immediately terminates the innermost loop
31253125
enclosing it. It is only permitted in the body of a loop. If the label is
3126-
present, then `break foo` terminates the loop with label `foo`, which need not
3126+
present, then `break 'foo` terminates the loop with label `'foo`, which need not
31273127
be the innermost label enclosing the `break` expression, but must enclose it.
31283128

31293129
### Continue expressions
@@ -3137,12 +3137,39 @@ executing a `continue` expression immediately terminates the current iteration
31373137
of the innermost loop enclosing it, returning control to the loop *head*. In
31383138
the case of a `while` loop, the head is the conditional expression controlling
31393139
the loop. In the case of a `for` loop, the head is the call-expression
3140-
controlling the loop. If the label is present, then `continue foo` returns
3141-
control to the head of the loop with label `foo`, which need not be the
3140+
controlling the loop. If the label is present, then `continue 'foo` returns
3141+
control to the head of the loop with label `'foo`, which need not be the
31423142
innermost label enclosing the `break` expression, but must enclose it.
31433143

31443144
A `continue` expression is only permitted in the body of a loop.
31453145

3146+
### While loops
3147+
3148+
```{.ebnf .gram}
3149+
while_expr : [ lifetime ':' ] "while" no_struct_literal_expr '{' block '}' ;
3150+
```
3151+
3152+
A `while` loop begins by evaluating the boolean loop conditional expression.
3153+
If the loop conditional expression evaluates to `true`, the loop body block
3154+
executes and control returns to the loop conditional expression. If the loop
3155+
conditional expression evaluates to `false`, the `while` expression completes.
3156+
3157+
An example:
3158+
3159+
```
3160+
let mut i = 0;
3161+
3162+
while i < 10 {
3163+
println!("hello");
3164+
i = i + 1;
3165+
}
3166+
```
3167+
3168+
Like `loop` expressions, `while` loops can be controlled with `break` or
3169+
`continue`, and may optionally have a _label_. See [infinite
3170+
loops](#infinite-loops), [break expressions](#break-expressions), and
3171+
[continue expressions](#continue-expressions) for more information.
3172+
31463173
### For expressions
31473174

31483175
```{.ebnf .gram}
@@ -3177,6 +3204,11 @@ for i in 0..256 {
31773204
}
31783205
```
31793206

3207+
Like `loop` expressions, `for` loops can be controlled with `break` or
3208+
`continue`, and may optionally have a _label_. See [infinite
3209+
loops](#infinite-loops), [break expressions](#break-expressions), and
3210+
[continue expressions](#continue-expressions) for more information.
3211+
31803212
### If expressions
31813213

31823214
```{.ebnf .gram}
@@ -3649,23 +3681,23 @@ call_closure(closure_no_args, closure_args);
36493681

36503682
```
36513683

3652-
### Object types
3684+
### Trait objects
36533685

36543686
Every trait item (see [traits](#traits)) defines a type with the same name as
3655-
the trait. This type is called the _object type_ of the trait. Object types
3687+
the trait. This type is called the _trait object_ of the trait. Trait objects
36563688
permit "late binding" of methods, dispatched using _virtual method tables_
36573689
("vtables"). Whereas most calls to trait methods are "early bound" (statically
36583690
resolved) to specific implementations at compile time, a call to a method on an
3659-
object type is only resolved to a vtable entry at compile time. The actual
3691+
trait objects is only resolved to a vtable entry at compile time. The actual
36603692
implementation for each vtable entry can vary on an object-by-object basis.
36613693

36623694
Given a pointer-typed expression `E` of type `&T` or `Box<T>`, where `T`
36633695
implements trait `R`, casting `E` to the corresponding pointer type `&R` or
3664-
`Box<R>` results in a value of the _object type_ `R`. This result is
3696+
`Box<R>` results in a value of the _trait object_ `R`. This result is
36653697
represented as a pair of pointers: the vtable pointer for the `T`
36663698
implementation of `R`, and the pointer value of `E`.
36673699

3668-
An example of an object type:
3700+
An example of a trait object:
36693701

36703702
```
36713703
trait Printable {
@@ -3685,7 +3717,7 @@ fn main() {
36853717
}
36863718
```
36873719

3688-
In this example, the trait `Printable` occurs as an object type in both the
3720+
In this example, the trait `Printable` occurs as a trait object in both the
36893721
type signature of `print`, and the cast expression in `main`.
36903722

36913723
### Type parameters

branches/try/src/doc/trpl/macros.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ let x: Vec<u32> = {
5757
We can implement this shorthand, using a macro: [^actual]
5858

5959
[^actual]: The actual definition of `vec!` in libcollections differs from the
60-
one presented here, for reasons of efficiency and reusability. Some
61-
of these are mentioned in the [advanced macros chapter][].
60+
one presented here, for reasons of efficiency and reusability.
6261

6362
```rust
6463
macro_rules! vec {
@@ -106,7 +105,7 @@ These have [their own little grammar] within the language.
106105

107106
The matcher `$x:expr` will match any Rust expression, binding that syntax tree
108107
to the ‘metavariable’ `$x`. The identifier `expr` is a ‘fragment specifier’;
109-
the full possibilities are enumerated in the [advanced macros chapter][].
108+
the full possibilities are enumerated later in this chapter.
110109
Surrounding the matcher with `$(...),*` will match zero or more expressions,
111110
separated by commas.
112111

@@ -566,7 +565,7 @@ When this library is loaded with `#[macro_use] extern crate`, only `m2` will
566565
be imported.
567566

568567
The Rust Reference has a [listing of macro-related
569-
attributes](../reference.html#macro--and-plugin-related-attributes).
568+
attributes](../reference.html#macro-related-attributes).
570569

571570
# The variable `$crate`
572571

0 commit comments

Comments
 (0)