aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/lib.rs
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-31 02:42:52 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-31 17:19:20 +0800
commit2aa7bda3cb21ce6c052b82e08bcab79a625d04f2 (patch)
treef10b89007fc67ca1a948f34abe6869b49296b932 /mingling_macros/src/lib.rs
parent3aa409a55e4f2f0ab41b0949cc06eb13c2da4a43 (diff)
Enhance code quality across the entire codebase
Diffstat (limited to 'mingling_macros/src/lib.rs')
-rw-r--r--mingling_macros/src/lib.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs
index 8cae29f..7a93895 100644
--- a/mingling_macros/src/lib.rs
+++ b/mingling_macros/src/lib.rs
@@ -82,7 +82,7 @@ pub(crate) static CHAINS_EXIST: Registry = OnceLock::new();
pub(crate) static RENDERERS_EXIST: Registry = OnceLock::new();
pub(crate) static HELP_REQUESTS: Registry = OnceLock::new();
-/// Checks that a TypePath is a simple single-segment identifier (no `::` in the path).
+/// Checks that a `TypePath` is a simple single-segment identifier (no `::` in the path).
///
/// This is used by `#[renderer]`, `#[help]`, `#[chain]`, and `#[completion]` attribute macros
/// to ensure that the type in the function signature is a bare identifier like `Empty`,
@@ -307,7 +307,7 @@ pub fn empty_result(_input: TokenStream) -> TokenStream {
///
/// When the `extra_macros` feature is enabled, the `CommandStruct => EntryStruct`
/// portion can be omitted. The struct names are auto-derived from the command path
-/// using PascalCase conversion:
+/// using `PascalCase` conversion:
///
/// ```rust,ignore
/// // Auto-derives: "remote.add" → CMDRemoteAdd ⇒ EntryRemoteAdd
@@ -1188,7 +1188,7 @@ pub fn program_comp_gen(input: TokenStream) -> TokenStream {
/// Registers a type into the global packed types registry for inclusion in
/// the program enum generated by `gen_program!`.
///
-/// This macro is called internally by `pack!` and `#[derive(Groupped)]`(macro.derive_groupped.html)
+/// This macro is called internally by `pack!` and `#[derive(Groupped)]`(`macro.derive_groupped.html`)
/// and is generally not needed in user code. However, it can be used for manual
/// registration if you are implementing custom type registration outside of
/// the standard macros.
@@ -1201,6 +1201,10 @@ pub fn program_comp_gen(input: TokenStream) -> TokenStream {
///
/// Each call inserts the type's name into the `PACKED_TYPES` global set, which
/// is later consumed by `program_final_gen!` to generate enum variants.
+///
+/// # Panics
+///
+/// Panics if the global `PACKED_TYPES` mutex is poisoned.
#[proc_macro]
pub fn register_type(input: TokenStream) -> TokenStream {
let type_ident = parse_macro_input!(input as syn::Ident);
@@ -1348,7 +1352,13 @@ pub fn program_fallback_gen(input: TokenStream) -> TokenStream {
/// pub fn new() -> Program<MyProgram> { Program::new() }
/// }
/// ```
+///
+/// # Panics
+///
+/// Panics if any of the global registries (`PACKED_TYPES`, `RENDERERS`, `CHAINS`, etc.)
+/// are poisoned.
#[proc_macro]
+#[allow(clippy::too_many_lines)]
pub fn program_final_gen(input: TokenStream) -> TokenStream {
let name = read_name(&input);
@@ -1479,11 +1489,11 @@ pub fn program_final_gen(input: TokenStream) -> TokenStream {
.collect();
let num_variants = packed_types.len();
- let repr_type = if num_variants <= u8::MAX as usize {
+ let repr_type = if u8::try_from(num_variants).is_ok() {
quote! { u8 }
- } else if num_variants <= u16::MAX as usize {
+ } else if u16::try_from(num_variants).is_ok() {
quote! { u16 }
- } else if num_variants <= u32::MAX as usize {
+ } else if u32::try_from(num_variants).is_ok() {
quote! { u32 }
} else {
quote! { u128 }
@@ -1612,7 +1622,7 @@ pub fn program_final_gen(input: TokenStream) -> TokenStream {
///
/// # Related
///
-/// - `suggest_enum!`(macro.suggest_enum.html) — Build suggestions from an `EnumTag` enum.
+/// - `suggest_enum!`(`macro.suggest_enum.html`) — Build suggestions from an `EnumTag` enum.
#[cfg(feature = "comp")]
#[proc_macro]
pub fn suggest(input: TokenStream) -> TokenStream {