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(_) => { PatKind::Lit(_) | PatKind::Range(..) => {
// If the PatKind is a Lit then we want // If the PatKind is a Lit or a Range then we want
// to borrow discr. // to borrow discr.
needs_to_be_read = true; 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();
}