1
Fork 0

Add missing const edge case

This commit is contained in:
Roxane 2021-08-26 20:56:45 -04:00
parent 7b0e554ee2
commit 8fcfd6e136
3 changed files with 67 additions and 0 deletions

View file

@ -267,6 +267,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
if let ty::Adt(def, _) = place_ty.kind() {
if def.variants.len() > 1 {
needs_to_be_read = true;
} else if let Some(variant) = def.variants.iter().next() {
// If the pat kind is a Path we want to check whether the
// variant contains at least one field. If that's the case,
// we want to borrow discr.
if matches!(pat.kind, PatKind::Path(..)) && variant.fields.len() > 0 {
needs_to_be_read = true;
}
}
} else {
// If it is not ty::Adt, then it should be read