Fix handling 'unsigned int' type in generated thunk impls.
Before this CL, `format_cc_type` would take any C++ type name and try to
`make_ident` out of the whole type name. This would panic for
multi-word typenames like `unsigned int` or `long long`.
PiperOrigin-RevId: 419833386
diff --git a/rs_bindings_from_cc/src_code_gen.rs b/rs_bindings_from_cc/src_code_gen.rs
index 4e05033..a7ece58 100644
--- a/rs_bindings_from_cc/src_code_gen.rs
+++ b/rs_bindings_from_cc/src_code_gen.rs
@@ -691,12 +691,12 @@
let nested_type = format_cc_type(&ty.type_args[0], ir)?;
Ok(quote! {#nested_type &})
}
- ident => {
+ cc_type_name => {
if !ty.type_args.is_empty() {
bail!("Type not yet supported: {:?}", ty);
}
- let ident = make_ident(ident);
- Ok(quote! {#ident #const_fragment})
+ let idents = cc_type_name.split_whitespace().map(make_ident);
+ Ok(quote! {#( #idents )* #const_fragment})
}
}
} else {
@@ -1055,6 +1055,21 @@
}
#[test]
+ fn test_unsigned_int_in_thunk_impls() -> Result<()> {
+ let ir = ir_from_cc("inline void foo(unsigned int i) {} ")?;
+ let rs_api_impl = generate_rs_api_impl(&ir)?;
+ assert_cc_matches!(
+ rs_api_impl,
+ quote! {
+ extern "C" void __rust_thunk___Z3fooj(unsigned int i) {
+ foo(i);
+ }
+ }
+ );
+ Ok(())
+ }
+
+ #[test]
fn test_record_static_methods_qualify_call_in_thunk() -> Result<()> {
let ir = ir_from_cc(&tokens_to_string(quote! {
struct SomeStruct {