Always capture slice when pattern requires checking the length
This commit is contained in:
parent
9d871b0617
commit
ace794c6d7
3 changed files with 209 additions and 91 deletions
|
@ -438,12 +438,19 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
// 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
|
||||
PatKind::Slice(lhs, wild, rhs) => {
|
||||
// We don't need to test the length if the pattern is `[..]`
|
||||
if matches!((lhs, wild, rhs), (&[], Some(_), &[]))
|
||||
// Arrays have a statically known size, so
|
||||
// there is no need to read their length
|
||||
|| discr_place.place.base_ty.is_array()
|
||||
{
|
||||
} else {
|
||||
needs_to_be_read = true;
|
||||
}
|
||||
}
|
||||
PatKind::Or(_) | PatKind::Box(_) | PatKind::Ref(..) | PatKind::Wild => {
|
||||
// If the PatKind is Or, Box, 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue