Skip to content

Commit 906e096

Browse files
authored
Fix generating bindings for async methods (#1279)
Use `&self` for the first argument, not `self_: ...`, by hooking into blocks that previously were checking just for method, not also async methods.
1 parent e067cc1 commit 906e096

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

crates/rust/src/interface.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ impl<'i> InterfaceGenerator<'i> {
177177
private: true,
178178
..Default::default()
179179
};
180-
if let FunctionKind::Method(_) = &func.kind {
181-
sig.self_arg = Some("&self".into());
182-
sig.self_is_first_param = true;
183-
}
180+
sig.update_for_func(&func);
184181
self.print_signature(func, true, &sig);
185182
self.src.push_str(";\n");
186183
let trait_method = mem::replace(&mut self.src, prev);
@@ -713,10 +710,7 @@ pub mod vtable{ordinal} {{
713710
let name = to_upper_camel_case(name);
714711
uwriteln!(self.src, "impl {name} {{");
715712
sig.use_item_name = true;
716-
if let FunctionKind::Method(_) = &func.kind {
717-
sig.self_arg = Some("&self".into());
718-
sig.self_is_first_param = true;
719-
}
713+
sig.update_for_func(&func);
720714
}
721715
self.src.push_str("#[allow(unused_unsafe, clippy::all)]\n");
722716
let params = self.print_signature(func, async_, &sig);
@@ -1219,10 +1213,7 @@ unsafe fn call_import(params: *mut u8, results: *mut u8) -> u32 {{
12191213
private: true,
12201214
..Default::default()
12211215
};
1222-
if let FunctionKind::Method(_) = &func.kind {
1223-
sig.self_arg = Some("&self".into());
1224-
sig.self_is_first_param = true;
1225-
}
1216+
sig.update_for_func(&func);
12261217
self.src.push_str("#[allow(unused_variables)]\n");
12271218
self.print_signature(func, true, &sig);
12281219
self.src.push_str("{ unreachable!() }\n");

crates/rust/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,15 @@ struct FnSig {
16481648
self_is_first_param: bool,
16491649
}
16501650

1651+
impl FnSig {
1652+
fn update_for_func(&mut self, func: &Function) {
1653+
if let FunctionKind::Method(_) | FunctionKind::AsyncMethod(_) = &func.kind {
1654+
self.self_arg = Some("&self".into());
1655+
self.self_is_first_param = true;
1656+
}
1657+
}
1658+
}
1659+
16511660
pub fn to_rust_ident(name: &str) -> String {
16521661
match name {
16531662
// Escape Rust keywords.

0 commit comments

Comments
 (0)