Auto merge of #28913 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #28621, #28872, #28893, #28904, #28905, #28908, #28910 - Failed merges: #28906
This commit is contained in:
commit
e38210b195
src
doc
libcore
librustc_driver
librustc_typeck
@ -258,7 +258,7 @@ symbol : "::" | "->"
|
||||
| ',' | ';' ;
|
||||
```
|
||||
|
||||
Symbols are a general class of printable [token](#tokens) that play structural
|
||||
Symbols are a general class of printable [tokens](#tokens) that play structural
|
||||
roles in a variety of grammar productions. They are catalogued here for
|
||||
completeness as the set of remaining miscellaneous printable tokens that do not
|
||||
otherwise appear as [unary operators](#unary-operator-expressions), [binary
|
||||
|
@ -418,7 +418,7 @@ The two values of the boolean type are written `true` and `false`.
|
||||
|
||||
### Symbols
|
||||
|
||||
Symbols are a general class of printable [token](#tokens) that play structural
|
||||
Symbols are a general class of printable [tokens](#tokens) that play structural
|
||||
roles in a variety of grammar productions. They are catalogued here for
|
||||
completeness as the set of remaining miscellaneous printable tokens that do not
|
||||
otherwise appear as [unary operators](#unary-operator-expressions), [binary
|
||||
|
@ -23,6 +23,31 @@ match x {
|
||||
|
||||
This prints `one`.
|
||||
|
||||
There’s one pitfall with patterns: like anything that introduces a new binding,
|
||||
they introduce shadowing. For example:
|
||||
|
||||
```rust
|
||||
let x = 'x';
|
||||
let c = 'c';
|
||||
|
||||
match c {
|
||||
x => println!("x: {} c: {}", x, c),
|
||||
}
|
||||
|
||||
println!("x: {}", x)
|
||||
```
|
||||
|
||||
This prints:
|
||||
|
||||
```text
|
||||
x: c c: c
|
||||
x: x
|
||||
```
|
||||
|
||||
In other words, `x =>` matches the pattern and introduces a new binding named
|
||||
`x` that’s in scope for the match arm. Because we already have a binding named
|
||||
`x`, this new `x` shadows it.
|
||||
|
||||
# Multiple patterns
|
||||
|
||||
You can match multiple patterns with `|`:
|
||||
|
@ -492,3 +492,32 @@ If we forget to implement `Foo`, Rust will tell us:
|
||||
```text
|
||||
error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277]
|
||||
```
|
||||
|
||||
# Deriving
|
||||
|
||||
Implementing traits like `Debug` and `Default` over and over again can become
|
||||
quite tedious. For that reason, Rust provides an [attribute][attributes] that
|
||||
allows you to let Rust automatically implement traits for you:
|
||||
|
||||
```rust
|
||||
#[derive(Debug)]
|
||||
struct Foo;
|
||||
|
||||
fn main() {
|
||||
println!("{:?}", Foo);
|
||||
}
|
||||
```
|
||||
|
||||
[attributes]: attributes.html
|
||||
|
||||
However, deriving is limited to a certain set of traits:
|
||||
|
||||
- [`Clone`](../core/clone/trait.Clone.html)
|
||||
- [`Copy`](../core/marker/trait.Copy.html)
|
||||
- [`Debug`](../core/fmt/trait.Debug.html)
|
||||
- [`Default`](../core/default/trait.Default.html)
|
||||
- [`Eq`](../core/cmp/trait.Eq.html)
|
||||
- [`Hash`](../core/hash/trait.Hash.html)
|
||||
- [`Ord`](../core/cmp/trait.Ord.html)
|
||||
- [`PartialEq`](../core/cmp/trait.PartialEq.html)
|
||||
- [`PartialOrd`](../core/cmp/trait.PartialOrd.html)
|
||||
|
@ -935,7 +935,7 @@ pub trait Iterator {
|
||||
|
||||
/// Creates an iterator that clones the elements it yields.
|
||||
///
|
||||
/// This is useful for converting an Iterator<&T> to an Iterator<T>,
|
||||
/// This is useful for converting an `Iterator<&T>` to an`Iterator<T>`,
|
||||
/// so it's a more convenient form of `map(|&x| x)`.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -285,7 +285,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
||||
-> Compilation {
|
||||
match matches.opt_str("explain") {
|
||||
Some(ref code) => {
|
||||
match descriptions.find_description(&code[..]) {
|
||||
let normalised = if !code.starts_with("E") {
|
||||
format!("E{0:0>4}", code)
|
||||
} else {
|
||||
code.to_string()
|
||||
};
|
||||
match descriptions.find_description(&normalised) {
|
||||
Some(ref description) => {
|
||||
// Slice off the leading newline and print.
|
||||
print!("{}", &description[1..]);
|
||||
|
@ -1308,8 +1308,8 @@ extern "rust-intrinsic" {
|
||||
"##,
|
||||
|
||||
E0101: r##"
|
||||
You hit this error because the compiler the compiler lacks information
|
||||
to determine a type for this expression. Erroneous code example:
|
||||
You hit this error because the compiler lacks the information to
|
||||
determine a type for this expression. Erroneous code example:
|
||||
|
||||
```
|
||||
fn main() {
|
||||
|
Loading…
Reference in New Issue
Block a user