Skip to content

Commit aebbece

Browse files
committed
Handle rust-call abi without self argument
Fixes rust-lang#1236
1 parent daf79b5 commit aebbece

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

example/std_example.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
#![feature(core_intrinsics, generators, generator_trait, is_sorted, repr_simd)]
1+
#![feature(
2+
core_intrinsics,
3+
generators,
4+
generator_trait,
5+
is_sorted,
6+
repr_simd,
7+
tuple_trait,
8+
unboxed_closures
9+
)]
210

311
#[cfg(target_arch = "x86_64")]
412
use std::arch::x86_64::*;
@@ -157,6 +165,8 @@ fn main() {
157165
foo(I64X2(0, 0));
158166

159167
transmute_fat_pointer();
168+
169+
rust_call_abi();
160170
}
161171

162172
fn panic(_: u128) {
@@ -174,6 +184,13 @@ fn transmute_fat_pointer() -> TwoPtrs {
174184
unsafe { transmute::<_, TwoPtrs>("true !") }
175185
}
176186

187+
extern "rust-call" fn rust_call_abi_callee<T: std::marker::Tuple>(_: T) {}
188+
189+
fn rust_call_abi() {
190+
rust_call_abi_callee(());
191+
rust_call_abi_callee((1, 2));
192+
}
193+
177194
#[repr(simd)]
178195
struct I64X2(i64, i64);
179196

src/abi/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,22 @@ pub(crate) fn codegen_terminator_call<'tcx>(
445445

446446
// Unpack arguments tuple for closures
447447
let mut args = if fn_sig.abi() == Abi::RustCall {
448-
assert_eq!(args.len(), 2, "rust-call abi requires two arguments");
449-
let self_arg = codegen_call_argument_operand(fx, &args[0]);
450-
let pack_arg = codegen_call_argument_operand(fx, &args[1]);
448+
let (self_arg, pack_arg) = match args {
449+
[pack_arg] => (None, codegen_call_argument_operand(fx, pack_arg)),
450+
[self_arg, pack_arg] => (
451+
Some(codegen_call_argument_operand(fx, self_arg)),
452+
codegen_call_argument_operand(fx, pack_arg),
453+
),
454+
_ => panic!("rust-call abi requires one or two arguments"),
455+
};
451456

452457
let tupled_arguments = match pack_arg.value.layout().ty.kind() {
453458
ty::Tuple(ref tupled_arguments) => tupled_arguments,
454459
_ => bug!("argument to function with \"rust-call\" ABI is not a tuple"),
455460
};
456461

457462
let mut args = Vec::with_capacity(1 + tupled_arguments.len());
458-
args.push(self_arg);
463+
args.extend(self_arg);
459464
for i in 0..tupled_arguments.len() {
460465
args.push(CallArgument {
461466
value: pack_arg.value.value_field(fx, FieldIdx::new(i)),

0 commit comments

Comments
 (0)