{"record":{"id":"db0b1887a1e07e1a","repo":"rust-lang/rust","slug":"duplicate-modifier","errorCode":null,"errorMessage":"duplicate modifier","messagePattern":"duplicate modifier","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_macros/src/query.rs","lineNumber":172,"sourceCode":"    let mut arena_cache = None;\n    let mut cache_on_disk = None;\n    let mut depth_limit = None;\n    let mut desc = None;\n    let mut eval_always = None;\n    let mut feedable = None;\n    let mut handle_cycle_error = None;\n    let mut no_force = None;\n    let mut no_hash = None;\n    let mut separate_provide_extern = None;\n    // tidy-alphabetical-end\n\n    while !input.is_empty() {\n        let modifier: Ident = input.parse()?;\n\n        macro_rules! try_insert {\n            ($name:ident = $expr:expr) => {\n                if $name.is_some() {\n                    return Err(Error::new(modifier.span(), \"duplicate modifier\"));\n                }\n                $name = Some($expr);\n            };\n        }\n\n        if modifier == \"arena_cache\" {\n            try_insert!(arena_cache = modifier);\n        } else if modifier == \"cache_on_disk\" {\n            try_insert!(cache_on_disk = modifier);\n        } else if modifier == \"depth_limit\" {\n            try_insert!(depth_limit = modifier);\n        } else if modifier == \"desc\" {\n            // Parse a description modifier like:\n            // `desc { \"foo {}\", tcx.item_path(key) }`\n            let attr_content;\n            braced!(attr_content in input);\n            let expr_list = attr_content.parse_terminated(Expr::parse, Token![,])?;\n            try_insert!(desc = Desc { modifier, expr_list });","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_macros/src/query.rs#L154-L190","documentation":"Emitted by parse_query_modifiers in the rustc_queries! macro. The parser maintains an Option<Ident> slot for each modifier key (arena_cache, cache_on_disk, depth_limit, desc, eval_always, feedable, handle_cycle_error, no_force, no_hash, separate_provide_extern). The try_insert! macro checks if the slot is already Some — if so, the second occurrence of that key triggers 'duplicate modifier' at the span of the duplicate ident.","triggerScenarios":"Writing a query modifier block where the same modifier key appears twice. Example: query foo(key: K) -> V { desc { \"...\" }, eval_always, eval_always } — the second eval_always is the duplicate.","commonSituations":"Copy-pasting a modifier line and forgetting to delete the original; refactoring a query's modifiers and leaving a stale entry; merge conflicts resolved by keeping both sides' modifier.","solutions":["Remove the duplicate modifier — each key can appear at most once per query.","Review the full modifier block for your query and ensure each key is listed exactly once.","If you need the effect of a modifier combined with something else, check rustc_middle::query::modifiers for how modifiers interact — they are designed to be mutually exclusive flags."],"exampleFix":"// before\nquery foo(key: DefId) -> Ty<'tcx> {\n    desc { \"computes foo for `{}`\", key }\n    eval_always\n    eval_always\n}\n// after: remove the duplicate\nquery foo(key: DefId) -> Ty<'tcx> {\n    desc { \"computes foo for `{}`\", key }\n    eval_always\n}","handlingStrategy":"validation","validationCode":"// No runtime API to validate — this is a proc-macro compile-time check.\n// To prevent it, review each query's modifier block for duplicates.\n// You can write a simple lint script:\nconst KNOWN_MODIFIERS: &[&str] = &[\n    \"arena_cache\", \"cache_on_disk\", \"depth_limit\", \"desc\",\n    \"eval_always\", \"feedable\", \"handle_cycle_error\",\n    \"no_force\", \"no_hash\", \"separate_provide_extern\",\n];\n// Parse each query block and assert no modifier appears more than once.","typeGuard":null,"tryCatchPattern":"// Compile-time error — cannot be caught at runtime.\n// Fix by removing the duplicate modifier entry.","preventionTips":["Each query modifier key can appear at most once per query block.","When refactoring modifiers, diff the before/after to spot unintended duplicates.","Keep modifiers in the alphabetical order shown in the tidy comments for easier review."],"tags":["rustc","proc-macro","query","compiler-internals"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}