mirror of
https://github.com/rust-lang/rust
synced 2024-10-06 08:40:35 +00:00
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
This commit is contained in:
commit
0486e12ad0
|
@ -80,3 +80,4 @@ Language](http://www.cs.indiana.edu/~eholk/papers/hips2013.pdf). Early GPU work
|
|||
Rust](http://munksgaard.me/papers/laumann-munksgaard-larsen.pdf). Philip
|
||||
Munksgaard's master's thesis. Research for Servo.
|
||||
* [Ownership is Theft: Experiences Building an Embedded OS in Rust - Amit Levy, et. al.](http://amitlevy.com/papers/tock-plos2015.pdf)
|
||||
* [You can't spell trust without Rust](https://raw.githubusercontent.com/Gankro/thesis/master/thesis.pdf). Alexis Beingessner's master's thesis.
|
||||
|
|
|
@ -111,7 +111,7 @@ If we're on Linux or a Mac, all we need to do is open a terminal and type this:
|
|||
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh
|
||||
```
|
||||
|
||||
This will download a script, and stat the installation. If it all goes well,
|
||||
This will download a script, and start the installation. If it all goes well,
|
||||
you’ll see this appear:
|
||||
|
||||
```text
|
||||
|
|
|
@ -908,6 +908,7 @@ let guess: u32 = match guess.trim().parse() {
|
|||
```
|
||||
|
||||
This is how you generally move from ‘crash on error’ to ‘actually handle the
|
||||
error’, by switching from `expect()` to a `match` statement. The `Result`
|
||||
returned by `parse()` is an `enum` like `Ordering`, but in this case, each
|
||||
variant has some data associated with it: `Ok` is a success, and `Err` is a
|
||||
failure. Each contains more information: the successfully parsed integer, or an
|
||||
|
|
|
@ -77,10 +77,11 @@ The compiler currently makes a few assumptions about symbols which are available
|
|||
in the executable to call. Normally these functions are provided by the standard
|
||||
library, but without it you must define your own.
|
||||
|
||||
The first of these two functions, `eh_personality`, is used by the
|
||||
failure mechanisms of the compiler. This is often mapped to GCC's
|
||||
personality function (see the
|
||||
[libstd implementation](../std/rt/unwind/index.html) for more
|
||||
information), but crates which do not trigger a panic can be assured
|
||||
that this function is never called. The second function, `panic_fmt`, is
|
||||
also used by the failure mechanisms of the compiler.
|
||||
The first of these two functions, `eh_personality`, is used by the failure
|
||||
mechanisms of the compiler. This is often mapped to GCC's personality function
|
||||
(see the [libstd implementation][unwind] for more information), but crates
|
||||
which do not trigger a panic can be assured that this function is never
|
||||
called. The second function, `panic_fmt`, is also used by the failure
|
||||
mechanisms of the compiler.
|
||||
|
||||
[unwind]: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/unwind/gcc.rs
|
||||
|
|
|
@ -277,16 +277,22 @@ This will compile without error.
|
|||
This means that even if someone does something bad like add methods to `i32`,
|
||||
it won’t affect you, unless you `use` that trait.
|
||||
|
||||
There’s one more restriction on implementing traits: either the trait, or the
|
||||
type you’re writing the `impl` for, must be defined by you. So, we could
|
||||
implement the `HasArea` type for `i32`, because `HasArea` is in our code. But
|
||||
if we tried to implement `ToString`, a trait provided by Rust, for `i32`, we could
|
||||
not, because neither the trait nor the type are in our code.
|
||||
There’s one more restriction on implementing traits: either the trait
|
||||
or the type you’re implementing it for must be defined by you. Or more
|
||||
precisely, one of them must be defined in the same crate as the `impl`
|
||||
you're writing. For more on Rust's module and package system, see the
|
||||
chapter on [crates and modules][cm].
|
||||
|
||||
So, we could implement the `HasArea` type for `i32`, because we defined
|
||||
`HasArea` in our code. But if we tried to implement `ToString`, a trait
|
||||
provided by Rust, for `i32`, we could not, because neither the trait nor
|
||||
the type are defined in our crate.
|
||||
|
||||
One last thing about traits: generic functions with a trait bound use
|
||||
‘monomorphization’ (mono: one, morph: form), so they are statically dispatched.
|
||||
What’s that mean? Check out the chapter on [trait objects][to] for more details.
|
||||
|
||||
[cm]: crates-and-modules.html
|
||||
[to]: trait-objects.html
|
||||
|
||||
# Multiple trait bounds
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div id="versioninfo">
|
||||
<img src="https://www.rust-lang.org/logos/rust-logo-32x32-blk.png" width="32" height="32" alt><br>
|
||||
<img src="https://www.rust-lang.org/logos/rust-logo-32x32-blk.png" width="32" height="32" alt="Rust logo"><br>
|
||||
<span class="white-sticker"><a href="https://www.rust-lang.org">Rust</a> VERSION</span><br>
|
||||
<a href="https://github.com/rust-lang/rust/commit/STAMP"
|
||||
class="hash white-sticker">SHORT_HASH</a>
|
||||
|
|
|
@ -1194,7 +1194,7 @@ unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
|
|||
}
|
||||
|
||||
impl<K, V> BTreeMap<K, V> {
|
||||
/// Gets an iterator over the entries of the map.
|
||||
/// Gets an iterator over the entries of the map, sorted by key.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -1202,9 +1202,9 @@ impl<K, V> BTreeMap<K, V> {
|
|||
/// use std::collections::BTreeMap;
|
||||
///
|
||||
/// let mut map = BTreeMap::new();
|
||||
/// map.insert(1, "a");
|
||||
/// map.insert(2, "b");
|
||||
/// map.insert(3, "c");
|
||||
/// map.insert(2, "b");
|
||||
/// map.insert(1, "a");
|
||||
///
|
||||
/// for (key, value) in map.iter() {
|
||||
/// println!("{}: {}", key, value);
|
||||
|
@ -1224,7 +1224,7 @@ pub fn iter(&self) -> Iter<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Gets a mutable iterator over the entries of the map.
|
||||
/// Gets a mutable iterator over the entries of the map, sorted by key.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -1257,7 +1257,7 @@ pub fn iter_mut(&mut self) -> IterMut<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Gets an iterator over the keys of the map.
|
||||
/// Gets an iterator over the keys of the map, in sorted order.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -1265,8 +1265,8 @@ pub fn iter_mut(&mut self) -> IterMut<K, V> {
|
|||
/// use std::collections::BTreeMap;
|
||||
///
|
||||
/// let mut a = BTreeMap::new();
|
||||
/// a.insert(1, "a");
|
||||
/// a.insert(2, "b");
|
||||
/// a.insert(1, "a");
|
||||
///
|
||||
/// let keys: Vec<_> = a.keys().cloned().collect();
|
||||
/// assert_eq!(keys, [1, 2]);
|
||||
|
@ -1276,7 +1276,7 @@ pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
|
|||
Keys { inner: self.iter() }
|
||||
}
|
||||
|
||||
/// Gets an iterator over the values of the map.
|
||||
/// Gets an iterator over the values of the map, in order by key.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -1284,11 +1284,11 @@ pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
|
|||
/// use std::collections::BTreeMap;
|
||||
///
|
||||
/// let mut a = BTreeMap::new();
|
||||
/// a.insert(1, "a");
|
||||
/// a.insert(2, "b");
|
||||
/// a.insert(1, "hello");
|
||||
/// a.insert(2, "goodbye");
|
||||
///
|
||||
/// let values: Vec<&str> = a.values().cloned().collect();
|
||||
/// assert_eq!(values, ["a", "b"]);
|
||||
/// assert_eq!(values, ["hello", "goodbye"]);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn values<'a>(&'a self) -> Values<'a, K, V> {
|
||||
|
|
|
@ -124,7 +124,7 @@ fn main() {
|
|||
let mut x = Rc::new(RefCell::new(MyStruct{ s: 5u32 }));
|
||||
let y = x.clone();
|
||||
x.borrow_mut().s = 6;
|
||||
println!("{}", x.borrow.s);
|
||||
println!("{}", x.borrow().s);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -207,7 +207,41 @@ fn main() {}
|
|||
E0317: r##"
|
||||
User-defined types or type parameters cannot shadow the primitive types.
|
||||
This error indicates you tried to define a type, struct or enum with the same
|
||||
name as an existing primitive type.
|
||||
name as an existing primitive type:
|
||||
|
||||
```
|
||||
struct u8 {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
To fix this, simply name it something else.
|
||||
|
||||
Such an error may also occur if you define a type parameter which shadows a
|
||||
primitive type. An example would be something like:
|
||||
|
||||
```
|
||||
impl<u8> MyTrait for Option<u8> {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
In such a case, if you meant for `u8` to be a generic type parameter (i.e. any
|
||||
type can be used in its place), use something like `T` instead:
|
||||
|
||||
```
|
||||
impl<T> MyTrait for Option<T> {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
On the other hand, if you wished to refer to the specific type `u8`, remove it
|
||||
from the type parameter list:
|
||||
|
||||
```
|
||||
impl MyTrait for Option<u8> {
|
||||
// ...
|
||||
}
|
||||
|
||||
See the Types section of the reference for more information about the primitive
|
||||
types:
|
||||
|
|
|
@ -2269,6 +2269,8 @@ impl<T> ForeignTrait for T { ... } // error
|
|||
impl<T> ForeignTrait for MyType<T> { ... } // Ok
|
||||
```
|
||||
|
||||
Please note that a type alias is not sufficient.
|
||||
|
||||
For another example of an error, suppose there's another trait defined in `foo`
|
||||
named `ForeignTrait2` that takes two type parameters. Then this `impl` results
|
||||
in the same rule violation:
|
||||
|
|
|
@ -148,7 +148,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
|
|||
"".to_string()
|
||||
} else {
|
||||
format!("<a href='{}{}/index.html'>\
|
||||
<img src='{}' alt='' width='100'></a>",
|
||||
<img src='{}' alt='logo' width='100'></a>",
|
||||
page.root_path, layout.krate,
|
||||
layout.logo)
|
||||
},
|
||||
|
|
|
@ -383,7 +383,7 @@ a {
|
|||
}
|
||||
|
||||
.content span.enum, .content a.enum, .block a.current.enum { color: #5e9766; }
|
||||
.content span.struct, .content a.struct, .block a.current.struct { color: #e53700; }
|
||||
.content span.struct, .content a.struct, .block a.current.struct { color: #df3600; }
|
||||
.content a.type { color: #e57300; }
|
||||
.content a.macro { color: #068000; }
|
||||
.block a.current.crate { font-weight: 500; }
|
||||
|
|
|
@ -106,14 +106,14 @@ a {
|
|||
}
|
||||
|
||||
.docblock a, .stability a {
|
||||
color: #4e8bca;
|
||||
color: #3873AD;
|
||||
}
|
||||
|
||||
a.test-arrow {
|
||||
color: #f5f5f5;
|
||||
}
|
||||
|
||||
.content span.trait, .content a.trait, .block a.current.trait { color: #8866ff; }
|
||||
.content span.trait, .content a.trait, .block a.current.trait { color: #7c5af3; }
|
||||
|
||||
.search-input {
|
||||
color: #555;
|
||||
|
|
|
@ -272,6 +272,35 @@ fn test_resize_policy() {
|
|||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// `HashMap` also implements an [`Entry API`](#method.entry), which allows
|
||||
/// for more complex methods of getting, setting, updating and removing keys and
|
||||
/// their values:
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::HashMap;
|
||||
///
|
||||
/// // type inference lets us omit an explicit type signature (which
|
||||
/// // would be `HashMap<&str, u8>` in this example).
|
||||
/// let mut player_stats = HashMap::new();
|
||||
///
|
||||
/// fn random_stat_buff() -> u8 {
|
||||
/// // could actually return some random value here - let's just return
|
||||
/// // some fixed value for now
|
||||
/// 42
|
||||
/// }
|
||||
///
|
||||
/// // insert a key only if it doesn't already exist
|
||||
/// player_stats.entry("health").or_insert(100);
|
||||
///
|
||||
/// // insert a key using a function that provides a new value only if it
|
||||
/// // doesn't already exist
|
||||
/// player_stats.entry("defence").or_insert_with(random_stat_buff);
|
||||
///
|
||||
/// // update a key, guarding against the key possibly not being set
|
||||
/// let stat = player_stats.entry("attack").or_insert(100);
|
||||
/// *stat += random_stat_buff();
|
||||
/// ```
|
||||
///
|
||||
/// The easiest way to use `HashMap` with a custom type as key is to derive `Eq` and `Hash`.
|
||||
/// We must also derive `PartialEq`.
|
||||
///
|
||||
|
|
|
@ -407,7 +407,6 @@ impl CStr {
|
|||
/// # fn main() {
|
||||
/// use std::ffi::CStr;
|
||||
/// use std::os::raw::c_char;
|
||||
/// use std::str;
|
||||
///
|
||||
/// extern {
|
||||
/// fn my_string() -> *const c_char;
|
||||
|
@ -415,8 +414,7 @@ impl CStr {
|
|||
///
|
||||
/// unsafe {
|
||||
/// let slice = CStr::from_ptr(my_string());
|
||||
/// println!("string returned: {}",
|
||||
/// str::from_utf8(slice.to_bytes()).unwrap());
|
||||
/// println!("string returned: {}", slice.to_str().unwrap());
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
|
|
|
@ -414,7 +414,7 @@ pub fn read(&mut self, read: bool) -> &mut OpenOptions {
|
|||
/// This option, when true, will indicate that the file should be
|
||||
/// `write`-able if opened.
|
||||
///
|
||||
/// If a file already exist, any write calls on the file will overwrite its
|
||||
/// If the file already exists, any write calls on it will overwrite its
|
||||
/// contents, without truncating it.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -487,8 +487,8 @@ pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions {
|
|||
/// This option indicates whether a new file will be created if the file
|
||||
/// does not yet already exist.
|
||||
///
|
||||
/// The file must be opened with write or append access in order to create
|
||||
/// a new file.
|
||||
/// In order for the file to be created, `write` or `append` access must
|
||||
/// be used.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
of resources is currently unclear",
|
||||
issue = "27798")]
|
||||
#![rustc_deprecated(since = "1.7.0",
|
||||
reason = "easily confused with system sempahores and not \
|
||||
reason = "easily confused with system semaphores and not \
|
||||
used enough to pull its weight")]
|
||||
#![allow(deprecated)]
|
||||
|
||||
|
|
33
src/test/auxiliary/issue_30123_aux.rs
Normal file
33
src/test/auxiliary/issue_30123_aux.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct Directed;
|
||||
pub struct Undirected;
|
||||
|
||||
pub struct Graph<N, E, Ty = Directed> {
|
||||
nodes: Vec<PhantomData<N>>,
|
||||
edges: Vec<PhantomData<E>>,
|
||||
ty: PhantomData<Ty>,
|
||||
}
|
||||
|
||||
|
||||
impl<N, E> Graph<N, E, Directed> {
|
||||
pub fn new() -> Self {
|
||||
Graph{nodes: Vec::new(), edges: Vec::new(), ty: PhantomData}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N, E> Graph<N, E, Undirected> {
|
||||
pub fn new_undirected() -> Self {
|
||||
Graph{nodes: Vec::new(), edges: Vec::new(), ty: PhantomData}
|
||||
}
|
||||
}
|
19
src/test/compile-fail/issue-30123.rs
Normal file
19
src/test/compile-fail/issue-30123.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// aux-build:issue_30123_aux.rs
|
||||
|
||||
extern crate issue_30123_aux;
|
||||
use issue_30123_aux::*;
|
||||
|
||||
fn main() {
|
||||
let ug = Graph::<i32, i32>::new_undirected();
|
||||
//~^ ERR no associated item named `new_undirected` found for type
|
||||
}
|
Loading…
Reference in a new issue