Skip to content

Commit 5a4e83c

Browse files
authored
Rollup merge of #124550 - gurry:remove-redundant-code, r=oli-obk
Remove redundant union check in `KnownPanicsLint` const prop Removes the below check which prevents unions from being const propagated:https://github.com/rust-lang/rust/blob/f9dca46218d4b8efa062aec4fd0820cbb4942aa2/compiler/rustc_mir_transform/src/known_panics_lint.rs#L587-L594 It is not needed because after PR #124504 we mark unions as `NoPropagation` over here: https://github.com/rust-lang/rust/blob/f9dca46218d4b8efa062aec4fd0820cbb4942aa2/compiler/rustc_mir_transform/src/known_panics_lint.rs#L899-L902 which is enough to prevent them from being const propagated.
2 parents 784316e + 741d40f commit 5a4e83c

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

compiler/rustc_mir_transform/src/known_panics_lint.rs

+18-29
Original file line numberDiff line numberDiff line change
@@ -583,33 +583,21 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
583583
val.into()
584584
}
585585

586-
Aggregate(ref kind, ref fields) => {
587-
// Do not const prop union fields as they can be
588-
// made to produce values that don't match their
589-
// underlying layout's type (see ICE #121534).
590-
// If the last element of the `Adt` tuple
591-
// is `Some` it indicates the ADT is a union
592-
if let AggregateKind::Adt(_, _, _, _, Some(_)) = **kind {
593-
return None;
594-
};
595-
Value::Aggregate {
596-
fields: fields
597-
.iter()
598-
.map(|field| {
599-
self.eval_operand(field).map_or(Value::Uninit, Value::Immediate)
600-
})
601-
.collect(),
602-
variant: match **kind {
603-
AggregateKind::Adt(_, variant, _, _, _) => variant,
604-
AggregateKind::Array(_)
605-
| AggregateKind::Tuple
606-
| AggregateKind::RawPtr(_, _)
607-
| AggregateKind::Closure(_, _)
608-
| AggregateKind::Coroutine(_, _)
609-
| AggregateKind::CoroutineClosure(_, _) => VariantIdx::ZERO,
610-
},
611-
}
612-
}
586+
Aggregate(ref kind, ref fields) => Value::Aggregate {
587+
fields: fields
588+
.iter()
589+
.map(|field| self.eval_operand(field).map_or(Value::Uninit, Value::Immediate))
590+
.collect(),
591+
variant: match **kind {
592+
AggregateKind::Adt(_, variant, _, _, _) => variant,
593+
AggregateKind::Array(_)
594+
| AggregateKind::Tuple
595+
| AggregateKind::RawPtr(_, _)
596+
| AggregateKind::Closure(_, _)
597+
| AggregateKind::Coroutine(_, _)
598+
| AggregateKind::CoroutineClosure(_, _) => VariantIdx::ZERO,
599+
},
600+
},
613601

614602
Repeat(ref op, n) => {
615603
trace!(?op, ?n);
@@ -897,8 +885,9 @@ impl CanConstProp {
897885
for (local, val) in cpv.can_const_prop.iter_enumerated_mut() {
898886
let ty = body.local_decls[local].ty;
899887
if ty.is_union() {
900-
// Do not const prop unions as they can
901-
// ICE during layout calc
888+
// Unions are incompatible with the current implementation of
889+
// const prop because Rust has no concept of an active
890+
// variant of a union
902891
*val = ConstPropMode::NoPropagation;
903892
} else {
904893
match tcx.layout_of(param_env.and(ty)) {

0 commit comments

Comments
 (0)