Skip to content

Commit c47e0e1

Browse files
authored
Rollup merge of #154502 - RalfJung:interpret-untuple-check, r=oli-obk
interpret: ensure that untupled arguments are actually tuples Something seems very wrong if they are not. ;)
2 parents 2645f0d + ad298d5 commit c47e0e1

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

  • compiler/rustc_const_eval/src/interpret

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
6060
}
6161

6262
/// Helper function for argument untupling.
63-
pub(super) fn fn_arg_field(
63+
fn fn_arg_project_field(
6464
&self,
6565
arg: &FnArg<'tcx, M::Provenance>,
6666
field: FieldIdx,
@@ -655,12 +655,17 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
655655
if caller_abi == ExternAbi::RustCall && !args.is_empty() {
656656
// Untuple
657657
let (untuple_arg, args) = args.split_last().unwrap();
658+
let ty::Tuple(untuple_fields) = untuple_arg.layout().ty.kind() else {
659+
span_bug!(self.cur_span(), "untuple argument must be a tuple")
660+
};
658661
trace!("init_fn_call: Will pass last argument by untupling");
659662
Cow::from(
660663
args.iter()
664+
// The regular arguments.
661665
.map(|a| interp_ok(a.clone()))
662-
.chain((0..untuple_arg.layout().fields.count()).map(|i| {
663-
self.fn_arg_field(untuple_arg, FieldIdx::from_usize(i))
666+
// The fields of the untupled argument.
667+
.chain((0..untuple_fields.len()).map(|i| {
668+
self.fn_arg_project_field(untuple_arg, FieldIdx::from_usize(i))
664669
}))
665670
.collect::<InterpResult<'_, Vec<_>>>()?,
666671
)

0 commit comments

Comments
 (0)