Skip to content

Commit 526abe8

Browse files
committed
Rollup merge of rust-lang#24455 - lfairy:explainify, r=alexcrichton
cc rust-lang#24407
2 parents 6140872 + 98faf54 commit 526abe8

File tree

1 file changed

+76
-6
lines changed

1 file changed

+76
-6
lines changed

src/librustc/diagnostics.rs

+76-6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,46 @@ reference when using guards or refactor the entire expression, perhaps by
112112
putting the condition inside the body of the arm.
113113
"##,
114114

115+
E0152: r##"
116+
Lang items are already implemented in the standard library. Unless you are
117+
writing a free-standing application (e.g. a kernel), you do not need to provide
118+
them yourself.
119+
120+
You can build a free-standing crate by adding `#![no_std]` to the crate
121+
attributes:
122+
123+
#![feature(no_std)]
124+
#![no_std]
125+
126+
See also https://doc.rust-lang.org/book/no-stdlib.html
127+
"##,
128+
129+
E0158: r##"
130+
`const` and `static` mean different things. A `const` is a compile-time
131+
constant, an alias for a literal value. This property means you can match it
132+
directly within a pattern.
133+
134+
The `static` keyword, on the other hand, guarantees a fixed location in memory.
135+
This does not always mean that the value is constant. For example, a global
136+
mutex can be declared `static` as well.
137+
138+
If you want to match against a `static`, consider using a guard instead:
139+
140+
static FORTY_TWO: i32 = 42;
141+
match Some(42) {
142+
Some(x) if x == FORTY_TWO => ...
143+
...
144+
}
145+
"##,
146+
147+
E0161: r##"
148+
In Rust, you can only move a value when its size is known at compile time.
149+
150+
To work around this restriction, consider "hiding" the value behind a reference:
151+
either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move
152+
it around as usual.
153+
"##,
154+
115155
E0162: r##"
116156
An if-let pattern attempts to match the pattern, and enters the body if the
117157
match was succesful. If the match is irrefutable (when it cannot fail to match),
@@ -151,6 +191,32 @@ loop {
151191
}
152192
"##,
153193

194+
E0170: r##"
195+
Enum variants are qualified by default. For example, given this type:
196+
197+
enum Method {
198+
GET,
199+
POST
200+
}
201+
202+
you would match it using:
203+
204+
match m {
205+
Method::GET => ...
206+
Method::POST => ...
207+
}
208+
209+
If you don't qualify the names, the code will bind new variables named "GET" and
210+
"POST" instead. This behavior is likely not what you want, so rustc warns when
211+
that happens.
212+
213+
Qualified names are good practice, and most code works well with them. But if
214+
you prefer them unqualified, you can import the variants into scope:
215+
216+
use Method::*;
217+
enum Method { GET, POST }
218+
"##,
219+
154220
E0297: r##"
155221
Patterns used to bind names must be irrefutable. That is, they must guarantee
156222
that a name will be extracted in all cases. Instead of pattern matching the
@@ -227,6 +293,16 @@ match Some(5) {
227293
}
228294
229295
See also https://github.com/rust-lang/rust/issues/14587
296+
"##,
297+
298+
E0306: r##"
299+
In an array literal `[x; N]`, `N` is the number of elements in the array. This
300+
number cannot be negative.
301+
"##,
302+
303+
E0307: r##"
304+
The length of an array is part of its type. For this reason, this length must be
305+
a compile-time constant.
230306
"##
231307

232308
}
@@ -256,10 +332,6 @@ register_diagnostics! {
256332
E0137,
257333
E0138,
258334
E0139,
259-
E0152,
260-
E0158,
261-
E0161,
262-
E0170,
263335
E0261, // use of undeclared lifetime name
264336
E0262, // illegal lifetime parameter name
265337
E0263, // lifetime name declared twice in same scope
@@ -291,8 +363,6 @@ register_diagnostics! {
291363
E0300, // unexpanded macro
292364
E0304, // expected signed integer constant
293365
E0305, // expected constant
294-
E0306, // expected positive integer for repeat count
295-
E0307, // expected constant integer for repeat count
296366
E0308,
297367
E0309, // thing may not live long enough
298368
E0310, // thing may not live long enough

0 commit comments

Comments
 (0)