Skip to content

Commit d2df07c

Browse files
committed
Rename {Create,Lazy}TokenStream as {To,Lazy}AttrTokenStream.
`To` is better than `Create` for indicating that this is a non-consuming conversion, rather than creating something out of nothing. And the addition of `Attr` is because the current names makes them sound like they relate to `TokenStream`, but really they relate to `AttrTokenStream`.
1 parent f6c9e1d commit d2df07c

File tree

9 files changed

+84
-81
lines changed

9 files changed

+84
-81
lines changed

compiler/rustc_ast/src/ast.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub use UnsafeSource::*;
2424

2525
use crate::ptr::P;
2626
use crate::token::{self, CommentKind, Delimiter};
27-
use crate::tokenstream::{DelimSpan, LazyTokenStream, TokenStream};
27+
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
2828
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2929
use rustc_data_structures::stack::ensure_sufficient_stack;
3030
use rustc_data_structures::sync::Lrc;
@@ -92,7 +92,7 @@ pub struct Path {
9292
/// The segments in the path: the things separated by `::`.
9393
/// Global paths begin with `kw::PathRoot`.
9494
pub segments: Vec<PathSegment>,
95-
pub tokens: Option<LazyTokenStream>,
95+
pub tokens: Option<LazyAttrTokenStream>,
9696
}
9797

9898
impl PartialEq<Symbol> for Path {
@@ -564,7 +564,7 @@ pub struct Block {
564564
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
565565
pub rules: BlockCheckMode,
566566
pub span: Span,
567-
pub tokens: Option<LazyTokenStream>,
567+
pub tokens: Option<LazyAttrTokenStream>,
568568
/// The following *isn't* a parse error, but will cause multiple errors in following stages.
569569
/// ```compile_fail
570570
/// let x = {
@@ -583,7 +583,7 @@ pub struct Pat {
583583
pub id: NodeId,
584584
pub kind: PatKind,
585585
pub span: Span,
586-
pub tokens: Option<LazyTokenStream>,
586+
pub tokens: Option<LazyAttrTokenStream>,
587587
}
588588

589589
impl Pat {
@@ -967,8 +967,8 @@ impl Stmt {
967967
/// a trailing semicolon.
968968
///
969969
/// This only modifies the parsed AST struct, not the attached
970-
/// `LazyTokenStream`. The parser is responsible for calling
971-
/// `CreateTokenStream::add_trailing_semi` when there is actually
970+
/// `LazyAttrTokenStream`. The parser is responsible for calling
971+
/// `ToAttrTokenStream::add_trailing_semi` when there is actually
972972
/// a semicolon in the tokenstream.
973973
pub fn add_trailing_semicolon(mut self) -> Self {
974974
self.kind = match self.kind {
@@ -1014,7 +1014,7 @@ pub struct MacCallStmt {
10141014
pub mac: P<MacCall>,
10151015
pub style: MacStmtStyle,
10161016
pub attrs: AttrVec,
1017-
pub tokens: Option<LazyTokenStream>,
1017+
pub tokens: Option<LazyAttrTokenStream>,
10181018
}
10191019

10201020
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]
@@ -1039,7 +1039,7 @@ pub struct Local {
10391039
pub kind: LocalKind,
10401040
pub span: Span,
10411041
pub attrs: AttrVec,
1042-
pub tokens: Option<LazyTokenStream>,
1042+
pub tokens: Option<LazyAttrTokenStream>,
10431043
}
10441044

10451045
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -1138,7 +1138,7 @@ pub struct Expr {
11381138
pub kind: ExprKind,
11391139
pub span: Span,
11401140
pub attrs: AttrVec,
1141-
pub tokens: Option<LazyTokenStream>,
1141+
pub tokens: Option<LazyAttrTokenStream>,
11421142
}
11431143

11441144
impl Expr {
@@ -1997,7 +1997,7 @@ pub struct Ty {
19971997
pub id: NodeId,
19981998
pub kind: TyKind,
19991999
pub span: Span,
2000-
pub tokens: Option<LazyTokenStream>,
2000+
pub tokens: Option<LazyAttrTokenStream>,
20012001
}
20022002

20032003
impl Clone for Ty {
@@ -2562,7 +2562,7 @@ impl<D: Decoder> Decodable<D> for AttrId {
25622562
pub struct AttrItem {
25632563
pub path: Path,
25642564
pub args: MacArgs,
2565-
pub tokens: Option<LazyTokenStream>,
2565+
pub tokens: Option<LazyAttrTokenStream>,
25662566
}
25672567

25682568
/// A list of attributes.
@@ -2582,7 +2582,7 @@ pub struct Attribute {
25822582
#[derive(Clone, Encodable, Decodable, Debug)]
25832583
pub struct NormalAttr {
25842584
pub item: AttrItem,
2585-
pub tokens: Option<LazyTokenStream>,
2585+
pub tokens: Option<LazyAttrTokenStream>,
25862586
}
25872587

25882588
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -2633,7 +2633,7 @@ impl PolyTraitRef {
26332633
pub struct Visibility {
26342634
pub kind: VisibilityKind,
26352635
pub span: Span,
2636-
pub tokens: Option<LazyTokenStream>,
2636+
pub tokens: Option<LazyAttrTokenStream>,
26372637
}
26382638

26392639
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -2719,7 +2719,7 @@ pub struct Item<K = ItemKind> {
27192719
///
27202720
/// Note that the tokens here do not include the outer attributes, but will
27212721
/// include inner attributes.
2722-
pub tokens: Option<LazyTokenStream>,
2722+
pub tokens: Option<LazyAttrTokenStream>,
27232723
}
27242724

27252725
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::LazyTokenStream;
7+
use crate::tokenstream::LazyAttrTokenStream;
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};
@@ -124,18 +124,18 @@ impl HasSpan for AttrItem {
124124

125125
/// A trait for AST nodes having (or not having) collected tokens.
126126
pub trait HasTokens {
127-
fn tokens(&self) -> Option<&LazyTokenStream>;
128-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>>;
127+
fn tokens(&self) -> Option<&LazyAttrTokenStream>;
128+
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>>;
129129
}
130130

131131
macro_rules! impl_has_tokens {
132132
($($T:ty),+ $(,)?) => {
133133
$(
134134
impl HasTokens for $T {
135-
fn tokens(&self) -> Option<&LazyTokenStream> {
135+
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
136136
self.tokens.as_ref()
137137
}
138-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
138+
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
139139
Some(&mut self.tokens)
140140
}
141141
}
@@ -147,10 +147,10 @@ macro_rules! impl_has_tokens_none {
147147
($($T:ty),+ $(,)?) => {
148148
$(
149149
impl HasTokens for $T {
150-
fn tokens(&self) -> Option<&LazyTokenStream> {
150+
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
151151
None
152152
}
153-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
153+
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
154154
None
155155
}
156156
}
@@ -162,25 +162,25 @@ impl_has_tokens!(AssocItem, AttrItem, Block, Expr, ForeignItem, Item, Pat, Path,
162162
impl_has_tokens_none!(Arm, ExprField, FieldDef, GenericParam, Param, PatField, Variant);
163163

164164
impl<T: AstDeref<Target: HasTokens>> HasTokens for T {
165-
fn tokens(&self) -> Option<&LazyTokenStream> {
165+
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
166166
self.ast_deref().tokens()
167167
}
168-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
168+
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
169169
self.ast_deref_mut().tokens_mut()
170170
}
171171
}
172172

173173
impl<T: HasTokens> HasTokens for Option<T> {
174-
fn tokens(&self) -> Option<&LazyTokenStream> {
174+
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
175175
self.as_ref().and_then(|inner| inner.tokens())
176176
}
177-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
177+
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
178178
self.as_mut().and_then(|inner| inner.tokens_mut())
179179
}
180180
}
181181

182182
impl HasTokens for StmtKind {
183-
fn tokens(&self) -> Option<&LazyTokenStream> {
183+
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
184184
match self {
185185
StmtKind::Local(local) => local.tokens.as_ref(),
186186
StmtKind::Item(item) => item.tokens(),
@@ -189,7 +189,7 @@ impl HasTokens for StmtKind {
189189
StmtKind::MacCall(mac) => mac.tokens.as_ref(),
190190
}
191191
}
192-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
192+
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
193193
match self {
194194
StmtKind::Local(local) => Some(&mut local.tokens),
195195
StmtKind::Item(item) => item.tokens_mut(),
@@ -201,24 +201,24 @@ impl HasTokens for StmtKind {
201201
}
202202

203203
impl HasTokens for Stmt {
204-
fn tokens(&self) -> Option<&LazyTokenStream> {
204+
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
205205
self.kind.tokens()
206206
}
207-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
207+
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
208208
self.kind.tokens_mut()
209209
}
210210
}
211211

212212
impl HasTokens for Attribute {
213-
fn tokens(&self) -> Option<&LazyTokenStream> {
213+
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
214214
match &self.kind {
215215
AttrKind::Normal(normal) => normal.tokens.as_ref(),
216216
kind @ AttrKind::DocComment(..) => {
217217
panic!("Called tokens on doc comment attr {:?}", kind)
218218
}
219219
}
220220
}
221-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
221+
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
222222
Some(match &mut self.kind {
223223
AttrKind::Normal(normal) => &mut normal.tokens,
224224
kind @ AttrKind::DocComment(..) => {
@@ -229,7 +229,7 @@ impl HasTokens for Attribute {
229229
}
230230

231231
impl HasTokens for Nonterminal {
232-
fn tokens(&self) -> Option<&LazyTokenStream> {
232+
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
233233
match self {
234234
Nonterminal::NtItem(item) => item.tokens(),
235235
Nonterminal::NtStmt(stmt) => stmt.tokens(),
@@ -243,7 +243,7 @@ impl HasTokens for Nonterminal {
243243
Nonterminal::NtIdent(..) | Nonterminal::NtLifetime(..) => None,
244244
}
245245
}
246-
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
246+
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
247247
match self {
248248
Nonterminal::NtItem(item) => item.tokens_mut(),
249249
Nonterminal::NtStmt(stmt) => stmt.tokens_mut(),

compiler/rustc_ast/src/attr/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ast::{Path, PathSegment};
88
use crate::ptr::P;
99
use crate::token::{self, CommentKind, Delimiter, Token};
1010
use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
11-
use crate::tokenstream::{LazyTokenStream, TokenStream};
11+
use crate::tokenstream::{LazyAttrTokenStream, TokenStream};
1212
use crate::util::comments;
1313

1414
use rustc_index::bit_set::GrowableBitSet;
@@ -301,7 +301,7 @@ impl Attribute {
301301
.tokens
302302
.as_ref()
303303
.unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self))
304-
.create_token_stream()
304+
.to_attr_token_stream()
305305
.to_tokenstream(),
306306
AttrKind::DocComment(comment_kind, data) => TokenStream::new(vec![TokenTree::Token(
307307
Token::new(token::DocComment(comment_kind, self.style, data), self.span),
@@ -353,7 +353,7 @@ pub fn mk_attr(style: AttrStyle, path: Path, args: MacArgs, span: Span) -> Attri
353353

354354
pub fn mk_attr_from_item(
355355
item: AttrItem,
356-
tokens: Option<LazyTokenStream>,
356+
tokens: Option<LazyAttrTokenStream>,
357357
style: AttrStyle,
358358
span: Span,
359359
) -> Attribute {

compiler/rustc_ast/src/mut_visit.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -697,17 +697,20 @@ pub fn visit_attr_tts<T: MutVisitor>(AttrTokenStream(tts): &mut AttrTokenStream,
697697
}
698698
}
699699

700-
pub fn visit_lazy_tts_opt_mut<T: MutVisitor>(lazy_tts: Option<&mut LazyTokenStream>, vis: &mut T) {
700+
pub fn visit_lazy_tts_opt_mut<T: MutVisitor>(
701+
lazy_tts: Option<&mut LazyAttrTokenStream>,
702+
vis: &mut T,
703+
) {
701704
if T::VISIT_TOKENS {
702705
if let Some(lazy_tts) = lazy_tts {
703-
let mut tts = lazy_tts.create_token_stream();
706+
let mut tts = lazy_tts.to_attr_token_stream();
704707
visit_attr_tts(&mut tts, vis);
705-
*lazy_tts = LazyTokenStream::new(tts);
708+
*lazy_tts = LazyAttrTokenStream::new(tts);
706709
}
707710
}
708711
}
709712

710-
pub fn visit_lazy_tts<T: MutVisitor>(lazy_tts: &mut Option<LazyTokenStream>, vis: &mut T) {
713+
pub fn visit_lazy_tts<T: MutVisitor>(lazy_tts: &mut Option<LazyAttrTokenStream>, vis: &mut T) {
711714
visit_lazy_tts_opt_mut(lazy_tts.as_mut(), vis);
712715
}
713716

0 commit comments

Comments
 (0)