diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-03-14 22:24:28 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-03-14 22:24:28 -0700 |
| commit | e7c6ad89cfd937d741b9d256e950ec0de96a7142 (patch) | |
| tree | 64967ced37821935138e1f09ff92a21f231868c9 /compiler/rustc_mir_transform/src | |
| parent | 87696fd5a1a1b7cd75cd9a66896deae0ab56cfb5 (diff) | |
| download | rust-e7c6ad89cfd937d741b9d256e950ec0de96a7142.tar.gz rust-e7c6ad89cfd937d741b9d256e950ec0de96a7142.zip | |
Improved implementation and comments after code review feedback
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/lower_intrinsics.rs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/compiler/rustc_mir_transform/src/lower_intrinsics.rs b/compiler/rustc_mir_transform/src/lower_intrinsics.rs index 151fff27d14..5d7382305ae 100644 --- a/compiler/rustc_mir_transform/src/lower_intrinsics.rs +++ b/compiler/rustc_mir_transform/src/lower_intrinsics.rs @@ -150,7 +150,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics { } } sym::read_via_copy => { - let Ok([arg]) = <[_; 1]>::try_from(std::mem::take(args)) else { + let [arg] = args.as_slice() else { span_bug!(terminator.source_info.span, "Wrong number of arguments"); }; let derefed_place = @@ -159,18 +159,23 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics { } else { span_bug!(terminator.source_info.span, "Only passing a local is supported"); }; - block.statements.push(Statement { - source_info: terminator.source_info, - kind: StatementKind::Assign(Box::new(( - *destination, - Rvalue::Use(Operand::Copy(derefed_place)), - ))), - }); - if let Some(target) = *target { - terminator.kind = TerminatorKind::Goto { target }; - } else { - // Reading something uninhabited means this is unreachable. - terminator.kind = TerminatorKind::Unreachable; + terminator.kind = match *target { + None => { + // No target means this read something uninhabited, + // so it must be unreachable, and we don't need to + // preserve the assignment either. + TerminatorKind::Unreachable + } + Some(target) => { + block.statements.push(Statement { + source_info: terminator.source_info, + kind: StatementKind::Assign(Box::new(( + *destination, + Rvalue::Use(Operand::Copy(derefed_place)), + ))), + }); + TerminatorKind::Goto { target } + } } } sym::discriminant_value => { |
