mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 10:33:34 +00:00
Rollup merge of #87554 - sexxi-goose:fix-issue-87426, r=nikomatsakis
2229: Discr should be read when PatKind is Range This PR fixes an issue related to pattern matching in closures when Edition 2021 is enabled. - If any of the patterns the discr is being matched on is `PatKind::Range` then the discr should be read r? ```@nikomatsakis``` Closes https://github.com/rust-lang/rust/issues/87426
This commit is contained in:
commit
aaef1a1649
@ -267,12 +267,21 @@ 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;
|
||||
}
|
||||
_ => {}
|
||||
PatKind::Or(_)
|
||||
| PatKind::Box(_)
|
||||
| PatKind::Slice(..)
|
||||
| PatKind::Ref(..)
|
||||
| PatKind::Wild => {
|
||||
// If the PatKind is Or, Box, Slice or Ref, the decision is made later
|
||||
// as these patterns contains subpatterns
|
||||
// If the PatKind is Wild, the decision is made based on the other patterns being
|
||||
// examined
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
14
src/test/ui/closures/2229_closure_analysis/issue-87426.rs
Normal file
14
src/test/ui/closures/2229_closure_analysis/issue-87426.rs
Normal 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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user