rust-lang/rust · critical
Attempted to decode LazyAttrTokenStream
Error message
Attempted to decode LazyAttrTokenStream
What it means
`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.
Source
Thrown at compiler/rustc_ast/src/tokenstream.rs:156
self.0.to_attr_token_stream()
}
}
impl fmt::Debug for LazyAttrTokenStream {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "LazyAttrTokenStream({:?})", self.to_attr_token_stream())
}
}
impl<S: SpanEncoder> Encodable<S> for LazyAttrTokenStream {
fn encode(&self, _s: &mut S) {
panic!("Attempted to encode LazyAttrTokenStream");
}
}
impl<D: SpanDecoder> Decodable<D> for LazyAttrTokenStream {
fn decode(_d: &mut D) -> Self {
panic!("Attempted to decode LazyAttrTokenStream");
}
}
impl StableHash for LazyAttrTokenStream {
fn stable_hash<Hcx: StableHashCtxt>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
panic!("Attempted to compute stable hash for LazyAttrTokenStream");
}
}
/// A token range within a `Parser`'s full token stream.
#[derive(Clone, Debug)]
pub struct ParserRange(pub Range<u32>);
/// A token range within an individual AST node's (lazy) token stream, i.e.
/// relative to that node's first token. Distinct from `ParserRange` so the two
/// kinds of range can't be mixed up.
#[derive(Clone, Debug)]
pub struct NodeRange(pub Range<u32>);View on GitHub (pinned to 22057b88b0)
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.
Example fix
// no code fix — operational remedy: rm -rf target/incremental && cargo build
Defensive patterns
Strategy: validation
Validate before calling
// LazyAttrTokenStream cannot be deserialized; build it from a parser instead. // Do not put LazyAttrTokenStream fields in Decodable structs.
Prevention
- 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.
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- Attempted to encode LazyAttrTokenStream
- Attempted to compute stable hash for LazyAttrTokenStream
- Unexpected last token {last_token:?}
- if we had an explicit self, we wouldn't be here
- empty prefix in a simple import
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/cbcc70a3f76f19fb.json.
Report an issue: GitHub.