Skip to content

Commit 63a0e4e

Browse files
committed
Combine Kind verification into expand_type_alias_verify
1 parent 445dcc6 commit 63a0e4e

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

macro/src/expand.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ fn expand(ffi: Module, apis: &[Api], types: &Types) -> TokenStream {
5656
}
5757
Api::TypeAlias(alias) => {
5858
expanded.extend(expand_type_alias(alias));
59-
hidden.extend(expand_type_alias_verify(namespace, alias));
60-
let ident = &alias.ident;
61-
if types.required_trivial_aliases.contains(ident) {
62-
hidden.extend(expand_type_alias_kind_trivial_verify(alias));
63-
}
59+
hidden.extend(expand_type_alias_verify(namespace, alias, types));
6460
}
6561
}
6662
}
@@ -671,29 +667,30 @@ fn expand_type_alias(alias: &TypeAlias) -> TokenStream {
671667
}
672668
}
673669

674-
fn expand_type_alias_verify(namespace: &Namespace, alias: &TypeAlias) -> TokenStream {
670+
fn expand_type_alias_verify(
671+
namespace: &Namespace,
672+
alias: &TypeAlias,
673+
types: &Types,
674+
) -> TokenStream {
675675
let ident = &alias.ident;
676676
let type_id = type_id(namespace, ident);
677677
let begin_span = alias.type_token.span;
678678
let end_span = alias.semi_token.span;
679679
let begin = quote_spanned!(begin_span=> ::cxx::private::verify_extern_type::<);
680680
let end = quote_spanned!(end_span=> >);
681681

682-
quote! {
682+
let mut verify = quote! {
683683
const _: fn() = #begin #ident, #type_id #end;
684-
}
685-
}
686-
687-
fn expand_type_alias_kind_trivial_verify(type_alias: &TypeAlias) -> TokenStream {
688-
let ident = &type_alias.ident;
689-
let begin_span = type_alias.type_token.span;
690-
let end_span = type_alias.semi_token.span;
691-
let begin = quote_spanned!(begin_span=> ::cxx::private::verify_extern_kind::<);
692-
let end = quote_spanned!(end_span=> >);
684+
};
693685

694-
quote! {
695-
const _: fn() = #begin #ident, ::cxx::kind::Trivial #end;
686+
if types.required_trivial_aliases.contains(&alias.ident) {
687+
let begin = quote_spanned!(begin_span=> ::cxx::private::verify_extern_kind::<);
688+
verify.extend(quote! {
689+
const _: fn() = #begin #ident, ::cxx::kind::Trivial #end;
690+
});
696691
}
692+
693+
verify
697694
}
698695

699696
fn type_id(namespace: &Namespace, ident: &Ident) -> TokenStream {

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ pub type Vector<T> = CxxVector<T>;
422422
#[doc(hidden)]
423423
pub mod private {
424424
pub use crate::cxx_vector::VectorElement;
425-
pub use crate::extern_type::verify_extern_kind;
426-
pub use crate::extern_type::verify_extern_type;
425+
pub use crate::extern_type::{verify_extern_kind, verify_extern_type};
427426
pub use crate::function::FatFunction;
428427
pub use crate::opaque::Opaque;
429428
pub use crate::result::{r#try, Result};

0 commit comments

Comments
 (0)