#![allow(unused)]
// fn get_mut_undeleted_section_match(v: &mut Vec<usize>, at: usize) -> &mut usize {
// match v.get_mut(at) {
// Some(se) => {
// se
// }
// None => panic!("array was only {} long", v.len()),
// }
// }
fn get_nonzero_section(v: &mut Vec<usize>, at: usize) -> &mut usize {
if let Some(se) = v.get_mut(at) {
se
} else {
panic!("array was only {} long", v.len())
}
}
fn main() {}
It's so simple, we can tell that in the none branch, the mutable borrow is no longer needed (the match branch contains no reference members, so should not hold the borrow), but it wont allow the immutable borrow. I'm sure something like this has been reported before, but I don't know how to find the tracking issue.
(workaround: Take a copy of v.len()
at the beginning, but what I'm really interested in is finding the tracking issue. This wouldn't be adequiate if, for instance, you needed to run a complex query on v in the non-matching arm, based on what was in the arm.)