Skip to content

Commit ee51314

Browse files
committed
Fix Option<Pin<_>> argument handling
1 parent 3c05a6b commit ee51314

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

macro/src/expand.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -527,16 +527,15 @@ fn expand_cxx_function_shim(efn: &ExternFn, types: &Types) -> TokenStream {
527527
true => quote_spanned!(span=> ::cxx::private::RustVec::from_mut(#var)),
528528
},
529529
inner if types.is_considered_improper_ctype(inner) => {
530-
let var = match ty.pinned {
531-
false => quote!(#var),
532-
true => quote_spanned!(span=> ::std::pin::Pin::into_inner_unchecked(#var)),
530+
let unpin = match ty.pinned {
531+
false => quote!(),
532+
true => quote_spanned!(span=> ::std::pin::Pin::into_inner_unchecked),
533533
};
534-
let to_ptr = match ty.mutable {
535-
false => {
536-
quote_spanned!(span=> |var| var as *const #inner as *const ::std::ffi::c_void)
537-
}
538-
true => quote_spanned!(span=> |var| var as *mut #inner as *mut ::std::ffi::c_void),
534+
let raw_mutability = match ty.mutable {
535+
false => quote_spanned!(span=> const),
536+
true => quote_spanned!(span=> mut),
539537
};
538+
let to_ptr = quote_spanned!(span=> |var| #unpin(var) as *#raw_mutability #inner as *#raw_mutability ::std::ffi::c_void);
540539
match (ty.option, ty.mutable) {
541540
(false, _) => quote_spanned!(span=> #[allow(clippy::redundant_closure_call)] (#to_ptr)(#var)),
542541
(true, false) => quote_spanned!(span=> #var.map_or(::std::ptr::null(), #to_ptr)),

0 commit comments

Comments
 (0)