Unraw idents

This commit is contained in:
2025-06-23 07:18:16 +10:00
parent 884acd71e1
commit c3fb3407c4
2 changed files with 39 additions and 27 deletions

View File

@@ -2,7 +2,7 @@ use crate::utils::{ffi_crate, syn_assert, syn_error};
use darling::FromMeta;
use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use syn::*;
use syn::{ext::IdentExt, *};
#[derive(Debug, FromMeta)]
pub struct Args {}
@@ -42,8 +42,8 @@ pub fn transform(_args: Args, mut item: Item) -> Result<TokenStream> {
fn generate_type(ty: &Ident) -> Result<TokenStream> {
let ffi = ffi_crate();
let fmt = quote!(::std::format!);
let name = LitStr::new(&format!("{ty}"), ty.span());
let cdecl_fmt = LitStr::new(&format!("struct {ty} {{}}"), ty.span());
let name = LitStr::new(&format!("{}", ty.unraw()), ty.span());
let cdecl_fmt = LitStr::new(&format!("struct {} {{}}", ty.unraw()), ty.span());
Ok(quote! {
unsafe impl #ffi::Type for #ty {
@@ -79,8 +79,8 @@ fn generate_cdef_structure(str: &mut ItemStruct) -> Result<TokenStream> {
let build = generate_build_cdef(&to_cfields(&mut str.fields)?)?;
Ok(quote! {
unsafe impl #ffi::CDef for #ty {
fn build(b: &mut #ffi::CDefBuilder) { #build }
unsafe impl #ffi::Cdef for #ty {
fn build(b: &mut #ffi::CdefBuilder) { #build }
}
})
}
@@ -104,8 +104,8 @@ fn generate_cdef_enum(enu: &mut ItemEnum) -> Result<TokenStream> {
.collect::<Result<Vec<_>>>()?;
Ok(quote! {
unsafe impl #ffi::CDef for #ty {
fn build(b: &mut #ffi::CDefBuilder) {
unsafe impl #ffi::Cdef for #ty {
fn build(b: &mut #ffi::CdefBuilder) {
b.field::<::std::ffi::c_int>("__tag").inner_union(|b| { #(#build)* });
}
}
@@ -133,7 +133,7 @@ fn to_cfields(fields: &mut Fields) -> Result<Vec<CField>> {
.map(|(i, field)| {
Ok(CField {
name: match field.ident {
Some(ref name) => format!("{name}"),
Some(ref name) => format!("{}", name.unraw()),
None => format!("__{i}"),
},
ty: field.ty.clone(),