{"id":"cbcc70a3f76f19fb","repo":"rust-lang/rust","slug":"attempted-to-decode-lazyattrtokenstream","errorCode":null,"errorMessage":"Attempted to decode LazyAttrTokenStream","messagePattern":"Attempted to decode LazyAttrTokenStream","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_ast/src/tokenstream.rs","lineNumber":156,"sourceCode":"        self.0.to_attr_token_stream()\n    }\n}\n\nimpl fmt::Debug for LazyAttrTokenStream {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        write!(f, \"LazyAttrTokenStream({:?})\", self.to_attr_token_stream())\n    }\n}\n\nimpl<S: SpanEncoder> Encodable<S> for LazyAttrTokenStream {\n    fn encode(&self, _s: &mut S) {\n        panic!(\"Attempted to encode LazyAttrTokenStream\");\n    }\n}\n\nimpl<D: SpanDecoder> Decodable<D> for LazyAttrTokenStream {\n    fn decode(_d: &mut D) -> Self {\n        panic!(\"Attempted to decode LazyAttrTokenStream\");\n    }\n}\n\nimpl StableHash for LazyAttrTokenStream {\n    fn stable_hash<Hcx: StableHashCtxt>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {\n        panic!(\"Attempted to compute stable hash for LazyAttrTokenStream\");\n    }\n}\n\n/// A token range within a `Parser`'s full token stream.\n#[derive(Clone, Debug)]\npub struct ParserRange(pub Range<u32>);\n\n/// A token range within an individual AST node's (lazy) token stream, i.e.\n/// relative to that node's first token. Distinct from `ParserRange` so the two\n/// kinds of range can't be mixed up.\n#[derive(Clone, Debug)]\npub struct NodeRange(pub Range<u32>);","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_ast/src/tokenstream.rs#L138-L174","documentation":"`panic!(\"Attempted to decode LazyAttrTokenStream\")` is the symmetric counterpart of the encode panic: the `Decodable` impl for `LazyAttrTokenStream` always panics because no `LazyAttrTokenStream` was ever meant to be on disk (see error 36). Encountering it during decode means the on-disk format was written with a type layout that included a `LazyAttrTokenStream`, indicating either a corrupted/inconsistent serialization or a schema regression.","triggerScenarios":"`Decodable::decode` is invoked for a type that, on the encoding side, erroneously contained a `LazyAttrTokenStream` — so the decoder hits this stub. Reachable via incremental-compilation load, crate metadata decoding, or query result decoding where the source side failed to force the lazy stream.","commonSituations":"Mismatched encode/decode paths after a refactor that introduced `LazyAttrTokenStream` into a serializable struct without forcing. Stale incremental compilation cache (`s-incremental`) from a prior rustc build. Cross-version crate metadata reads between incompatible rustc builds.","solutions":["Clear the incremental compilation cache (`rm -rf target/incremental` or `cargo clean`) and rebuild — a stale cache is the most common trigger.","If it persists, find the encode-side bug (see error 36) and force the lazy stream to `AttrTokenStream` before encoding.","Ensure you're not loading metadata produced by a different rustc version; rebuild dependencies with the same toolchain."],"exampleFix":"// no code fix — operational remedy:\nrm -rf target/incremental && cargo build","handlingStrategy":"validation","validationCode":"// LazyAttrTokenStream cannot be deserialized; build it from a parser instead.\n// Do not put LazyAttrTokenStream fields in Decodable structs.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat `LazyAttrTokenStream` as an in-memory-only type that lives inside the parser session.","Do not store it in structs that participate in `rustc_serialize` round-trips.","If you need a serializable token stream, convert via `to_attr_token_stream()` and persist that."],"tags":["rustc","internals","tokenstream","deserialization","incr-comp","cache"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}