rust-lang/rust · error · syn::Error
unknown query modifier
Error message
unknown query modifier
What it means
Thrown by parse_query_modifiers (query.rs:204) in the rustc_queries proc-macro when a token inside a query's modifier braces does not match any of the ten recognized modifier names. The parser is an if/else-if chain (query.rs:178-205) ending in a catch-all Err, so any unrecognized identifier (or a keyword reached via a typo) is rejected with the span of that identifier.
Source
Thrown at compiler/rustc_macros/src/query.rs:204
// `desc { "foo {}", tcx.item_path(key) }`
let attr_content;
braced!(attr_content in input);
let expr_list = attr_content.parse_terminated(Expr::parse, Token![,])?;
try_insert!(desc = Desc { modifier, expr_list });
} else if modifier == "eval_always" {
try_insert!(eval_always = modifier);
} else if modifier == "feedable" {
try_insert!(feedable = modifier);
} else if modifier == "handle_cycle_error" {
try_insert!(handle_cycle_error = modifier);
} else if modifier == "no_force" {
try_insert!(no_force = modifier);
} else if modifier == "no_hash" {
try_insert!(no_hash = modifier);
} else if modifier == "separate_provide_extern" {
try_insert!(separate_provide_extern = modifier);
} else {
return Err(Error::new(modifier.span(), "unknown query modifier"));
}
}
let Some(desc) = desc else {
return Err(input.error("no description provided"));
};
Ok(QueryModifiers {
// tidy-alphabetical-start
arena_cache,
cache_on_disk,
depth_limit,
desc,
eval_always,
feedable,
handle_cycle_error,
no_force,
no_hash,
separate_provide_extern,
// tidy-alphabetical-endView on GitHub (pinned to 22057b88b0)
Solutions
- Correct the modifier identifier to one of the supported names listed in query.rs:178-202 (and rustc_middle::query::modifiers).
- If you genuinely need a new modifier, add it to QueryModifiers (query.rs:137-150), the parse chain, and make_modifiers_stream before using it.
- Check for typos and trailing punctuation that may have produced an unexpected token.
Example fix
// before
query type_of(key: DefId) -> Ty<'tcx> {
cycle_error
desc { "type of `{}`", tcx.def_path_str(key) }
}
// after
query type_of(key: DefId) -> Ty<'tcx> {
handle_cycle_error
desc { "type of `{}`", tcx.def_path_str(key) }
} Defensive patterns
Strategy: validation
Validate before calling
const KNOWN: &[&str] = &["eval_always","dep_kind","anon","feedable","cycle_delay","no_fetch"];
fn is_known_modifier(m: &str) -> bool { KNOWN.contains(&m) }
// for m in used { assert!(is_known_modifier(m), "unknown query modifier {m}"); } Type guard
fn modifier_kind(m: &str) -> Option<&'static str> {
match m {
"eval_always" | "dep_kind" | "anon" | "feedable" => Some(m),
_ => None,
}
} Prevention
- Keep a single source of truth for allowed modifier strings and diff it against query.rs:204
- Reject unknown modifiers in a pre-commit lint before they reach the proc macro
- Add a unit test asserting every documented modifier passes is_known_modifier
When it happens
Trigger: Writing a query whose braces block contains a modifier name not in the set {arena_cache, cache_on_disk, depth_limit, desc, eval_always, feedable, handle_cycle_error, no_force, no_hash, separate_provide_extern}; e.g. `query foo(k: K) -> V { cycle_error, desc {"x"} }` (should be handle_cycle_error) or placing a stray token/typo in the modifier list.
Common situations: Contributing a new query to rustc and guessing a modifier name; renaming a modifier without updating all call sites; using an older modifier name that was renamed across rustc versions; copying an example from outdated documentation.
Related errors
- duplicate modifier
- Expected a string literal
- attributes not supported on queries
- attributes must be outer attributes (`///`), not inner attri
- {:?} shouldn't exist here
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/e1583a7f7f4901aa.json.
Report an issue: GitHub.