File tree 7 files changed +65
-6
lines changed
7 files changed +65
-6
lines changed Original file line number Diff line number Diff line change @@ -258,7 +258,7 @@ symbol : "::" | "->"
258
258
| ',' | ';' ;
259
259
```
260
260
261
- Symbols are a general class of printable [ token ] ( #tokens ) that play structural
261
+ Symbols are a general class of printable [ tokens ] ( #tokens ) that play structural
262
262
roles in a variety of grammar productions. They are catalogued here for
263
263
completeness as the set of remaining miscellaneous printable tokens that do not
264
264
otherwise appear as [ unary operators] ( #unary-operator-expressions ) , [ binary
Original file line number Diff line number Diff line change @@ -418,7 +418,7 @@ The two values of the boolean type are written `true` and `false`.
418
418
419
419
### Symbols
420
420
421
- Symbols are a general class of printable [ token ] ( #tokens ) that play structural
421
+ Symbols are a general class of printable [ tokens ] ( #tokens ) that play structural
422
422
roles in a variety of grammar productions. They are catalogued here for
423
423
completeness as the set of remaining miscellaneous printable tokens that do not
424
424
otherwise appear as [ unary operators] ( #unary-operator-expressions ) , [ binary
Original file line number Diff line number Diff line change @@ -23,6 +23,31 @@ match x {
23
23
24
24
This prints ` one ` .
25
25
26
+ There’s one pitfall with patterns: like anything that introduces a new binding,
27
+ they introduce shadowing. For example:
28
+
29
+ ``` rust
30
+ let x = 'x' ;
31
+ let c = 'c' ;
32
+
33
+ match c {
34
+ x => println! (" x: {} c: {}" , x , c ),
35
+ }
36
+
37
+ println! (" x: {}" , x )
38
+ ```
39
+
40
+ This prints:
41
+
42
+ ``` text
43
+ x: c c: c
44
+ x: x
45
+ ```
46
+
47
+ In other words, ` x => ` matches the pattern and introduces a new binding named
48
+ ` x ` that’s in scope for the match arm. Because we already have a binding named
49
+ ` x ` , this new ` x ` shadows it.
50
+
26
51
# Multiple patterns
27
52
28
53
You can match multiple patterns with ` | ` :
Original file line number Diff line number Diff line change @@ -492,3 +492,32 @@ If we forget to implement `Foo`, Rust will tell us:
492
492
``` text
493
493
error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277]
494
494
```
495
+
496
+ # Deriving
497
+
498
+ Implementing traits like ` Debug ` and ` Default ` over and over again can become
499
+ quite tedious. For that reason, Rust provides an [ attribute] [ attributes ] that
500
+ allows you to let Rust automatically implement traits for you:
501
+
502
+ ``` rust
503
+ #[derive(Debug )]
504
+ struct Foo ;
505
+
506
+ fn main () {
507
+ println! (" {:?}" , Foo );
508
+ }
509
+ ```
510
+
511
+ [ attributes ] : attributes.html
512
+
513
+ However, deriving is limited to a certain set of traits:
514
+
515
+ - [ ` Clone ` ] ( ../core/clone/trait.Clone.html )
516
+ - [ ` Copy ` ] ( ../core/marker/trait.Copy.html )
517
+ - [ ` Debug ` ] ( ../core/fmt/trait.Debug.html )
518
+ - [ ` Default ` ] ( ../core/default/trait.Default.html )
519
+ - [ ` Eq ` ] ( ../core/cmp/trait.Eq.html )
520
+ - [ ` Hash ` ] ( ../core/hash/trait.Hash.html )
521
+ - [ ` Ord ` ] ( ../core/cmp/trait.Ord.html )
522
+ - [ ` PartialEq ` ] ( ../core/cmp/trait.PartialEq.html )
523
+ - [ ` PartialOrd ` ] ( ../core/cmp/trait.PartialOrd.html )
Original file line number Diff line number Diff line change @@ -935,7 +935,7 @@ pub trait Iterator {
935
935
936
936
/// Creates an iterator that clones the elements it yields.
937
937
///
938
- /// This is useful for converting an Iterator<&T> to an Iterator<T>,
938
+ /// This is useful for converting an ` Iterator<&T>` to an` Iterator<T>` ,
939
939
/// so it's a more convenient form of `map(|&x| x)`.
940
940
///
941
941
/// # Examples
Original file line number Diff line number Diff line change @@ -285,7 +285,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
285
285
-> Compilation {
286
286
match matches. opt_str ( "explain" ) {
287
287
Some ( ref code) => {
288
- match descriptions. find_description ( & code[ ..] ) {
288
+ let normalised = if !code. starts_with ( "E" ) {
289
+ format ! ( "E{0:0>4}" , code)
290
+ } else {
291
+ code. to_string ( )
292
+ } ;
293
+ match descriptions. find_description ( & normalised) {
289
294
Some ( ref description) => {
290
295
// Slice off the leading newline and print.
291
296
print ! ( "{}" , & description[ 1 ..] ) ;
Original file line number Diff line number Diff line change @@ -1308,8 +1308,8 @@ extern "rust-intrinsic" {
1308
1308
"## ,
1309
1309
1310
1310
E0101 : r##"
1311
- You hit this error because the compiler the compiler lacks information
1312
- to determine a type for this expression. Erroneous code example:
1311
+ You hit this error because the compiler lacks the information to
1312
+ determine a type for this expression. Erroneous code example:
1313
1313
1314
1314
```
1315
1315
fn main() {
You can’t perform that action at this time.
0 commit comments