update rust ast

This commit is contained in:
2025-11-14 19:38:19 +00:00
parent 30d3a1568c
commit 8713595767
+11 -8
View File
@@ -4,8 +4,8 @@ use std::env;
use std::fs;
use std::process;
use syn::{
spanned::Spanned, FnArg, Item, ItemEnum, ItemFn, ItemImpl, ItemMod, ItemStruct, ItemTrait,
ItemUse, Pat, Type, Visibility,
spanned::Spanned, Attribute, FnArg, Item, ItemEnum, ItemFn, ItemImpl, ItemMod, ItemStruct,
ItemTrait, Pat, Type, Visibility,
};
#[derive(Serialize)]
@@ -166,6 +166,7 @@ fn parse_function(item_fn: &ItemFn) -> Option<RustDecl> {
methods: Vec::new(),
return_type,
parameters,
docstring: extract_docstring(&item_fn.attrs),
})
}
@@ -197,6 +198,7 @@ fn parse_struct(item_struct: &ItemStruct) -> Option<RustDecl> {
methods: Vec::new(),
return_type: None,
parameters: Vec::new(),
docstring: extract_docstring(&item_fn.attrs),
})
}
@@ -228,6 +230,7 @@ fn parse_enum(item_enum: &ItemEnum) -> Option<RustDecl> {
methods: Vec::new(),
return_type: None,
parameters: Vec::new(),
docstring: extract_docstring(&item_fn.attrs),
})
}
@@ -265,6 +268,7 @@ fn parse_trait(item_trait: &ItemTrait) -> Option<RustDecl> {
methods,
return_type: None,
parameters: Vec::new(),
docstring: extract_docstring(&item_fn.attrs),
})
}
@@ -329,22 +333,21 @@ fn parse_impl(item_impl: &ItemImpl) -> Option<RustDecl> {
/// Pull a concatenated docstring from a list of attributes.
/// Handles both `///` comments (converted to `#[doc = "..."]` by syn)
/// and explicit `#[doc = "..."]` attributes.
fn extract_docstring(attrs: &[syn::Attribute]) -> Option<String> {
fn extract_docstring(attrs: &[Attribute]) -> Option<String> {
let mut docs = Vec::new();
for attr in attrs {
if attr.path.is_ident("doc") {
// `path()` is the correct method; `path` is a field
if attr.path().is_ident("doc") {
// #[doc = "…"]
if let Ok(meta) = attr.parse_meta() {
if let syn::Meta::NameValue(nv) = meta {
if let syn::Lit::Str(lit) = nv.lit {
// The field is `value`, not `lit`
if let syn::Lit::Str(lit) = nv.value {
docs.push(lit.value());
}
}
}
} else if attr.path.is_ident("doc") {
// Just in case `#[doc]` appears without a value (unlikely but harmless)
continue;
}
}