Skip to content

Commit 110a9b3

Browse files
committed
Add comment and fix fmt issue
1 parent 8fcfd6e commit 110a9b3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

compiler/rustc_typeck/src/expr_use_visitor.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,21 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
268268
if def.variants.len() > 1 {
269269
needs_to_be_read = true;
270270
} else if let Some(variant) = def.variants.iter().next() {
271+
// We need to handle `const` in match arms slightly differently
272+
// as they are not processed the same way as other match arms.
273+
// Consider this const `const OP1: Opcode = Opcode(0x1)`, this
274+
// will generate a pattern with kind Path while if use Opcode(0x1)
275+
// this will generate pattern TupleStruct and Lit.
276+
// When dealing with pat kind Path we need to make additional checks
277+
// to ensure we have all the info needed to make a decision on whether
278+
// to borrow discr.
279+
//
271280
// If the pat kind is a Path we want to check whether the
272281
// variant contains at least one field. If that's the case,
273282
// we want to borrow discr.
274-
if matches!(pat.kind, PatKind::Path(..)) && variant.fields.len() > 0 {
283+
if matches!(pat.kind, PatKind::Path(..))
284+
&& variant.fields.len() > 0
285+
{
275286
needs_to_be_read = true;
276287
}
277288
}

0 commit comments

Comments
 (0)