Skip to content

Commit ee0c16b

Browse files
committed
XXX: Remove LazyAttrTokenStream
1 parent b4feaa1 commit ee0c16b

File tree

10 files changed

+86
-148
lines changed

10 files changed

+86
-148
lines changed

compiler/rustc_ast/src/ast.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use UnsafeSource::*;
2626

2727
use crate::ptr::P;
2828
use crate::token::{self, CommentKind, Delimiter};
29-
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
29+
use crate::tokenstream::{AttrTokenStream, DelimSpan, TokenStream};
3030
pub use rustc_ast_ir::{Movability, Mutability};
3131
use rustc_data_structures::packed::Pu128;
3232
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -94,7 +94,7 @@ pub struct Path {
9494
/// The segments in the path: the things separated by `::`.
9595
/// Global paths begin with `kw::PathRoot`.
9696
pub segments: ThinVec<PathSegment>,
97-
pub tokens: Option<LazyAttrTokenStream>,
97+
pub tokens: Option<AttrTokenStream>,
9898
}
9999

100100
impl PartialEq<Symbol> for Path {
@@ -544,7 +544,7 @@ pub struct Block {
544544
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
545545
pub rules: BlockCheckMode,
546546
pub span: Span,
547-
pub tokens: Option<LazyAttrTokenStream>,
547+
pub tokens: Option<AttrTokenStream>,
548548
/// The following *isn't* a parse error, but will cause multiple errors in following stages.
549549
/// ```compile_fail
550550
/// let x = {
@@ -563,7 +563,7 @@ pub struct Pat {
563563
pub id: NodeId,
564564
pub kind: PatKind,
565565
pub span: Span,
566-
pub tokens: Option<LazyAttrTokenStream>,
566+
pub tokens: Option<AttrTokenStream>,
567567
}
568568

569569
impl Pat {
@@ -1002,7 +1002,7 @@ impl Stmt {
10021002
/// a trailing semicolon.
10031003
///
10041004
/// This only modifies the parsed AST struct, not the attached
1005-
/// `LazyAttrTokenStream`. The parser is responsible for calling
1005+
/// `AttrTokenStream`. The parser is responsible for calling
10061006
/// `ToAttrTokenStream::add_trailing_semi` when there is actually
10071007
/// a semicolon in the tokenstream.
10081008
pub fn add_trailing_semicolon(mut self) -> Self {
@@ -1050,7 +1050,7 @@ pub struct MacCallStmt {
10501050
pub mac: P<MacCall>,
10511051
pub style: MacStmtStyle,
10521052
pub attrs: AttrVec,
1053-
pub tokens: Option<LazyAttrTokenStream>,
1053+
pub tokens: Option<AttrTokenStream>,
10541054
}
10551055

10561056
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]
@@ -1076,7 +1076,7 @@ pub struct Local {
10761076
pub span: Span,
10771077
pub colon_sp: Option<Span>,
10781078
pub attrs: AttrVec,
1079-
pub tokens: Option<LazyAttrTokenStream>,
1079+
pub tokens: Option<AttrTokenStream>,
10801080
}
10811081

10821082
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -1175,7 +1175,7 @@ pub struct Expr {
11751175
pub kind: ExprKind,
11761176
pub span: Span,
11771177
pub attrs: AttrVec,
1178-
pub tokens: Option<LazyAttrTokenStream>,
1178+
pub tokens: Option<AttrTokenStream>,
11791179
}
11801180

11811181
impl Expr {
@@ -2102,7 +2102,7 @@ pub struct Ty {
21022102
pub id: NodeId,
21032103
pub kind: TyKind,
21042104
pub span: Span,
2105-
pub tokens: Option<LazyAttrTokenStream>,
2105+
pub tokens: Option<AttrTokenStream>,
21062106
}
21072107

21082108
impl Clone for Ty {
@@ -2831,7 +2831,7 @@ pub enum AttrKind {
28312831
pub struct NormalAttr {
28322832
pub item: AttrItem,
28332833
// Tokens for the full attribute, e.g. `#[foo]`, `#![bar]`.
2834-
pub tokens: Option<LazyAttrTokenStream>,
2834+
pub tokens: Option<AttrTokenStream>,
28352835
}
28362836

28372837
impl NormalAttr {
@@ -2854,7 +2854,7 @@ pub struct AttrItem {
28542854
pub path: Path,
28552855
pub args: AttrArgs,
28562856
// Tokens for the meta item, e.g. just the `foo` within `#[foo]` or `#![foo]`.
2857-
pub tokens: Option<LazyAttrTokenStream>,
2857+
pub tokens: Option<AttrTokenStream>,
28582858
}
28592859

28602860
/// `TraitRef`s appear in impls.
@@ -2894,7 +2894,7 @@ impl PolyTraitRef {
28942894
pub struct Visibility {
28952895
pub kind: VisibilityKind,
28962896
pub span: Span,
2897-
pub tokens: Option<LazyAttrTokenStream>,
2897+
pub tokens: Option<AttrTokenStream>,
28982898
}
28992899

29002900
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -2987,7 +2987,7 @@ pub struct Item<K = ItemKind> {
29872987
///
29882988
/// Note that the tokens here do not include the outer attributes, but will
29892989
/// include inner attributes.
2990-
pub tokens: Option<LazyAttrTokenStream>,
2990+
pub tokens: Option<AttrTokenStream>,
29912991
}
29922992

29932993
impl Item {

compiler/rustc_ast/src/ast_traits.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use crate::ptr::P;
66
use crate::token::Nonterminal;
7-
use crate::tokenstream::LazyAttrTokenStream;
7+
use crate::tokenstream::AttrTokenStream;
88
use crate::{Arm, Crate, ExprField, FieldDef, GenericParam, Param, PatField, Variant};
99
use crate::{AssocItem, Expr, ForeignItem, Item, NodeId};
1010
use crate::{AttrItem, AttrKind, Block, Pat, Path, Ty, Visibility};
@@ -91,18 +91,18 @@ impl<T: AstDeref<Target: HasNodeId>> HasNodeId for T {
9191

9292
/// A trait for AST nodes having (or not having) collected tokens.
9393
pub trait HasTokens {
94-
fn tokens(&self) -> Option<&LazyAttrTokenStream>;
95-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>>;
94+
fn tokens(&self) -> Option<&AttrTokenStream>;
95+
fn tokens_mut(&mut self) -> Option<&mut Option<AttrTokenStream>>;
9696
}
9797

9898
macro_rules! impl_has_tokens {
9999
($($T:ty),+ $(,)?) => {
100100
$(
101101
impl HasTokens for $T {
102-
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
102+
fn tokens(&self) -> Option<&AttrTokenStream> {
103103
self.tokens.as_ref()
104104
}
105-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
105+
fn tokens_mut(&mut self) -> Option<&mut Option<AttrTokenStream>> {
106106
Some(&mut self.tokens)
107107
}
108108
}
@@ -114,10 +114,10 @@ macro_rules! impl_has_tokens_none {
114114
($($T:ty),+ $(,)?) => {
115115
$(
116116
impl HasTokens for $T {
117-
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
117+
fn tokens(&self) -> Option<&AttrTokenStream> {
118118
None
119119
}
120-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
120+
fn tokens_mut(&mut self) -> Option<&mut Option<AttrTokenStream>> {
121121
None
122122
}
123123
}
@@ -129,25 +129,25 @@ impl_has_tokens!(AssocItem, AttrItem, Block, Expr, ForeignItem, Item, Pat, Path,
129129
impl_has_tokens_none!(Arm, ExprField, FieldDef, GenericParam, Param, PatField, Variant);
130130

131131
impl<T: AstDeref<Target: HasTokens>> HasTokens for T {
132-
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
132+
fn tokens(&self) -> Option<&AttrTokenStream> {
133133
self.ast_deref().tokens()
134134
}
135-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
135+
fn tokens_mut(&mut self) -> Option<&mut Option<AttrTokenStream>> {
136136
self.ast_deref_mut().tokens_mut()
137137
}
138138
}
139139

140140
impl<T: HasTokens> HasTokens for Option<T> {
141-
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
141+
fn tokens(&self) -> Option<&AttrTokenStream> {
142142
self.as_ref().and_then(|inner| inner.tokens())
143143
}
144-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
144+
fn tokens_mut(&mut self) -> Option<&mut Option<AttrTokenStream>> {
145145
self.as_mut().and_then(|inner| inner.tokens_mut())
146146
}
147147
}
148148

149149
impl HasTokens for StmtKind {
150-
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
150+
fn tokens(&self) -> Option<&AttrTokenStream> {
151151
match self {
152152
StmtKind::Let(local) => local.tokens.as_ref(),
153153
StmtKind::Item(item) => item.tokens(),
@@ -156,7 +156,7 @@ impl HasTokens for StmtKind {
156156
StmtKind::MacCall(mac) => mac.tokens.as_ref(),
157157
}
158158
}
159-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
159+
fn tokens_mut(&mut self) -> Option<&mut Option<AttrTokenStream>> {
160160
match self {
161161
StmtKind::Let(local) => Some(&mut local.tokens),
162162
StmtKind::Item(item) => item.tokens_mut(),
@@ -168,24 +168,24 @@ impl HasTokens for StmtKind {
168168
}
169169

170170
impl HasTokens for Stmt {
171-
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
171+
fn tokens(&self) -> Option<&AttrTokenStream> {
172172
self.kind.tokens()
173173
}
174-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
174+
fn tokens_mut(&mut self) -> Option<&mut Option<AttrTokenStream>> {
175175
self.kind.tokens_mut()
176176
}
177177
}
178178

179179
impl HasTokens for Attribute {
180-
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
180+
fn tokens(&self) -> Option<&AttrTokenStream> {
181181
match &self.kind {
182182
AttrKind::Normal(normal) => normal.tokens.as_ref(),
183183
kind @ AttrKind::DocComment(..) => {
184184
panic!("Called tokens on doc comment attr {kind:?}")
185185
}
186186
}
187187
}
188-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
188+
fn tokens_mut(&mut self) -> Option<&mut Option<AttrTokenStream>> {
189189
Some(match &mut self.kind {
190190
AttrKind::Normal(normal) => &mut normal.tokens,
191191
kind @ AttrKind::DocComment(..) => {
@@ -196,7 +196,7 @@ impl HasTokens for Attribute {
196196
}
197197

198198
impl HasTokens for Nonterminal {
199-
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
199+
fn tokens(&self) -> Option<&AttrTokenStream> {
200200
match self {
201201
Nonterminal::NtItem(item) => item.tokens(),
202202
Nonterminal::NtStmt(stmt) => stmt.tokens(),
@@ -209,7 +209,7 @@ impl HasTokens for Nonterminal {
209209
Nonterminal::NtBlock(block) => block.tokens(),
210210
}
211211
}
212-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
212+
fn tokens_mut(&mut self) -> Option<&mut Option<AttrTokenStream>> {
213213
match self {
214214
Nonterminal::NtItem(item) => item.tokens_mut(),
215215
Nonterminal::NtStmt(stmt) => stmt.tokens_mut(),

compiler/rustc_ast/src/attr/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem, NormalAttr};
88
use crate::ast::{Path, PathSegment, DUMMY_NODE_ID};
99
use crate::ptr::P;
1010
use crate::token::{self, CommentKind, Delimiter, Token};
11+
use crate::tokenstream::{AttrTokenStream, TokenStream};
1112
use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
12-
use crate::tokenstream::{LazyAttrTokenStream, TokenStream};
1313
use crate::util::comments;
1414
use crate::util::literal::escape_string_symbol;
1515
use rustc_index::bit_set::GrowableBitSet;
@@ -210,7 +210,6 @@ impl Attribute {
210210
.tokens
211211
.as_ref()
212212
.unwrap_or_else(|| panic!("attribute is missing tokens: {self:?}"))
213-
.to_attr_token_stream()
214213
.to_token_trees(),
215214
),
216215
&AttrKind::DocComment(comment_kind, data) => TokenStream::token_alone(
@@ -586,7 +585,7 @@ pub fn mk_attr(
586585
pub fn mk_attr_from_item(
587586
g: &AttrIdGenerator,
588587
item: AttrItem,
589-
tokens: Option<LazyAttrTokenStream>,
588+
tokens: Option<AttrTokenStream>,
590589
style: AttrStyle,
591590
span: Span,
592591
) -> Attribute {

0 commit comments

Comments
 (0)