From 5d015561836761e7a3d99e46dc91ccc7b6403e73 Mon Sep 17 00:00:00 2001 From: Will Speak Date: Tue, 6 Oct 2015 21:15:04 +0100 Subject: [PATCH 1/7] Make `--explain` Handle Partial Error Codes Currently the explain command requires full erorr codes, complete with the leading zeros and the E at the beginning. This commit changes that, if you don't supply a full erorr code then the error number is padded out to the required size and the E is added to the beginning. This means that where previously you would need to write E0001, you can now write 0001, 001, 01 or jsut 1 to refer to the same error. --- src/librustc_driver/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index d5644d49e1e..e4f033efb58 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -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..]); From bbc2056694f2fd4f631fb1b7d74c47ffe200b036 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Wed, 7 Oct 2015 16:41:15 -0400 Subject: [PATCH 2/7] Comment on shadowing with patterns Fixes #28687 --- src/doc/trpl/patterns.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md index a365732fe9b..bce147cc71f 100644 --- a/src/doc/trpl/patterns.md +++ b/src/doc/trpl/patterns.md @@ -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 `|`: From 4d7eee1817582c4bf70862d47aca9e75bb264bc7 Mon Sep 17 00:00:00 2001 From: panicbit Date: Thu, 8 Oct 2015 07:10:56 +0200 Subject: [PATCH 3/7] trpl: mention deriving in traits section --- src/doc/trpl/traits.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 0870a6ef341..8726a29d710 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -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` +- `Copy` +- `Debug` +- `Default` +- `Eq` +- `Hash` +- `Ord` +- `PartialEq` +- `PartialOrd` From 7515514fdccbfb7e41b9ba7844f9b34308efe7f0 Mon Sep 17 00:00:00 2001 From: panicbit Date: Thu, 8 Oct 2015 07:27:26 +0200 Subject: [PATCH 4/7] trpl: link to derivable trait's docs --- src/doc/trpl/traits.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 8726a29d710..27debf86e39 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -512,12 +512,12 @@ fn main() { However, deriving is limited to a certain set of traits: -- `Clone` -- `Copy` -- `Debug` -- `Default` -- `Eq` -- `Hash` -- `Ord` -- `PartialEq` -- `PartialOrd` +- [`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) From 88506c22612088c377fddd0472e13c9d2f84a68a Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 8 Oct 2015 07:24:00 +0200 Subject: [PATCH 5/7] reference: fix typos --- src/doc/grammar.md | 2 +- src/doc/reference.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 7bfe8b62e8a..0fd3070d3bd 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -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 diff --git a/src/doc/reference.md b/src/doc/reference.md index db3f4b064b1..d8dc195dcaf 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -415,7 +415,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 From f18d1ad32469ca87452e701ab6ec636b79112070 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 8 Oct 2015 08:00:02 -0400 Subject: [PATCH 6/7] Format code-like text in Iterator::cloned doc-comment --- src/libcore/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 00c7773fd8b..3554325d0db 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -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, + /// This is useful for converting an `Iterator<&T>` to an`Iterator`, /// so it's a more convenient form of `map(|&x| x)`. /// /// # Examples From e4cc54ed06e792881791e380ad1eac0f14024ff4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 8 Oct 2015 11:32:38 +0200 Subject: [PATCH 7/7] Fix typo in E0101 --- src/librustc_typeck/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 8408e9c0c70..4746819f6a9 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -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() {