Range PatKind implies discr should be read

This commit is contained in:
Roxane 2021-07-28 10:35:48 -04:00
parent eba3228b2a
commit 9829efb892
2 changed files with 20 additions and 3 deletions

View file

@ -267,12 +267,15 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
}
}
}
PatKind::Lit(_) => {
// If the PatKind is a Lit then we want
PatKind::Lit(_) | PatKind::Range(..) => {
// If the PatKind is a Lit or a Range then we want
// to borrow discr.
needs_to_be_read = true;
}
_ => {}
_ => {
// If the PatKind is Or, Box, Slice or Ref, the decision is made later
// as these patterns contains subpatterns
}
}
}));
}

View file

@ -0,0 +1,14 @@
// run-pass
// edition:2021
pub fn foo() {
let ref_x_ck = 123;
let _y = || match ref_x_ck {
2_000_000..=3_999_999 => { println!("A")}
_ => { println!("B")}
};
}
fn main() {
foo();
}