DioxusLabs/dioxus · error

css_module cannot be applied to generic structs

Error message

css_module cannot be applied to generic structs

What it means

`#[css_module]` requires a non-generic struct; this compile error is emitted when the annotated struct declares generic parameters. The generated asset handle type cannot support generics, so generic structs are rejected.

Solutions

  1. Remove the generic parameters from the struct; css_module can only be applied to non-generic unit structs.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/manganis/manganis-macro/src/css_module.rs:56 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/9251908002613c57. Report an issue: GitHub.

Appendix: source

Thrown at packages/manganis/manganis-macro/src/css_module.rs:56

    }
}

pub(crate) fn expand_css_module_struct(
    tokens: &mut proc_macro2::TokenStream,
    attribute: &CssModuleAttribute,
    item_struct: &ItemStruct,
) {
    if !item_struct.fields.is_empty() {
        let err = syn::Error::new(
            item_struct.fields.span(),
            "css_module can only be applied to unit structs",
        )
        .into_compile_error();
        tokens.append_all(err);
        return;
    }
    if !item_struct.generics.params.is_empty() {
        let err = syn::Error::new(
            item_struct.generics.span(),
            "css_module cannot be applied to generic structs",
        )
        .into_compile_error();
        tokens.append_all(err);
        return;
    }
    let struct_vis = &item_struct.vis;
    let struct_name = &item_struct.ident;
    let struct_name_private = format_ident!("__{}", struct_name);

    // Use the regular asset parser to generate the linker bridge.
    let mut linker_tokens = quote! {
        /// Auto-generated Manganis asset for css modules.
        #[allow(missing_docs)]
        const ASSET: manganis::Asset =
    };
    attribute.asset_parser.to_tokens(&mut linker_tokens);

View on GitHub (pinned to 24f6a829df)