astral-sh/ruff · error · syn::Error

expected attribute to be in the form of [#prefix = "..."]

Error message

expected attribute to be in the form of [#prefix = "..."]

What it means

A syn compile error from the RuleNamespace derive: a variant's #[prefix(...)] attribute is not a name-value string literal of the form #[prefix = "..."]. Prefixes are extracted only from that exact attribute shape.

Source

Thrown at crates/ruff_macros/src/rule_namespace.rs:45

    let mut all_prefixes = HashSet::new();

    for variant in variants {
        let mut first_chars = HashSet::new();
        let prefixes: Result<Vec<_>, _> = variant
            .attrs
            .iter()
            .filter(|attr| attr.path().is_ident("prefix"))
            .map(|attr| {
                let Meta::NameValue(MetaNameValue {
                    value:
                        syn::Expr::Lit(ExprLit {
                            lit: Lit::Str(lit), ..
                        }),
                    ..
                }) = &attr.meta
                else {
                    return Err(Error::new(
                        attr.span(),
                        r#"expected attribute to be in the form of [#prefix = "..."]"#,
                    ));
                };
                let str = lit.value();
                match str.chars().next() {
                    None => {
                        return Err(Error::new(
                            lit.span(),
                            "expected prefix string to be non-empty",
                        ));
                    }
                    Some(c) => {
                        if !first_chars.insert(c) {
                            return Err(Error::new(
                                lit.span(),
                                format!(
                                    "this variant already has another prefix \

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Write the attribute as #[prefix = "E"]
  2. Remove list- or symbol-shaped prefix attributes
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ruff_macros/src/rule_namespace.rs:45 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/e37c65de4aca3f49. Report an issue: GitHub.