Skip to content

Commit ab1723b

Browse files
committed
rustc: Add long diagnostics for E0301
1 parent 9c6f4b6 commit ab1723b

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
@@ -139,6 +139,20 @@ for item in xs {
139139
}
140140
"##,
141141

142+
E0301: r##"
143+
Mutable borrows are not allowed in pattern guards, because matching cannot have
144+
side effects. Side effects could alter the matched object or the environment
145+
on which the match depends in such a way, that the match would not be
146+
exhaustive. For instance, the following would not match any arm if mutable
147+
borrows were allowed:
148+
149+
match Some(()) {
150+
None => { },
151+
option if option.take().is_none() => { /* impossible, option is `Some` */ },
152+
Some(_) => { } // When the previous match failed, the option became `None`.
153+
}
154+
"##,
155+
142156
E0303: r##"
143157
In certain cases it is possible for sub-bindings to violate memory safety.
144158
Updates to the borrow checker in a future version of Rust may remove this
@@ -224,7 +238,6 @@ register_diagnostics! {
224238
E0298, // mismatched types between arms
225239
E0299, // mismatched types between arms
226240
E0300, // unexpanded macro
227-
E0301, // cannot mutable borrow in a pattern guard
228241
E0302, // cannot assign in a pattern guard
229242
E0304, // expected signed integer constant
230243
E0305, // expected constant

0 commit comments

Comments
 (0)