File tree Expand file tree Collapse file tree 7 files changed +65
-6
lines changed Expand file tree Collapse file tree 7 files changed +65
-6
lines changed Original file line number Diff line number Diff line change @@ -258,7 +258,7 @@ symbol : "::" | "->"
258258 | ',' | ';' ;
259259```
260260
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
262262roles in a variety of grammar productions. They are catalogued here for
263263completeness as the set of remaining miscellaneous printable tokens that do not
264264otherwise 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`.
418418
419419### Symbols
420420
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
422422roles in a variety of grammar productions. They are catalogued here for
423423completeness as the set of remaining miscellaneous printable tokens that do not
424424otherwise appear as [ unary operators] ( #unary-operator-expressions ) , [ binary
Original file line number Diff line number Diff line change @@ -23,6 +23,31 @@ match x {
2323
2424This prints ` one ` .
2525
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+
2651# Multiple patterns
2752
2853You 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:
492492``` text
493493error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277]
494494```
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 {
935935
936936 /// Creates an iterator that clones the elements it yields.
937937 ///
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>` ,
939939 /// so it's a more convenient form of `map(|&x| x)`.
940940 ///
941941 /// # Examples
Original file line number Diff line number Diff line change @@ -285,7 +285,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
285285 -> Compilation {
286286 match matches. opt_str ( "explain" ) {
287287 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) {
289294 Some ( ref description) => {
290295 // Slice off the leading newline and print.
291296 print ! ( "{}" , & description[ 1 ..] ) ;
Original file line number Diff line number Diff line change @@ -1308,8 +1308,8 @@ extern "rust-intrinsic" {
13081308"## ,
13091309
13101310E0101 : 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:
13131313
13141314```
13151315fn main() {
You can’t perform that action at this time.
0 commit comments