Skip to content

Commit 9fa2ae3

Browse files
committed
---
yaml --- r: 216543 b: refs/heads/stable c: 45b9a34 h: refs/heads/master i: 216541: c628197 216539: ce0a04e 216535: 3d8b401 216527: 14d066d 216511: c39a3af v: v3
1 parent d3d58a5 commit 9fa2ae3

File tree

117 files changed

+1592
-880
lines changed

Some content is hidden

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

117 files changed

+1592
-880
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: f86da3d6dee0bfde56c27a33bfe33d9e3c0b2c83
32+
refs/heads/stable: 45b9a34a7b0ad3ccf85cd8f5a92cfe2e01861e69
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/reference.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,8 +1557,7 @@ warnings are generated, or otherwise "you used a private item of another module
15571557
and weren't allowed to."
15581558

15591559
By default, everything in Rust is *private*, with one exception. Enum variants
1560-
in a `pub` enum are also public by default. You are allowed to alter this
1561-
default visibility with the `priv` keyword. When an item is declared as `pub`,
1560+
in a `pub` enum are also public by default. When an item is declared as `pub`,
15621561
it can be thought of as being accessible to the outside world. For example:
15631562

15641563
```
@@ -2426,11 +2425,18 @@ Tuples are written by enclosing zero or more comma-separated expressions in
24262425
parentheses. They are used to create [tuple-typed](#tuple-types) values.
24272426

24282427
```{.tuple}
2429-
(0,);
24302428
(0.0, 4.5);
24312429
("a", 4usize, true);
24322430
```
24332431

2432+
You can disambiguate a single-element tuple from a value in parentheses with a
2433+
comma:
2434+
2435+
```
2436+
(0,); // single-element tuple
2437+
(0); // zero in parentheses
2438+
```
2439+
24342440
### Unit expressions
24352441

24362442
The expression `()` denotes the _unit value_, the only value of the type with

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,5 @@ fn main() {
190190
We created an inner scope with an additional set of curly braces. `y` will go out of
191191
scope before we call `push()`, and so we’re all good.
192192

193-
This concept of ownership isn’t just good for preventing danging pointers, but an
193+
This concept of ownership isn’t just good for preventing dangling pointers, but an
194194
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/attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ Rust attributes are used for a number of different things. There is a full list
6767
of attributes [in the reference][reference]. Currently, you are not allowed to
6868
create your own attributes, the Rust compiler defines them.
6969

70-
[reference]: reference.html#attributes
70+
[reference]: ../reference.html#attributes

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/const-and-static.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@ this reason.
1919
# `static`
2020

2121
Rust provides a ‘global variable’ sort of facility in static items. They’re
22-
similar to [constants][const], but static items aren’t inlined upon use. This
23-
means that there is only one instance for each value, and it’s at a fixed
24-
location in memory.
22+
similar to constants, but static items aren’t inlined upon use. This means that
23+
there is only one instance for each value, and it’s at a fixed location in
24+
memory.
2525

2626
Here’s an example:
2727

2828
```rust
2929
static N: i32 = 5;
3030
```
3131

32-
[const]: const.html
33-
3432
Unlike [`let`][let] bindings, you must annotate the type of a `static`.
3533

3634
[let]: variable-bindings.html

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,26 +235,15 @@ Ranges are one of two basic iterators that you'll see. The other is `iter()`.
235235
in turn:
236236

237237
```rust
238-
let nums = [1, 2, 3];
238+
let nums = vec![1, 2, 3];
239239

240240
for num in nums.iter() {
241241
println!("{}", num);
242242
}
243243
```
244244

245245
These two basic iterators should serve you well. There are some more
246-
advanced iterators, including ones that are infinite. Like using range syntax
247-
and `step_by`:
248-
249-
```rust
250-
# #![feature(step_by)]
251-
(1..).step_by(5);
252-
```
253-
254-
This iterator counts up from one, adding five each time. It will give
255-
you a new integer every time, forever (well, technically, until it reaches the
256-
maximum number representable by an `i32`). But since iterators are lazy,
257-
that's okay! You probably don't want to use `collect()` on it, though...
246+
advanced iterators, including ones that are infinite.
258247

259248
That's enough about iterators. Iterator adapters are the last concept
260249
we need to talk about with regards to iterators. Let's get to it!

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ If not, there are a number of places where you can get help. The easiest is
9393
[the #rust IRC channel on irc.mozilla.org][irc], which you can access through
9494
[Mibbit][mibbit]. Click that link, and you'll be chatting with other Rustaceans
9595
(a silly nickname we call ourselves), and we can help you out. Other great
96-
resources include [the user’s forum][users], and [Stack Overflow][stack
97-
overflow].
96+
resources include [the user’s forum][users], and [Stack Overflow][stack overflow].
9897

9998
[irc]: irc://irc.mozilla.org/#rust
10099
[mibbit]: http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust

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

branches/stable/src/doc/trpl/primitive-types.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ or “breaks up” the tuple, and assigns the bits to three bindings.
248248

249249
This pattern is very powerful, and we’ll see it repeated more later.
250250

251+
You can disambiguate a single-element tuple from a value in parentheses with a
252+
comma:
253+
254+
```
255+
(0,); // single-element tuple
256+
(0); // zero in parentheses
257+
```
258+
251259
## Tuple Indexing
252260

253261
You can also access fields of a tuple with indexing syntax:

branches/stable/src/doc/trpl/raw-pointers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Raw pointers are useful for FFI: Rust’s `*const T` and `*mut T` are similar to
8080
C’s `const T*` and `T*`, respectfully. For more about this use, consult the
8181
[FFI chapter][ffi].
8282

83-
[ffi]: ffi.md
83+
[ffi]: ffi.html
8484

8585
# References and raw pointers
8686

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Rust has a feature called ‘`static mut`’ which allows for mutable global sta
101101
Doing so can cause a data race, and as such is inherently not safe. For more
102102
details, see the [static][static] section of the book.
103103

104-
[static]: static.html
104+
[static]: const-and-static.html#static
105105

106106
## Dereference a raw pointer
107107

branches/stable/src/doc/trpl/unsized-types.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ impl Foo for &str {
3838
```
3939

4040
Meaning, this implementation would only work for [references][ref], and not
41-
other types of pointers. With this `impl`, all pointers, including (at some
42-
point, there are some bugs to fix first) user-defined custom smart pointers,
43-
can use this `impl`.
41+
other types of pointers. With the `impl for str`, all pointers, including (at
42+
some point, there are some bugs to fix first) user-defined custom smart
43+
pointers, can use this `impl`.
44+
45+
[ref]: references-and-borrowing.html
4446

4547
# ?Sized
4648

branches/stable/src/liballoc/boxed.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ impl<T: ?Sized + Hash> Hash for Box<T> {
240240
impl Box<Any> {
241241
#[inline]
242242
#[stable(feature = "rust1", since = "1.0.0")]
243+
/// Attempt to downcast the box to a concrete type.
243244
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
244245
if self.is::<T>() {
245246
unsafe {
@@ -257,11 +258,15 @@ impl Box<Any> {
257258
}
258259
}
259260

260-
impl Box<Any+Send> {
261+
impl Box<Any + Send> {
261262
#[inline]
262263
#[stable(feature = "rust1", since = "1.0.0")]
263-
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
264-
<Box<Any>>::downcast(self)
264+
/// Attempt to downcast the box to a concrete type.
265+
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any + Send>> {
266+
<Box<Any>>::downcast(self).map_err(|s| unsafe {
267+
// reapply the Send marker
268+
mem::transmute::<Box<Any>, Box<Any + Send>>(s)
269+
})
265270
}
266271
}
267272

branches/stable/src/libcollections/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@
398398
//! longer than this width, then it is truncated down to this many characters and only those are
399399
//! emitted.
400400
//!
401-
//! For integral types, this has no meaning currently.
401+
//! For integral types, this is ignored.
402402
//!
403403
//! For floating-point types, this indicates how many digits after the decimal point should be
404404
//! printed.

0 commit comments

Comments
 (0)