Improve consistency in LowerIntrinsics
.
In some cases `target` and `arg` are obtained fallibly, and in some cases they are obtained infallibly. This commit changes them all to infallible.
This commit is contained in:
parent
751c8b481b
commit
5445953659
1 changed files with 63 additions and 62 deletions
|
@ -35,7 +35,7 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
sym::forget => {
|
||||
if let Some(target) = *target {
|
||||
let target = target.unwrap();
|
||||
block.statements.push(Statement {
|
||||
source_info: terminator.source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
|
@ -49,7 +49,6 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
}
|
||||
sym::copy_nonoverlapping => {
|
||||
let target = target.unwrap();
|
||||
let Ok([src, dst, count]) = take_array(args) else {
|
||||
|
@ -121,7 +120,7 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
|
||||
if let Some(target) = *target {
|
||||
let target = target.unwrap();
|
||||
let Ok([lhs, rhs]) = take_array(args) else {
|
||||
bug!("Wrong arguments for {} intrinsic", intrinsic.name);
|
||||
};
|
||||
|
@ -140,9 +139,8 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
}
|
||||
sym::size_of | sym::min_align_of => {
|
||||
if let Some(target) = *target {
|
||||
let target = target.unwrap();
|
||||
let tp_ty = generic_args.type_at(0);
|
||||
let null_op = match intrinsic.name {
|
||||
sym::size_of => NullOp::SizeOf,
|
||||
|
@ -158,7 +156,6 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
}
|
||||
sym::read_via_copy => {
|
||||
let Ok([arg]) = take_array(args) else {
|
||||
span_bug!(terminator.source_info.span, "Wrong number of arguments");
|
||||
|
@ -219,7 +216,14 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
sym::discriminant_value => {
|
||||
if let (Some(target), Some(arg)) = (*target, args[0].node.place()) {
|
||||
let target = target.unwrap();
|
||||
let Ok([arg]) = take_array(args) else {
|
||||
span_bug!(
|
||||
terminator.source_info.span,
|
||||
"Wrong arguments for discriminant_value intrinsic"
|
||||
);
|
||||
};
|
||||
let arg = arg.node.place().unwrap();
|
||||
let arg = tcx.mk_place_deref(arg);
|
||||
block.statements.push(Statement {
|
||||
source_info: terminator.source_info,
|
||||
|
@ -230,7 +234,6 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
}
|
||||
sym::offset => {
|
||||
let target = target.unwrap();
|
||||
let Ok([ptr, delta]) = take_array(args) else {
|
||||
|
@ -267,7 +270,6 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||
Rvalue::Cast(CastKind::Transmute, arg.node, dst_ty),
|
||||
))),
|
||||
});
|
||||
|
||||
if let Some(target) = *target {
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
} else {
|
||||
|
@ -299,7 +301,6 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
|||
Rvalue::Aggregate(Box::new(kind), fields.into()),
|
||||
))),
|
||||
});
|
||||
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
sym::ptr_metadata => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue