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

prefix has already been defined before

Error message

prefix has already been defined before

What it means

Compile-time error from the rule_namespace derive in ruff_macros. While collecting the string-literal prefixes attached to enum variants, derive_impl inserts each prefix's first character into a set; if the character is already present, two variants declare prefixes that begin with the same character, making prefix-based rule-code dispatch ambiguous. The macro rejects the expansion with this error at the offending literal's span. Not a runtime condition — fix by making each variant's prefix start with a distinct character.

Source

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

                        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 \
                                    starting with the character '{c}'"
                                ),
                            ));
                        }
                    }
                }
                if !all_prefixes.insert(str.clone()) {
                    return Err(Error::new(
                        lit.span(),
                        "prefix has already been defined before",
                    ));
                }
                Ok(str)
            })
            .collect();
        let prefixes = prefixes?;

        if prefixes.is_empty() {
            return Err(Error::new(
                variant.span(),
                r#"Missing #[prefix = "..."] attribute"#,
            ));
        }

        let Some(doc_attr) = variant
            .attrs

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Remove the duplicate prefix declaration
  2. Rename one of the prefixes to a unique string
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ruff_macros/src/rule_namespace.rs:71 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/b2384ff214e3b2cc. Report an issue: GitHub.