diff options
| author | Roxane <roxane.fruytier@hotmail.com> | 2021-07-28 10:35:48 -0400 |
|---|---|---|
| committer | Roxane <roxane.fruytier@hotmail.com> | 2021-07-28 10:52:39 -0400 |
| commit | 9829efb892f7c249f2c889722a098e6a9b34f3fb (patch) | |
| tree | e2dca4173767ff30aa35fc30b86f5f441a98b518 | |
| parent | eba3228b2a9875d268ff3990903d04e19f6cdb0c (diff) | |
| download | rust-9829efb892f7c249f2c889722a098e6a9b34f3fb.tar.gz rust-9829efb892f7c249f2c889722a098e6a9b34f3fb.zip | |
Range PatKind implies discr should be read
| -rw-r--r-- | compiler/rustc_typeck/src/expr_use_visitor.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/closures/2229_closure_analysis/issue-87426.rs | 14 |
2 files changed, 20 insertions, 3 deletions
diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index 6c76a8960bb..201804f9fc4 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -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 + } } })); } diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87426.rs b/src/test/ui/closures/2229_closure_analysis/issue-87426.rs new file mode 100644 index 00000000000..4a6eb5154c1 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/issue-87426.rs @@ -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(); +} \ No newline at end of file |
