Simplify LazyAttrTokenStream.

This commit does the following.
- Changes it from `Lrc<Box<dyn ToAttrTokenStream>>` to
  `Lrc<LazyAttrTokenStreamInner>`.
- Reworks `LazyAttrTokenStreamImpl` as `LazyAttrTokenStreamInner`, which
  is a two-variant enum.
- Removes the `ToAttrTokenStream` trait and the two impls of it.

The recursion limit must be increased in some crates otherwise rustdoc
aborts.
This commit is contained in:
Nicholas Nethercote
2025-04-29 11:57:27 +10:00
parent 28236ab703
commit 298c56f4ba
12 changed files with 138 additions and 118 deletions

View File

@@ -11,6 +11,7 @@
#![feature(if_let_guard)]
#![feature(iter_intersperse)]
#![feature(string_from_utf8_lossy_owned)]
#![recursion_limit = "256"]
// tidy-alphabetical-end
use std::path::{Path, PathBuf};

View File

@@ -3,8 +3,7 @@ use std::mem;
use rustc_ast::token::Token;
use rustc_ast::tokenstream::{
AttrsTarget, LazyAttrTokenStream, LazyAttrTokenStreamImpl, NodeRange, ParserRange, Spacing,
TokenCursor,
AttrsTarget, LazyAttrTokenStream, NodeRange, ParserRange, Spacing, TokenCursor,
};
use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, HasTokens};
use rustc_data_structures::fx::FxHashSet;
@@ -337,13 +336,13 @@ impl<'a> Parser<'a> {
// - `attrs`: includes the outer and the inner attr.
// - `tokens`: lazy tokens for `g` (with its inner attr deleted).
let tokens = LazyAttrTokenStream::new(LazyAttrTokenStreamImpl {
start_token: collect_pos.start_token,
cursor_snapshot: collect_pos.cursor_snapshot,
let tokens = LazyAttrTokenStream::new_pending(
collect_pos.start_token,
collect_pos.cursor_snapshot,
num_calls,
break_last_token: self.break_last_token,
self.break_last_token,
node_replacements,
});
);
let mut tokens_used = false;
// If in "definite capture mode" we need to register a replace range
@@ -405,14 +404,3 @@ fn needs_tokens(attrs: &[ast::Attribute]) -> bool {
}
})
}
// Some types are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(target_pointer_width = "64")]
mod size_asserts {
use rustc_data_structures::static_assert_size;
use super::*;
// tidy-alphabetical-start
static_assert_size!(LazyAttrTokenStreamImpl, 96);
// tidy-alphabetical-end
}