diff options
| author | Roxane <roxane.fruytier@hotmail.com> | 2021-08-27 09:00:50 -0400 |
|---|---|---|
| committer | Roxane <roxane.fruytier@hotmail.com> | 2021-08-27 09:00:50 -0400 |
| commit | 110a9b3b1ca1fddd34a3ecb8ec47fd8bb5ca7424 (patch) | |
| tree | 6d2c55d42177e04e6707401faa79e9f6e3d9a1e8 | |
| parent | 8fcfd6e136a31ea2a199b489e4df315a937fcd6a (diff) | |
| download | rust-110a9b3b1ca1fddd34a3ecb8ec47fd8bb5ca7424.tar.gz rust-110a9b3b1ca1fddd34a3ecb8ec47fd8bb5ca7424.zip | |
Add comment and fix fmt issue
| -rw-r--r-- | compiler/rustc_typeck/src/expr_use_visitor.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index e7c3a366cc4..7c99a37f6e7 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -268,10 +268,21 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { if def.variants.len() > 1 { needs_to_be_read = true; } else if let Some(variant) = def.variants.iter().next() { + // We need to handle `const` in match arms slightly differently + // as they are not processed the same way as other match arms. + // Consider this const `const OP1: Opcode = Opcode(0x1)`, this + // will generate a pattern with kind Path while if use Opcode(0x1) + // this will generate pattern TupleStruct and Lit. + // When dealing with pat kind Path we need to make additional checks + // to ensure we have all the info needed to make a decision on whether + // to borrow discr. + // // 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 { + if matches!(pat.kind, PatKind::Path(..)) + && variant.fields.len() > 0 + { needs_to_be_read = true; } } |
