Skip to content

Commit 48a376d

Browse files
committed
rustc: Add long diagnostics for E0302
1 parent ab1723b commit 48a376d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/librustc/diagnostics.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ match Some(()) {
153153
}
154154
"##,
155155

156+
E0302: r##"
157+
Assignments are not allowed in pattern guards, because matching cannot have
158+
side effects. Side effects could alter the matched object or the environment
159+
on which the match depends in such a way, that the match would not be
160+
exhaustive. For instance, the following would not match any arm if assignments
161+
were allowed:
162+
163+
match Some(()) {
164+
None => { },
165+
option if { option = None; false } { },
166+
Some(_) => { } // When the previous match failed, the option became `None`.
167+
}
168+
"##,
169+
156170
E0303: r##"
157171
In certain cases it is possible for sub-bindings to violate memory safety.
158172
Updates to the borrow checker in a future version of Rust may remove this
@@ -238,7 +252,6 @@ register_diagnostics! {
238252
E0298, // mismatched types between arms
239253
E0299, // mismatched types between arms
240254
E0300, // unexpanded macro
241-
E0302, // cannot assign in a pattern guard
242255
E0304, // expected signed integer constant
243256
E0305, // expected constant
244257
E0306, // expected positive integer for repeat count

0 commit comments

Comments
 (0)