diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-16 21:55:55 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-16 21:55:55 +0800 |
| commit | 5fe400c006d9d143aa7b977cb13f95e7380754a5 (patch) | |
| tree | 96eca77fa2c47a1b1e6b4713bfefba41555ee9d2 /mingling_macros/src/completion.rs | |
| parent | 29cdd6fdbe9dd658bbc6b6694b563b046c0d9f41 (diff) | |
Validate single-segment types in attribute macros
Diffstat (limited to 'mingling_macros/src/completion.rs')
| -rw-r--r-- | mingling_macros/src/completion.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/mingling_macros/src/completion.rs b/mingling_macros/src/completion.rs index ea57f06..cd4a9ad 100644 --- a/mingling_macros/src/completion.rs +++ b/mingling_macros/src/completion.rs @@ -1,6 +1,7 @@ use proc_macro::TokenStream; use quote::quote; -use syn::{Ident, ItemFn, parse_macro_input}; +use syn::spanned::Spanned; +use syn::{FnArg, Ident, ItemFn, PatType, Type, parse_macro_input}; #[cfg(feature = "comp")] pub fn completion_attr(attr: TokenStream, item: TokenStream) -> TokenStream { @@ -45,6 +46,23 @@ pub fn completion_attr(attr: TokenStream, item: TokenStream) -> TokenStream { .into(); } + // Check that the function parameter type is a single-segment type path (no `::`) + if let Some(arg) = inputs.first() + && let FnArg::Typed(PatType { ty, .. }) = arg + && let Type::Path(type_path) = &**ty + && type_path.path.segments.len() > 1 + { + return syn::Error::new( + type_path.span(), + format!( + "The type `{}` in #[completion] function must be a simple single-segment type, e.g. `HelloEntry` instead of `other::HelloEntry`. Qualified paths with `::` are not allowed here.", + quote! { #type_path } + ), + ) + .to_compile_error() + .into(); + } + // Get the function body let fn_body = &input_fn.block; |
