Skip to content

Commit 0486e12

Browse files
committed
Auto merge of #31148 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #30997, #31019, #31031, #31035, #31045, #31050, #31054, #31055, #31061, #31088, #31090, #31111, #31113, #31128, #31130, #31136, #31145, #31146 - Failed merges: #30932
2 parents b78b9ae + feb2673 commit 0486e12

File tree

19 files changed

+161
-37
lines changed

19 files changed

+161
-37
lines changed

src/doc/book/bibliography.md

+1
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ Language](http://www.cs.indiana.edu/~eholk/papers/hips2013.pdf). Early GPU work
8080
Rust](http://munksgaard.me/papers/laumann-munksgaard-larsen.pdf). Philip
8181
Munksgaard's master's thesis. Research for Servo.
8282
* [Ownership is Theft: Experiences Building an Embedded OS in Rust - Amit Levy, et. al.](http://amitlevy.com/papers/tock-plos2015.pdf)
83+
* [You can't spell trust without Rust](https://raw.githubusercontent.com/Gankro/thesis/master/thesis.pdf). Alexis Beingessner's master's thesis.

src/doc/book/getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ If we're on Linux or a Mac, all we need to do is open a terminal and type this:
111111
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh
112112
```
113113

114-
This will download a script, and stat the installation. If it all goes well,
114+
This will download a script, and start the installation. If it all goes well,
115115
you’ll see this appear:
116116

117117
```text

src/doc/book/guessing-game.md

+1
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ let guess: u32 = match guess.trim().parse() {
908908
```
909909
910910
This is how you generally move from ‘crash on error’ to ‘actually handle the
911+
error’, by switching from `expect()` to a `match` statement. The `Result`
911912
returned by `parse()` is an `enum` like `Ordering`, but in this case, each
912913
variant has some data associated with it: `Ok` is a success, and `Err` is a
913914
failure. Each contains more information: the successfully parsed integer, or an

src/doc/book/no-stdlib.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ The compiler currently makes a few assumptions about symbols which are available
7777
in the executable to call. Normally these functions are provided by the standard
7878
library, but without it you must define your own.
7979

80-
The first of these two functions, `eh_personality`, is used by the
81-
failure mechanisms of the compiler. This is often mapped to GCC's
82-
personality function (see the
83-
[libstd implementation](../std/rt/unwind/index.html) for more
84-
information), but crates which do not trigger a panic can be assured
85-
that this function is never called. The second function, `panic_fmt`, is
86-
also used by the failure mechanisms of the compiler.
80+
The first of these two functions, `eh_personality`, is used by the failure
81+
mechanisms of the compiler. This is often mapped to GCC's personality function
82+
(see the [libstd implementation][unwind] for more information), but crates
83+
which do not trigger a panic can be assured that this function is never
84+
called. The second function, `panic_fmt`, is also used by the failure
85+
mechanisms of the compiler.
86+
87+
[unwind]: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/unwind/gcc.rs

src/doc/book/traits.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,22 @@ This will compile without error.
277277
This means that even if someone does something bad like add methods to `i32`,
278278
it won’t affect you, unless you `use` that trait.
279279

280-
There’s one more restriction on implementing traits: either the trait, or the
281-
type you’re writing the `impl` for, must be defined by you. So, we could
282-
implement the `HasArea` type for `i32`, because `HasArea` is in our code. But
283-
if we tried to implement `ToString`, a trait provided by Rust, for `i32`, we could
284-
not, because neither the trait nor the type are in our code.
280+
There’s one more restriction on implementing traits: either the trait
281+
or the type you’re implementing it for must be defined by you. Or more
282+
precisely, one of them must be defined in the same crate as the `impl`
283+
you're writing. For more on Rust's module and package system, see the
284+
chapter on [crates and modules][cm].
285+
286+
So, we could implement the `HasArea` type for `i32`, because we defined
287+
`HasArea` in our code. But if we tried to implement `ToString`, a trait
288+
provided by Rust, for `i32`, we could not, because neither the trait nor
289+
the type are defined in our crate.
285290

286291
One last thing about traits: generic functions with a trait bound use
287292
‘monomorphization’ (mono: one, morph: form), so they are statically dispatched.
288293
What’s that mean? Check out the chapter on [trait objects][to] for more details.
289294

295+
[cm]: crates-and-modules.html
290296
[to]: trait-objects.html
291297

292298
# Multiple trait bounds

src/doc/version_info.html.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="versioninfo">
2-
<img src="https://www.rust-lang.org/logos/rust-logo-32x32-blk.png" width="32" height="32" alt><br>
2+
<img src="https://www.rust-lang.org/logos/rust-logo-32x32-blk.png" width="32" height="32" alt="Rust logo"><br>
33
<span class="white-sticker"><a href="https://www.rust-lang.org">Rust</a> VERSION</span><br>
44
<a href="https://github.com/rust-lang/rust/commit/STAMP"
55
class="hash white-sticker">SHORT_HASH</a>

src/libcollections/btree/map.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1194,17 +1194,17 @@ unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
11941194
}
11951195

11961196
impl<K, V> BTreeMap<K, V> {
1197-
/// Gets an iterator over the entries of the map.
1197+
/// Gets an iterator over the entries of the map, sorted by key.
11981198
///
11991199
/// # Examples
12001200
///
12011201
/// ```
12021202
/// use std::collections::BTreeMap;
12031203
///
12041204
/// let mut map = BTreeMap::new();
1205-
/// map.insert(1, "a");
1206-
/// map.insert(2, "b");
12071205
/// map.insert(3, "c");
1206+
/// map.insert(2, "b");
1207+
/// map.insert(1, "a");
12081208
///
12091209
/// for (key, value) in map.iter() {
12101210
/// println!("{}: {}", key, value);
@@ -1224,7 +1224,7 @@ impl<K, V> BTreeMap<K, V> {
12241224
}
12251225
}
12261226

1227-
/// Gets a mutable iterator over the entries of the map.
1227+
/// Gets a mutable iterator over the entries of the map, sorted by key.
12281228
///
12291229
/// # Examples
12301230
///
@@ -1257,16 +1257,16 @@ impl<K, V> BTreeMap<K, V> {
12571257
}
12581258
}
12591259

1260-
/// Gets an iterator over the keys of the map.
1260+
/// Gets an iterator over the keys of the map, in sorted order.
12611261
///
12621262
/// # Examples
12631263
///
12641264
/// ```
12651265
/// use std::collections::BTreeMap;
12661266
///
12671267
/// let mut a = BTreeMap::new();
1268-
/// a.insert(1, "a");
12691268
/// a.insert(2, "b");
1269+
/// a.insert(1, "a");
12701270
///
12711271
/// let keys: Vec<_> = a.keys().cloned().collect();
12721272
/// assert_eq!(keys, [1, 2]);
@@ -1276,19 +1276,19 @@ impl<K, V> BTreeMap<K, V> {
12761276
Keys { inner: self.iter() }
12771277
}
12781278

1279-
/// Gets an iterator over the values of the map.
1279+
/// Gets an iterator over the values of the map, in order by key.
12801280
///
12811281
/// # Examples
12821282
///
12831283
/// ```
12841284
/// use std::collections::BTreeMap;
12851285
///
12861286
/// let mut a = BTreeMap::new();
1287-
/// a.insert(1, "a");
1288-
/// a.insert(2, "b");
1287+
/// a.insert(1, "hello");
1288+
/// a.insert(2, "goodbye");
12891289
///
12901290
/// let values: Vec<&str> = a.values().cloned().collect();
1291-
/// assert_eq!(values, ["a", "b"]);
1291+
/// assert_eq!(values, ["hello", "goodbye"]);
12921292
/// ```
12931293
#[stable(feature = "rust1", since = "1.0.0")]
12941294
pub fn values<'a>(&'a self) -> Values<'a, K, V> {

src/librustc_borrowck/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn main() {
124124
let mut x = Rc::new(RefCell::new(MyStruct{ s: 5u32 }));
125125
let y = x.clone();
126126
x.borrow_mut().s = 6;
127-
println!("{}", x.borrow.s);
127+
println!("{}", x.borrow().s);
128128
}
129129
```
130130

src/librustc_resolve/diagnostics.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,41 @@ https://doc.rust-lang.org/reference.html#statements
207207
E0317: r##"
208208
User-defined types or type parameters cannot shadow the primitive types.
209209
This error indicates you tried to define a type, struct or enum with the same
210-
name as an existing primitive type.
210+
name as an existing primitive type:
211+
212+
```
213+
struct u8 {
214+
// ...
215+
}
216+
```
217+
218+
To fix this, simply name it something else.
219+
220+
Such an error may also occur if you define a type parameter which shadows a
221+
primitive type. An example would be something like:
222+
223+
```
224+
impl<u8> MyTrait for Option<u8> {
225+
// ...
226+
}
227+
```
228+
229+
In such a case, if you meant for `u8` to be a generic type parameter (i.e. any
230+
type can be used in its place), use something like `T` instead:
231+
232+
```
233+
impl<T> MyTrait for Option<T> {
234+
// ...
235+
}
236+
```
237+
238+
On the other hand, if you wished to refer to the specific type `u8`, remove it
239+
from the type parameter list:
240+
241+
```
242+
impl MyTrait for Option<u8> {
243+
// ...
244+
}
211245
212246
See the Types section of the reference for more information about the primitive
213247
types:

src/librustc_typeck/diagnostics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,8 @@ struct MyType<T>(T);
22692269
impl<T> ForeignTrait for MyType<T> { ... } // Ok
22702270
```
22712271
2272+
Please note that a type alias is not sufficient.
2273+
22722274
For another example of an error, suppose there's another trait defined in `foo`
22732275
named `ForeignTrait2` that takes two type parameters. Then this `impl` results
22742276
in the same rule violation:

src/librustdoc/html/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ r##"<!DOCTYPE html>
148148
"".to_string()
149149
} else {
150150
format!("<a href='{}{}/index.html'>\
151-
<img src='{}' alt='' width='100'></a>",
151+
<img src='{}' alt='logo' width='100'></a>",
152152
page.root_path, layout.krate,
153153
layout.logo)
154154
},

src/librustdoc/html/static/rustdoc.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ a {
383383
}
384384

385385
.content span.enum, .content a.enum, .block a.current.enum { color: #5e9766; }
386-
.content span.struct, .content a.struct, .block a.current.struct { color: #e53700; }
386+
.content span.struct, .content a.struct, .block a.current.struct { color: #df3600; }
387387
.content a.type { color: #e57300; }
388388
.content a.macro { color: #068000; }
389389
.block a.current.crate { font-weight: 500; }

src/librustdoc/html/static/styles/main.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ a {
106106
}
107107

108108
.docblock a, .stability a {
109-
color: #4e8bca;
109+
color: #3873AD;
110110
}
111111

112112
a.test-arrow {
113113
color: #f5f5f5;
114114
}
115115

116-
.content span.trait, .content a.trait, .block a.current.trait { color: #8866ff; }
116+
.content span.trait, .content a.trait, .block a.current.trait { color: #7c5af3; }
117117

118118
.search-input {
119119
color: #555;

src/libstd/collections/hash/map.rs

+29
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,35 @@ fn test_resize_policy() {
272272
/// }
273273
/// ```
274274
///
275+
/// `HashMap` also implements an [`Entry API`](#method.entry), which allows
276+
/// for more complex methods of getting, setting, updating and removing keys and
277+
/// their values:
278+
///
279+
/// ```
280+
/// use std::collections::HashMap;
281+
///
282+
/// // type inference lets us omit an explicit type signature (which
283+
/// // would be `HashMap<&str, u8>` in this example).
284+
/// let mut player_stats = HashMap::new();
285+
///
286+
/// fn random_stat_buff() -> u8 {
287+
/// // could actually return some random value here - let's just return
288+
/// // some fixed value for now
289+
/// 42
290+
/// }
291+
///
292+
/// // insert a key only if it doesn't already exist
293+
/// player_stats.entry("health").or_insert(100);
294+
///
295+
/// // insert a key using a function that provides a new value only if it
296+
/// // doesn't already exist
297+
/// player_stats.entry("defence").or_insert_with(random_stat_buff);
298+
///
299+
/// // update a key, guarding against the key possibly not being set
300+
/// let stat = player_stats.entry("attack").or_insert(100);
301+
/// *stat += random_stat_buff();
302+
/// ```
303+
///
275304
/// The easiest way to use `HashMap` with a custom type as key is to derive `Eq` and `Hash`.
276305
/// We must also derive `PartialEq`.
277306
///

src/libstd/ffi/c_str.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,14 @@ impl CStr {
407407
/// # fn main() {
408408
/// use std::ffi::CStr;
409409
/// use std::os::raw::c_char;
410-
/// use std::str;
411410
///
412411
/// extern {
413412
/// fn my_string() -> *const c_char;
414413
/// }
415414
///
416415
/// unsafe {
417416
/// let slice = CStr::from_ptr(my_string());
418-
/// println!("string returned: {}",
419-
/// str::from_utf8(slice.to_bytes()).unwrap());
417+
/// println!("string returned: {}", slice.to_str().unwrap());
420418
/// }
421419
/// # }
422420
/// ```

src/libstd/fs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl OpenOptions {
414414
/// This option, when true, will indicate that the file should be
415415
/// `write`-able if opened.
416416
///
417-
/// If a file already exist, any write calls on the file will overwrite its
417+
/// If the file already exists, any write calls on it will overwrite its
418418
/// contents, without truncating it.
419419
///
420420
/// # Examples
@@ -487,8 +487,8 @@ impl OpenOptions {
487487
/// This option indicates whether a new file will be created if the file
488488
/// does not yet already exist.
489489
///
490-
/// The file must be opened with write or append access in order to create
491-
/// a new file.
490+
/// In order for the file to be created, `write` or `append` access must
491+
/// be used.
492492
///
493493
/// # Examples
494494
///

src/libstd/sync/semaphore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
of resources is currently unclear",
1414
issue = "27798")]
1515
#![rustc_deprecated(since = "1.7.0",
16-
reason = "easily confused with system sempahores and not \
16+
reason = "easily confused with system semaphores and not \
1717
used enough to pull its weight")]
1818
#![allow(deprecated)]
1919

src/test/auxiliary/issue_30123_aux.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::marker::PhantomData;
12+
13+
pub struct Directed;
14+
pub struct Undirected;
15+
16+
pub struct Graph<N, E, Ty = Directed> {
17+
nodes: Vec<PhantomData<N>>,
18+
edges: Vec<PhantomData<E>>,
19+
ty: PhantomData<Ty>,
20+
}
21+
22+
23+
impl<N, E> Graph<N, E, Directed> {
24+
pub fn new() -> Self {
25+
Graph{nodes: Vec::new(), edges: Vec::new(), ty: PhantomData}
26+
}
27+
}
28+
29+
impl<N, E> Graph<N, E, Undirected> {
30+
pub fn new_undirected() -> Self {
31+
Graph{nodes: Vec::new(), edges: Vec::new(), ty: PhantomData}
32+
}
33+
}

src/test/compile-fail/issue-30123.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:issue_30123_aux.rs
12+
13+
extern crate issue_30123_aux;
14+
use issue_30123_aux::*;
15+
16+
fn main() {
17+
let ug = Graph::<i32, i32>::new_undirected();
18+
//~^ ERR no associated item named `new_undirected` found for type
19+
}

0 commit comments

Comments
 (0)