{"record":{"id":"914542374cd3605b","repo":"rust-lang/rust","slug":"features-not-available-at-this-point-in-the-compil","errorCode":null,"errorMessage":"features not available at this point in the compiler","messagePattern":"features not available at this point in the compiler","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_attr_parsing/src/interface.rs","lineNumber":297,"sourceCode":"        attr_tools: &'sess RegisteredTools,\n        should_emit: ShouldEmit,\n    ) -> Self {\n        Self {\n            features: Some(features),\n            attr_tools: Some(attr_tools),\n            parse_filter: None,\n            sess,\n            should_emit,\n        }\n    }\n\n    pub(crate) fn sess(&self) -> &'sess Session {\n        self.sess\n    }\n\n    #[track_caller]\n    pub(crate) fn features(&self) -> &'sess Features {\n        self.features.expect(\"features not available at this point in the compiler\")\n    }\n\n    pub(crate) fn features_option(&self) -> Option<&'sess Features> {\n        self.features\n    }\n\n    pub(crate) fn dcx(&self) -> DiagCtxtHandle<'sess> {\n        self.sess().dcx()\n    }\n\n    pub(crate) fn emit_err(&self, diag: impl for<'x> Diagnostic<'x>) -> ErrorGuaranteed {\n        self.should_emit.emit_err(self.sess.dcx().create_err(diag))\n    }\n\n    /// Parse a list of attributes.\n    ///\n    /// `target_span` is the span of the thing this list of attributes is applied to,\n    /// and when `omit_doc` is set, doc attributes are filtered out.","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_attr_parsing/src/interface.rs#L279-L315","documentation":"interface.rs:297: AcceptContext::features() does self.features.expect(\"features not available at this point in the compiler\"). AcceptContext.features is Option<&Features>; an attribute parser that calls features() before the feature-gate information has been attached to the context panics. The invariant: features() must only be called during the attribute-acceptance phase after features are populated.","triggerScenarios":"An attribute parser invokes cx.features() outside the window where AcceptContext.features has been set (e.g. during early validation before feature computation, or in a context that intentionally has no features).","commonSituations":"A compiler-developer mistake calling features() too early, or an attribute registered to run in a phase that lacks feature info; an internal ordering bug.","solutions":["File a rustc ICE; this is an internal phase-ordering violation.","If you are writing/patching a compiler attribute parser, gate the call: use cx.features_option() (provided just above) instead of cx.features() when features may be absent.","Bisect with cargo bisect-rustc to locate the ordering change.","Reduce the triggering attribute set to the minimum that exercises the early parser."],"exampleFix":"// before (compiler code)\nlet feats = cx.features(); // panics if features not set yet\n\n// after\nlet feats = cx.features_option(); // None-safe\nmatch feats {\n    Some(f) if f.enabled(sym::my_feature) => { /* ... */ }\n    _ => { /* feature not available; skip */ }\n}","handlingStrategy":"validation","validationCode":"// Compiler-internal: prefer the None-safe accessor.\nlet feats = cx.features_option();\nlet on = feats.is_some_and(|f| f.enabled(sym::my_feature));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When patching the compiler, call cx.features_option() (None-safe) unless you are certain features are set.","Only call cx.features() during the attribute-acceptance phase after features are populated.","Register attribute parsers to run in a phase that has feature information.","File an ICE if it triggers on a stock toolchain."],"tags":["rust","attributes","feature-gate","compiler-internal"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}