Skip to content

Commit 79815e7

Browse files
committed
rustc: Add long diagnostics for E0158
1 parent 78dfacd commit 79815e7

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/librustc/diagnostics.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ attributes:
126126
See also https://doc.rust-lang.org/book/no-stdlib.html
127127
"##,
128128

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+
129147
E0162: r##"
130148
An if-let pattern attempts to match the pattern, and enters the body if the
131149
match was succesful. If the match is irrefutable (when it cannot fail to match),
@@ -270,7 +288,6 @@ register_diagnostics! {
270288
E0137,
271289
E0138,
272290
E0139,
273-
E0158,
274291
E0161,
275292
E0170,
276293
E0261, // use of undeclared lifetime name

0 commit comments

Comments
 (0)