Skip to content

Commit 268bb46

Browse files
committed
CTFE: extra assertions for Aggregate rvalues; remove unnecessarily eager special case
1 parent 35f74c2 commit 268bb46

File tree

1 file changed

+9
-7
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+9
-7
lines changed

compiler/rustc_const_eval/src/interpret/step.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
197197
}
198198

199199
Aggregate(ref kind, ref operands) => {
200+
// active_field_index is for union initialization.
200201
let (dest, active_field_index) = match **kind {
201202
mir::AggregateKind::Adt(adt_def, variant_index, _, _, active_field_index) => {
202203
self.write_discriminant(variant_index, &dest)?;
203204
if adt_def.is_enum() {
204-
(self.place_downcast(&dest, variant_index)?, active_field_index)
205+
assert!(active_field_index.is_none());
206+
(self.place_downcast(&dest, variant_index)?, None)
205207
} else {
208+
if active_field_index.is_some() {
209+
assert_eq!(operands.len(), 1);
210+
}
206211
(dest, active_field_index)
207212
}
208213
}
@@ -211,12 +216,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
211216

212217
for (i, operand) in operands.iter().enumerate() {
213218
let op = self.eval_operand(operand, None)?;
214-
// Ignore zero-sized fields.
215-
if !op.layout.is_zst() {
216-
let field_index = active_field_index.unwrap_or(i);
217-
let field_dest = self.place_field(&dest, field_index)?;
218-
self.copy_op(&op, &field_dest)?;
219-
}
219+
let field_index = active_field_index.unwrap_or(i);
220+
let field_dest = self.place_field(&dest, field_index)?;
221+
self.copy_op(&op, &field_dest)?;
220222
}
221223
}
222224

0 commit comments

Comments
 (0)