{"id":"33d1714c043caf9c","repo":"rust-lang/rust","slug":"mentioned-items-for-have-not-yet-been-set","errorCode":null,"errorMessage":"mentioned_items for {:?} have not yet been set","messagePattern":"mentioned_items for (.+?) have not yet been set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_middle/src/mir/mod.rs","lineNumber":747,"sourceCode":"            Some(l) => l,\n            None => panic!(\"required_consts for {:?} have not yet been set\", self.source.def_id()),\n        }\n    }\n\n    #[track_caller]\n    pub fn set_mentioned_items(&mut self, mentioned_items: Vec<Spanned<MentionedItem<'tcx>>>) {\n        assert!(\n            self.mentioned_items.is_none(),\n            \"mentioned_items for {:?} have already been set\",\n            self.source.def_id()\n        );\n        self.mentioned_items = Some(mentioned_items);\n    }\n    #[track_caller]\n    pub fn mentioned_items(&self) -> &[Spanned<MentionedItem<'tcx>>] {\n        match &self.mentioned_items {\n            Some(l) => l,\n            None => panic!(\"mentioned_items for {:?} have not yet been set\", self.source.def_id()),\n        }\n    }\n}\n\nimpl<'tcx> Index<BasicBlock> for Body<'tcx> {\n    type Output = BasicBlockData<'tcx>;\n\n    #[inline]\n    fn index(&self, index: BasicBlock) -> &BasicBlockData<'tcx> {\n        &self.basic_blocks[index]\n    }\n}\n\nimpl<'tcx> IndexMut<BasicBlock> for Body<'tcx> {\n    #[inline]\n    fn index_mut(&mut self, index: BasicBlock) -> &mut BasicBlockData<'tcx> {\n        &mut self.basic_blocks.as_mut()[index]\n    }","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_middle/src/mir/mod.rs#L729-L765","documentation":"`Body::mentioned_items()` (mir/mod.rs:747) panics if the `mentionedItems` field is still `None` — the MIR pass that collects \"mentioned items\" (a more inclusive set than `required_consts`, used by the coverage/inlineability checks) has not yet run for this `Body`. Same Option-vs-empty invariant as index 248.","triggerScenarios":"Calling `body.mentioned_items()` before the mentioned-items MIR pass invoked `set_mentioned_items`. Happens when a downstream pass, tool, or test queries the field on a `Body` whose pipeline phase predates the populate step, or when a `Body` is constructed by an external tool (mir-json, diff-testing harness) without populating the field.","commonSituations":"Adding a pass that consumes mentioned items for coverage/inline-cost analysis without declaring ordering against the populating pass; rustc upgrades where mentioned-items was introduced (or its populate phase moved); Miri/tools reading MIR bodies produced by a stripped rustc build.","solutions":["Declare the pipeline ordering so the populating pass runs before your consumer pass.","If constructing the `Body` directly, call `body.set_mentioned_items(vec![...])` before any read.","Gate the read on the MIR phase (`Body::phase`) that guarantees population.","Use an Option-style accessor or check `mentioned_items.is_some()` if you add one locally."],"exampleFix":"// before\nlet items = body.mentioned_items(); // None → panic\n\n// after\nbody.set_mentioned_items(collected);\nlet items = body.mentioned_items();","handlingStrategy":"validation","validationCode":"// Body::mentioned_items() panics until set_mentioned_items has run.\n// Mirror the guard used for required_consts.\nstruct BodyView<'a, 'tcx> {\n    body: &'a Body<'tcx>,\n    mentioned_set: bool,\n}\n\nfn mentioned_items<'a, 'tcx>(v: &BodyView<'a, 'tcx>) -> &'a [Spanned<MentionedItem<'tcx>>] {\n    if v.mentioned_set {\n        v.body.mentioned_items()\n    else {\n        &[]\n    }\n}","typeGuard":null,"tryCatchPattern":"let items = std::panic::catch_unwind(|| body.mentioned_items());\nmatch items {\n    Ok(i) => /* use i */,\n    Err(_) => /* mentioned-item collection pass not run yet; defer this consumer */,\n}","preventionTips":["Run the mentioned-items MIR pass before any consumer reads Body::mentioned_items(); the field is None by default.","Wrap Body access in a view struct that remembers which set_* calls have happened, so reads are gated on real state rather than hope.","Treat both required_consts and mentioned_items with the same lifecycle discipline -- they share the 'set once, read many' contract.","If you implement a custom MIR pass pipeline, assert at the end that every Body you intend to query later had set_mentioned_items invoked."],"tags":["rustc","mir","mir-body","query","pipeline","internal"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}