From 78dfacd40e729f50c4a85f6344605e8d28ac85f0 Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Wed, 15 Apr 2015 11:31:20 +1200 Subject: [PATCH 1/5] rustc: Add long diagnostics for E0152 --- src/librustc/diagnostics.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 938a74382e20e..1900657876785 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -112,6 +112,20 @@ reference when using guards or refactor the entire expression, perhaps by putting the condition inside the body of the arm. "##, +E0152: r##" +Lang items are already implemented in the standard library. Unless you are +writing a free-standing application (e.g. a kernel), you do not need to provide +them yourself. + +You can build a free-standing crate by adding `#![no_std]` to the crate +attributes: + +#![feature(no_std)] +#![no_std] + +See also https://doc.rust-lang.org/book/no-stdlib.html +"##, + E0162: r##" An if-let pattern attempts to match the pattern, and enters the body if the match was succesful. If the match is irrefutable (when it cannot fail to match), @@ -256,7 +270,6 @@ register_diagnostics! { E0137, E0138, E0139, - E0152, E0158, E0161, E0170, From 79815e7dc0e82103843eda232add0f340bd66567 Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Wed, 15 Apr 2015 11:54:21 +1200 Subject: [PATCH 2/5] rustc: Add long diagnostics for E0158 --- src/librustc/diagnostics.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 1900657876785..a13cb27f48c51 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -126,6 +126,24 @@ attributes: See also https://doc.rust-lang.org/book/no-stdlib.html "##, +E0158: r##" +`const` and `static` mean different things. A `const` is a compile-time +constant, an alias for a literal value. This property means you can match it +directly within a pattern. + +The `static` keyword, on the other hand, guarantees a fixed location in memory. +This does not always mean that the value is constant. For example, a global +mutex can be declared `static` as well. + +If you want to match against a `static`, consider using a guard instead: + +static FORTY_TWO: i32 = 42; +match Some(42) { + Some(x) if x == FORTY_TWO => ... + ... +} +"##, + E0162: r##" An if-let pattern attempts to match the pattern, and enters the body if the match was succesful. If the match is irrefutable (when it cannot fail to match), @@ -270,7 +288,6 @@ register_diagnostics! { E0137, E0138, E0139, - E0158, E0161, E0170, E0261, // use of undeclared lifetime name From 5c26228d49a7cd300ab7b36c6af673ff4a23bec0 Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Wed, 15 Apr 2015 20:25:58 +1200 Subject: [PATCH 3/5] rustc: Add long diagnostics for E0161 --- src/librustc/diagnostics.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index a13cb27f48c51..15bad7aa5e535 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -144,6 +144,14 @@ match Some(42) { } "##, +E0161: r##" +In Rust, you can only move a value when its size is known at compile time. + +To work around this restriction, consider "hiding" the value behind a reference: +either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move +it around as usual. +"##, + E0162: r##" An if-let pattern attempts to match the pattern, and enters the body if the match was succesful. If the match is irrefutable (when it cannot fail to match), @@ -288,7 +296,6 @@ register_diagnostics! { E0137, E0138, E0139, - E0161, E0170, E0261, // use of undeclared lifetime name E0262, // illegal lifetime parameter name From 84ef8698a0beb5aa5c94c2f8444b86663a15efef Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Wed, 15 Apr 2015 20:51:30 +1200 Subject: [PATCH 4/5] rustc: Add long diagnostics for E0170 --- src/librustc/diagnostics.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 15bad7aa5e535..222ebb09f915b 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -191,6 +191,32 @@ loop { } "##, +E0170: r##" +Enum variants are qualified by default. For example, given this type: + +enum Method { + GET, + POST +} + +you would match it using: + +match m { + Method::GET => ... + Method::POST => ... +} + +If you don't qualify the names, the code will bind new variables named "GET" and +"POST" instead. This behavior is likely not what you want, so rustc warns when +that happens. + +Qualified names are good practice, and most code works well with them. But if +you prefer them unqualified, you can import the variants into scope: + +use Method::*; +enum Method { GET, POST } +"##, + E0297: r##" Patterns used to bind names must be irrefutable. That is, they must guarantee that a name will be extracted in all cases. Instead of pattern matching the @@ -296,7 +322,6 @@ register_diagnostics! { E0137, E0138, E0139, - E0170, E0261, // use of undeclared lifetime name E0262, // illegal lifetime parameter name E0263, // lifetime name declared twice in same scope From 98faf54c85c58f4dceba24f6e361889dc29b75d3 Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Wed, 15 Apr 2015 21:15:09 +1200 Subject: [PATCH 5/5] rustc: Add long diagnostics for E0306 and E0307 --- src/librustc/diagnostics.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 222ebb09f915b..e1eb8d7418695 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -293,6 +293,16 @@ match Some(5) { } See also https://github.com/rust-lang/rust/issues/14587 +"##, + +E0306: r##" +In an array literal `[x; N]`, `N` is the number of elements in the array. This +number cannot be negative. +"##, + +E0307: r##" +The length of an array is part of its type. For this reason, this length must be +a compile-time constant. "## } @@ -353,8 +363,6 @@ register_diagnostics! { E0300, // unexpanded macro E0304, // expected signed integer constant E0305, // expected constant - E0306, // expected positive integer for repeat count - E0307, // expected constant integer for repeat count E0308, E0309, // thing may not live long enough E0310, // thing may not live long enough