Skip to content

Commit 9c6f4b6

Browse files
committed
rustc: Add long diagnostics for E0297
1 parent 47551b5 commit 9c6f4b6

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/librustc/diagnostics.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,33 @@ reference when using guards or refactor the entire expression, perhaps by
112112
putting the condition inside the body of the arm.
113113
"##,
114114

115+
E0297: r##"
116+
Patterns used to bind names must be irrefutable. That is, they must guarantee
117+
that a name will be extracted in all cases. Instead of pattern matching the
118+
loop variable, consider using a `match` or `if let` inside the loop body. For
119+
instance:
120+
121+
// This fails because `None` is not covered.
122+
for Some(x) in xs {
123+
...
124+
}
125+
126+
// Match inside the loop instead:
127+
for item in xs {
128+
match item {
129+
Some(x) => ...
130+
None => ...
131+
}
132+
}
133+
134+
// Or use `if let`:
135+
for item in xs {
136+
if let Some(x) = item {
137+
...
138+
}
139+
}
140+
"##,
141+
115142
E0303: r##"
116143
In certain cases it is possible for sub-bindings to violate memory safety.
117144
Updates to the borrow checker in a future version of Rust may remove this
@@ -194,7 +221,6 @@ register_diagnostics! {
194221
E0284, // cannot resolve type
195222
E0285, // overflow evaluation builtin bounds
196223
E0296, // malformed recursion limit attribute
197-
E0297, // refutable pattern in for loop binding
198224
E0298, // mismatched types between arms
199225
E0299, // mismatched types between arms
200226
E0300, // unexpanded macro

0 commit comments

Comments
 (0)