Skip to content

Commit 33dca5e

Browse files
committed
rustc: Add long diagnostics for E0165
1 parent c45eacd commit 33dca5e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/librustc/diagnostics.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ let Irrefutable(x) = irr;
131131
foo(x);
132132
"##,
133133

134+
E0165: r##"
135+
A while-let pattern attempts to match the pattern, and enters the body if the
136+
match was succesful. If the match is irrefutable (when it cannot fail to match),
137+
use a regular `let`-binding inside a `loop` instead. For instance:
138+
139+
struct Irrefutable(i32);
140+
let irr = Irrefutable(0);
141+
142+
// This fails to compile because the match is irrefutable.
143+
while let Irrefutable(x) = irr {
144+
...
145+
}
146+
147+
// Try this instead:
148+
loop {
149+
let Irrefutable(x) = irr;
150+
...
151+
}
152+
"##,
153+
134154
E0297: r##"
135155
Patterns used to bind names must be irrefutable. That is, they must guarantee
136156
that a name will be extracted in all cases. Instead of pattern matching the
@@ -239,7 +259,6 @@ register_diagnostics! {
239259
E0152,
240260
E0158,
241261
E0161,
242-
E0165,
243262
E0170,
244263
E0261, // use of undeclared lifetime name
245264
E0262, // illegal lifetime parameter name

0 commit comments

Comments
 (0)