Skip to content

Commit 3406319

Browse files
Fix rust-call ICE in mir-inliner
1 parent 750d6f8 commit 3406319

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

compiler/rustc_mir_transform/src/inline.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,20 @@ impl<'tcx> Inliner<'tcx> {
180180
return Err("failed to normalize return type");
181181
}
182182
if callsite.fn_sig.abi() == Abi::RustCall {
183-
let mut args = args.into_iter();
184-
let _ = args.next(); // Skip `self` argument.
185-
let arg_tuple_ty = args.next().unwrap().ty(&caller_body.local_decls, self.tcx);
186-
assert!(args.next().is_none());
183+
let (arg_tuple, skipped_args) = match &args[..] {
184+
[arg_tuple] => (arg_tuple, 0),
185+
[_, arg_tuple] => (arg_tuple, 1),
186+
_ => bug!("Expected `rust-call` to have 1 or 2 args"),
187+
};
187188

189+
let arg_tuple_ty = arg_tuple.ty(&caller_body.local_decls, self.tcx);
188190
let ty::Tuple(arg_tuple_tys) = arg_tuple_ty.kind() else {
189191
bug!("Closure arguments are not passed as a tuple");
190192
};
191193

192-
for (arg_ty, input) in arg_tuple_tys.iter().zip(callee_body.args_iter().skip(1)) {
194+
for (arg_ty, input) in
195+
arg_tuple_tys.iter().zip(callee_body.args_iter().skip(skipped_args))
196+
{
193197
let input_type = callee_body.local_decls[input].ty;
194198
if !equal_up_to_regions(self.tcx, self.param_env, arg_ty, input_type) {
195199
trace!(?arg_ty, ?input_type);

src/test/ui/abi/rustcall-generic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// revisions: normal opt
12
// check-pass
3+
//[opt] compile-flags: -Zmir-opt-level=3
4+
25
#![feature(unboxed_closures)]
36

47
extern "rust-call" fn foo<T>(_: T) {}

0 commit comments

Comments
 (0)