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:f9dca46218/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:f9dca46218/compiler/rustc_mir_transform/src/known_panics_lint.rs (L899-L902)
which is enough to prevent them from being const propagated.
This commit is contained in:
commit
5a4e83c2e0
@ -583,33 +583,21 @@ fn eval_rvalue(&mut self, rvalue: &Rvalue<'tcx>, dest: &Place<'tcx>) -> Option<(
|
|||||||
val.into()
|
val.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
Aggregate(ref kind, ref fields) => {
|
Aggregate(ref kind, ref fields) => Value::Aggregate {
|
||||||
// Do not const prop union fields as they can be
|
fields: fields
|
||||||
// made to produce values that don't match their
|
.iter()
|
||||||
// underlying layout's type (see ICE #121534).
|
.map(|field| self.eval_operand(field).map_or(Value::Uninit, Value::Immediate))
|
||||||
// If the last element of the `Adt` tuple
|
.collect(),
|
||||||
// is `Some` it indicates the ADT is a union
|
variant: match **kind {
|
||||||
if let AggregateKind::Adt(_, _, _, _, Some(_)) = **kind {
|
AggregateKind::Adt(_, variant, _, _, _) => variant,
|
||||||
return None;
|
AggregateKind::Array(_)
|
||||||
};
|
| AggregateKind::Tuple
|
||||||
Value::Aggregate {
|
| AggregateKind::RawPtr(_, _)
|
||||||
fields: fields
|
| AggregateKind::Closure(_, _)
|
||||||
.iter()
|
| AggregateKind::Coroutine(_, _)
|
||||||
.map(|field| {
|
| AggregateKind::CoroutineClosure(_, _) => VariantIdx::ZERO,
|
||||||
self.eval_operand(field).map_or(Value::Uninit, Value::Immediate)
|
},
|
||||||
})
|
},
|
||||||
.collect(),
|
|
||||||
variant: match **kind {
|
|
||||||
AggregateKind::Adt(_, variant, _, _, _) => variant,
|
|
||||||
AggregateKind::Array(_)
|
|
||||||
| AggregateKind::Tuple
|
|
||||||
| AggregateKind::RawPtr(_, _)
|
|
||||||
| AggregateKind::Closure(_, _)
|
|
||||||
| AggregateKind::Coroutine(_, _)
|
|
||||||
| AggregateKind::CoroutineClosure(_, _) => VariantIdx::ZERO,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Repeat(ref op, n) => {
|
Repeat(ref op, n) => {
|
||||||
trace!(?op, ?n);
|
trace!(?op, ?n);
|
||||||
@ -897,8 +885,9 @@ pub fn check<'tcx>(
|
|||||||
for (local, val) in cpv.can_const_prop.iter_enumerated_mut() {
|
for (local, val) in cpv.can_const_prop.iter_enumerated_mut() {
|
||||||
let ty = body.local_decls[local].ty;
|
let ty = body.local_decls[local].ty;
|
||||||
if ty.is_union() {
|
if ty.is_union() {
|
||||||
// Do not const prop unions as they can
|
// Unions are incompatible with the current implementation of
|
||||||
// ICE during layout calc
|
// const prop because Rust has no concept of an active
|
||||||
|
// variant of a union
|
||||||
*val = ConstPropMode::NoPropagation;
|
*val = ConstPropMode::NoPropagation;
|
||||||
} else {
|
} else {
|
||||||
match tcx.layout_of(param_env.and(ty)) {
|
match tcx.layout_of(param_env.and(ty)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user