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. ;)
This commit is contained in:
Ralf Jung
2026-03-28 13:15:54 +01:00
committed by GitHub
@@ -60,7 +60,7 @@ pub fn copy_fn_args(args: &[FnArg<'tcx, M::Provenance>]) -> Vec<OpTy<'tcx, M::Pr
}
/// Helper function for argument untupling.
pub(super) fn fn_arg_field(
fn fn_arg_project_field(
&self,
arg: &FnArg<'tcx, M::Provenance>,
field: FieldIdx,
@@ -655,12 +655,17 @@ pub(super) fn init_fn_call(
if caller_abi == ExternAbi::RustCall && !args.is_empty() {
// Untuple
let (untuple_arg, args) = args.split_last().unwrap();
let ty::Tuple(untuple_fields) = untuple_arg.layout().ty.kind() else {
span_bug!(self.cur_span(), "untuple argument must be a tuple")
};
trace!("init_fn_call: Will pass last argument by untupling");
Cow::from(
args.iter()
// The regular arguments.
.map(|a| interp_ok(a.clone()))
.chain((0..untuple_arg.layout().fields.count()).map(|i| {
self.fn_arg_field(untuple_arg, FieldIdx::from_usize(i))
// The fields of the untupled argument.
.chain((0..untuple_fields.len()).map(|i| {
self.fn_arg_project_field(untuple_arg, FieldIdx::from_usize(i))
}))
.collect::<InterpResult<'_, Vec<_>>>()?,
)