Skip to content

Commit 06c8ab7

Browse files
committed
Fix Option<Pin<_>> return handling
1 parent 957e0b9 commit 06c8ab7

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

macro/src/expand.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,12 +659,24 @@ fn expand_cxx_function_shim(efn: &ExternFn, types: &Types) -> TokenStream {
659659
},
660660
inner if types.is_considered_improper_ctype(inner) => {
661661
let mutability = ty.mutability;
662-
let deref_mut = quote_spanned!(span=> &#mutability *#call.cast());
663-
match ty.pinned {
664-
false => deref_mut,
662+
let cast_call = quote_spanned!(span=> let __ptr = #call.cast());
663+
let unpinned = quote_spanned!(span=> &#mutability *__ptr);
664+
let maybe_pinned = match ty.pinned {
665+
false => unpinned,
665666
true => {
666-
quote_spanned!(span=> ::std::pin::Pin::new_unchecked(#deref_mut))
667+
quote_spanned!(span=> ::std::pin::Pin::new_unchecked(#unpinned))
667668
}
669+
};
670+
match ty.option {
671+
false => quote_spanned!(span=> #cast_call; #maybe_pinned),
672+
true => quote_spanned! {span=>
673+
#cast_call;
674+
if __ptr.is_null() {
675+
::std::option::Option::None
676+
} else {
677+
::std::option::Option::Some(#maybe_pinned)
678+
}
679+
},
668680
}
669681
}
670682
_ => call,

0 commit comments

Comments
 (0)