Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rust-call ICE in mir-inliner #98823

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
@@ -180,16 +180,20 @@ impl<'tcx> Inliner<'tcx> {
return Err("failed to normalize return type");
}
if callsite.fn_sig.abi() == Abi::RustCall {
let mut args = args.into_iter();
let _ = args.next(); // Skip `self` argument.
let arg_tuple_ty = args.next().unwrap().ty(&caller_body.local_decls, self.tcx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should contemplate banning the use of unwrap from the compiler 😄.

assert!(args.next().is_none());
let (arg_tuple, skipped_args) = match &args[..] {
[arg_tuple] => (arg_tuple, 0),
[_, arg_tuple] => (arg_tuple, 1),
_ => bug!("Expected `rust-call` to have 1 or 2 args"),
};

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

for (arg_ty, input) in arg_tuple_tys.iter().zip(callee_body.args_iter().skip(1)) {
for (arg_ty, input) in
arg_tuple_tys.iter().zip(callee_body.args_iter().skip(skipped_args))
{
let input_type = callee_body.local_decls[input].ty;
if !equal_up_to_regions(self.tcx, self.param_env, arg_ty, input_type) {
trace!(?arg_ty, ?input_type);
3 changes: 3 additions & 0 deletions src/test/ui/abi/rustcall-generic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// revisions: normal opt
// check-pass
//[opt] compile-flags: -Zmir-opt-level=3

#![feature(unboxed_closures)]

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