Skip to content

Commit 78f3f5c

Browse files
committed
Remove redundant union check in `KnownPanicsLint const prop
because we are already marking unions `NoPropagation` in `CanConstProp::check()`. That is enough to prevent any attempts at const propagating unions and this second check is not needed. Also improve a comment in `CanConstProp::check()`.
1 parent f9dca46 commit 78f3f5c

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

compiler/rustc_mir_transform/src/known_panics_lint.rs

+17-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,8 @@ 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 const prop because
889+
// Rust has no conpcept of the active variant of a union
902890
*val = ConstPropMode::NoPropagation;
903891
} else {
904892
match tcx.layout_of(param_env.and(ty)) {

0 commit comments

Comments
 (0)