Skip to content

Commit 192ec0a

Browse files
committed
---
yaml --- r: 216607 b: refs/heads/stable c: 58b83e7 h: refs/heads/master i: 216605: 2bb71df 216603: 7a586d6 216599: 10de3dc 216591: 7dac91b 216575: 0d20320 v: v3
1 parent a231813 commit 192ec0a

File tree

104 files changed

+1557
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1557
-721
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ refs/heads/tmp: 378a370ff2057afeb1eae86eb6e78c476866a4a6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: a5286998df566e736b32f6795bfc3803bdaf453d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 700cff5262e416372d048d2559af61f0492a4e48
32+
refs/heads/stable: 58b83e7e740108611ad1e8286ee6b44ea5cbbb0f
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375

branches/stable/src/compiletest/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
269269
run_ignored: config.run_ignored,
270270
logfile: config.logfile.clone(),
271271
run_tests: true,
272-
run_benchmarks: true,
272+
bench_benchmarks: true,
273273
nocapture: env::var("RUST_TEST_NOCAPTURE").is_ok(),
274274
color: test::AutoColor,
275275
}

branches/stable/src/doc/complement-lang-faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ This does mean that indexed access to a Unicode codepoint inside a `str` value i
109109
* Most "character oriented" operations on text only work under very restricted language assumptions sets such as "ASCII-range codepoints only". Outside ASCII-range, you tend to have to use a complex (non-constant-time) algorithm for determining linguistic-unit (glyph, word, paragraph) boundaries anyways. We recommend using an "honest" linguistically-aware, Unicode-approved algorithm.
110110
* The `char` type is UCS4. If you honestly need to do a codepoint-at-a-time algorithm, it's trivial to write a `type wstr = [char]`, and unpack a `str` into it in a single pass, then work with the `wstr`. In other words: the fact that the language is not "decoding to UCS4 by default" shouldn't stop you from decoding (or re-encoding any other way) if you need to work with that encoding.
111111

112-
## Why are strings, vectors etc. built-in types rather than (say) special kinds of trait/impl?
112+
## Why are `str`s, slices, arrays etc. built-in types rather than (say) special kinds of trait/impl?
113113

114114
In each case there is one or more operator, literal constructor, overloaded use or integration with a built-in control structure that makes us think it would be awkward to phrase the type in terms of more-general type constructors. Same as, say, with numbers! But this is partly an aesthetic call, and we'd be willing to look at a worked-out proposal for eliminating or rephrasing these special cases.
115115

branches/stable/src/doc/reference.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,21 +2044,21 @@ A complete list of the built-in language items will be added in the future.
20442044

20452045
### Inline attributes
20462046

2047-
The inline attribute is used to suggest to the compiler to perform an inline
2048-
expansion and place a copy of the function or static in the caller rather than
2049-
generating code to call the function or access the static where it is defined.
2047+
The inline attribute suggests that the compiler should place a copy of
2048+
the function or static in the caller, rather than generating code to
2049+
call the function or access the static where it is defined.
20502050

20512051
The compiler automatically inlines functions based on internal heuristics.
2052-
Incorrectly inlining functions can actually making the program slower, so it
2052+
Incorrectly inlining functions can actually make the program slower, so it
20532053
should be used with care.
20542054

20552055
Immutable statics are always considered inlineable unless marked with
20562056
`#[inline(never)]`. It is undefined whether two different inlineable statics
20572057
have the same memory address. In other words, the compiler is free to collapse
20582058
duplicate inlineable statics together.
20592059

2060-
`#[inline]` and `#[inline(always)]` always causes the function to be serialized
2061-
into crate metadata to allow cross-crate inlining.
2060+
`#[inline]` and `#[inline(always)]` always cause the function to be serialized
2061+
into the crate metadata to allow cross-crate inlining.
20622062

20632063
There are three different types of inline attributes:
20642064

branches/stable/src/doc/trpl/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ want to dive in with a project, or ‘Syntax and Semantics’ if you prefer to
4040
start small, and learn a single concept thoroughly before moving onto the next.
4141
Copious cross-linking connects these parts together.
4242

43+
### Contributing
44+
45+
The source files from which this book is generated can be found on Github:
46+
[github.com/rust-lang/rust/tree/master/src/doc/trpl](https://github.com/rust-lang/rust/tree/master/src/doc/trpl)
47+
4348
## A brief introduction to Rust
4449

4550
Is Rust a language you might be interested in? Let’s examine a few small code
@@ -190,5 +195,5 @@ fn main() {
190195
We created an inner scope with an additional set of curly braces. `y` will go out of
191196
scope before we call `push()`, and so we’re all good.
192197

193-
This concept of ownership isn’t just good for preventing danging pointers, but an
198+
This concept of ownership isn’t just good for preventing dangling pointers, but an
194199
entire set of related problems, like iterator invalidation, concurrency, and more.

branches/stable/src/doc/trpl/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@
6464
* [Benchmark Tests](benchmark-tests.md)
6565
* [Box Syntax and Patterns](box-syntax-and-patterns.md)
6666
* [Slice Patterns](slice-patterns.md)
67+
* [Associated Constants](associated-constants.md)
6768
* [Glossary](glossary.md)
6869
* [Academic Research](academic-research.md)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
% Associated Constants
2+
3+
With the `associated_consts` feature, you can define constants like this:
4+
5+
```rust
6+
#![feature(associated_consts)]
7+
8+
trait Foo {
9+
const ID: i32;
10+
}
11+
12+
impl Foo for i32 {
13+
const ID: i32 = 1;
14+
}
15+
16+
fn main() {
17+
assert_eq!(1, i32::ID);
18+
}
19+
```
20+
21+
Any implementor of `Foo` will have to define `ID`. Without the definition:
22+
23+
```rust,ignore
24+
#![feature(associated_consts)]
25+
26+
trait Foo {
27+
const ID: i32;
28+
}
29+
30+
impl Foo for i32 {
31+
}
32+
```
33+
34+
gives
35+
36+
```text
37+
error: not all trait items implemented, missing: `ID` [E0046]
38+
impl Foo for i32 {
39+
}
40+
```
41+
42+
A default value can be implemented as well:
43+
44+
```rust
45+
#![feature(associated_consts)]
46+
47+
trait Foo {
48+
const ID: i32 = 1;
49+
}
50+
51+
impl Foo for i32 {
52+
}
53+
54+
impl Foo for i64 {
55+
const ID: i32 = 5;
56+
}
57+
58+
fn main() {
59+
assert_eq!(1, i32::ID);
60+
assert_eq!(5, i64::ID);
61+
}
62+
```
63+
64+
As you can see, when implementing `Foo`, you can leave it unimplemented, as
65+
with `i32`. It will then use the default value. But, as in `i64`, we can also
66+
add our own definition.
67+
68+
Associated constants don’t have to be associated with a trait. An `impl` block
69+
for a `struct` works fine too:
70+
71+
```rust
72+
#![feature(associated_consts)]
73+
74+
struct Foo;
75+
76+
impl Foo {
77+
pub const FOO: u32 = 3;
78+
}
79+
```

branches/stable/src/doc/trpl/concurrency.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ use std::thread;
116116
fn main() {
117117
let mut data = vec![1u32, 2, 3];
118118
119-
for i in 0..2 {
119+
for i in 0..3 {
120120
thread::spawn(move || {
121121
data[i] += 1;
122122
});
@@ -154,7 +154,7 @@ use std::sync::Mutex;
154154
fn main() {
155155
let mut data = Mutex::new(vec![1u32, 2, 3]);
156156
157-
for i in 0..2 {
157+
for i in 0..3 {
158158
let data = data.lock().unwrap();
159159
thread::spawn(move || {
160160
data[i] += 1;
@@ -196,7 +196,7 @@ use std::thread;
196196
fn main() {
197197
let data = Arc::new(Mutex::new(vec![1u32, 2, 3]));
198198
199-
for i in 0..2 {
199+
for i in 0..3 {
200200
let data = data.clone();
201201
thread::spawn(move || {
202202
let mut data = data.lock().unwrap();
@@ -217,7 +217,7 @@ thread more closely:
217217
# use std::thread;
218218
# fn main() {
219219
# let data = Arc::new(Mutex::new(vec![1u32, 2, 3]));
220-
# for i in 0..2 {
220+
# for i in 0..3 {
221221
# let data = data.clone();
222222
thread::spawn(move || {
223223
let mut data = data.lock().unwrap();

branches/stable/src/doc/trpl/error-handling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ struct Info {
252252
}
253253

254254
fn write_info(info: &Info) -> io::Result<()> {
255-
let mut file = File::open("my_best_friends.txt").unwrap();
255+
let mut file = File::create("my_best_friends.txt").unwrap();
256256

257257
if let Err(e) = writeln!(&mut file, "name: {}", info.name) {
258258
return Err(e)
@@ -282,7 +282,7 @@ struct Info {
282282
}
283283

284284
fn write_info(info: &Info) -> io::Result<()> {
285-
let mut file = try!(File::open("my_best_friends.txt"));
285+
let mut file = try!(File::create("my_best_friends.txt"));
286286

287287
try!(writeln!(&mut file, "name: {}", info.name));
288288
try!(writeln!(&mut file, "age: {}", info.age));

branches/stable/src/doc/trpl/hello-cargo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ projects. Cargo is currently in a pre-1.0 state, and so it is still a work in
55
progress. However, it is already good enough to use for many Rust projects, and
66
so it is assumed that Rust projects will use Cargo from the beginning.
77

8-
[cratesio]: https://doc.crates.io
8+
[cratesio]: http://doc.crates.io
99

1010
Cargo manages three things: building your code, downloading the dependencies
1111
your code needs, and building those dependencies. At first, your

branches/stable/src/doc/trpl/installing-rust.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ or a Mac, all you need to do is this (note that you don't need to type in the
66
`$`s, they just indicate the start of each command):
77

88
```bash
9-
$ curl -sf -L https://static.rust-lang.org/rustup.sh | sudo sh
9+
$ curl -sf -L https://static.rust-lang.org/rustup.sh | sh
1010
```
1111

1212
If you're concerned about the [potential insecurity][insecurity] of using `curl
13-
| sudo sh`, please keep reading and see our disclaimer below. And feel free to
13+
| sh`, please keep reading and see our disclaimer below. And feel free to
1414
use a two-step version of the installation and examine our installation script:
1515

1616
```bash
1717
$ curl -f -L https://static.rust-lang.org/rustup.sh -O
18-
$ sudo sh rustup.sh
18+
$ sh rustup.sh
1919
```
2020

2121
[insecurity]: http://curlpipesh.tumblr.com
@@ -40,13 +40,11 @@ If you used the Windows installer, just re-run the `.msi` and it will give you
4040
an uninstall option.
4141

4242
Some people, and somewhat rightfully so, get very upset when we tell you to
43-
`curl | sudo sh`. Basically, when you do this, you are trusting that the good
43+
`curl | sh`. Basically, when you do this, you are trusting that the good
4444
people who maintain Rust aren't going to hack your computer and do bad things.
4545
That's a good instinct! If you're one of those people, please check out the
4646
documentation on [building Rust from Source][from source], or [the official
47-
binary downloads][install page]. And we promise that this method will not be
48-
the way to install Rust forever: it's just the easiest way to keep people
49-
updated while Rust is in its alpha state.
47+
binary downloads][install page].
5048

5149
[from source]: https://github.com/rust-lang/rust#building-from-source
5250
[install page]: http://www.rust-lang.org/install.html

branches/stable/src/doc/trpl/nightly-rust.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ process, see ‘[Stability as a deliverable][stability]’.
99
To install nightly Rust, you can use `rustup.sh`:
1010

1111
```bash
12-
$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --channel=nightly
12+
$ curl -s https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly
1313
```
1414

1515
If you're concerned about the [potential insecurity][insecurity] of using `curl
16-
| sudo sh`, please keep reading and see our disclaimer below. And feel free to
16+
| sh`, please keep reading and see our disclaimer below. And feel free to
1717
use a two-step version of the installation and examine our installation script:
1818

1919
```bash
2020
$ curl -f -L https://static.rust-lang.org/rustup.sh -O
21-
$ sudo sh rustup.sh --channel=nightly
21+
$ sh rustup.sh --channel=nightly
2222
```
2323

2424
[insecurity]: http://curlpipesh.tumblr.com
@@ -43,13 +43,11 @@ If you used the Windows installer, just re-run the `.msi` and it will give you
4343
an uninstall option.
4444

4545
Some people, and somewhat rightfully so, get very upset when we tell you to
46-
`curl | sudo sh`. Basically, when you do this, you are trusting that the good
46+
`curl | sh`. Basically, when you do this, you are trusting that the good
4747
people who maintain Rust aren't going to hack your computer and do bad things.
4848
That's a good instinct! If you're one of those people, please check out the
4949
documentation on [building Rust from Source][from source], or [the official
50-
binary downloads][install page]. And we promise that this method will not be
51-
the way to install Rust forever: it's just the easiest way to keep people
52-
updated while Rust is in its alpha state.
50+
binary downloads][install page].
5351

5452
[from source]: https://github.com/rust-lang/rust#building-from-source
5553
[install page]: http://www.rust-lang.org/install.html

branches/stable/src/doc/trpl/patterns.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ This prints `something else`
7070

7171
# Bindings
7272

73-
If you’re matching multiple things, via a `|` or a `...`, you can bind
74-
the value to a name with `@`:
73+
You can bind values to names with `@`:
7574

7675
```rust
7776
let x = 1;
@@ -82,7 +81,36 @@ match x {
8281
}
8382
```
8483

85-
This prints `got a range element 1`.
84+
This prints `got a range element 1`. This is useful when you want to
85+
do a complicated match of part of a data structure:
86+
87+
```rust
88+
#[derive(Debug)]
89+
struct Person {
90+
name: Option<String>,
91+
}
92+
93+
let name = "Steve".to_string();
94+
let mut x: Option<Person> = Some(Person { name: Some(name) });
95+
match x {
96+
Some(Person { name: ref a @ Some(_), .. }) => println!("{:?}", a),
97+
_ => {}
98+
}
99+
```
100+
101+
This prints `Some("Steve")`: We’ve bound the inner `name` to `a`.
102+
103+
If you use `@` with `|`, you need to make sure the name is bound in each part
104+
of the pattern:
105+
106+
```rust
107+
let x = 5;
108+
109+
match x {
110+
e @ 1 ... 5 | e @ 8 ... 10 => println!("got a range element {}", e),
111+
_ => println!("anything"),
112+
}
113+
```
86114

87115
# Ignoring variants
88116

0 commit comments

Comments
 (0)