astral-sh/ruff · error · syn::Error
expected prefix string to be non-empty
Error message
expected prefix string to be non-empty
What it means
A syn compile error from the RuleNamespace derive: a #[prefix = "..."] attribute's string value is empty. Rule prefixes must be non-empty because the first character is used to route codes to linters.
Source
Thrown at crates/ruff_macros/src/rule_namespace.rs:53
.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 \
starting with the character '{c}'"
),
));
}
}
}
if !all_prefixes.insert(str.clone()) {
return Err(Error::new(View on GitHub (pinned to 26f38c119c)
Solutions
- Provide a non-empty prefix string such as "E"
- Remove the empty prefix attribute if the variant needs none
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/ruff_macros/src/rule_namespace.rs:53 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/0233bfb24f902ebd.
Report an issue: GitHub.