-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.
Description
Due to rust-lang/rust#15989, it isn't possible to assign/mutate in pattern guards. However, assignment/mutation of variables local to the pattern guard should be perfectly safe.
As reported on reddit: https://pay.reddit.com/r/rust/comments/2ztiag/cannot_mutably_borrow_in_a_pattern_guard/ by qthree:
This code is failing: http://is.gd/cAYb5r But that's ok: http://is.gd/7pF28q
For completeness, the failing code is:
fn main() {
let v = vec!["1".to_string(), "2".to_string(), "3".to_string()];
let q = match Some(&v) {
Some(iv) if iv.iter().any(|x| &x[..]=="2") => true,
_ => false
};
}
However, the following works:
fn main() {
let v = vec!["1".to_string(), "2".to_string(), "3".to_string()];
let q = match Some(&v) {
Some(iv) if (|| iv.iter().any(|x| &x[..]=="2"))() => true,
_ => false
};
}
Kha and mpgarate
Metadata
Metadata
Assignees
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.