Skip to content

Commit ccf41dd

Browse files
committed
Rename IsJoint -> Spacing
To match better naming from proc-macro
1 parent 4231fbc commit ccf41dd

File tree

10 files changed

+62
-65
lines changed

10 files changed

+62
-65
lines changed

compiler/rustc_ast/src/attr/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ast::{Path, PathSegment};
88
use crate::mut_visit::visit_clobber;
99
use crate::ptr::P;
1010
use crate::token::{self, CommentKind, Token};
11-
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
11+
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndSpacing};
1212

1313
use rustc_index::bit_set::GrowableBitSet;
1414
use rustc_span::source_map::{BytePos, Spanned};
@@ -361,7 +361,7 @@ pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
361361
}
362362

363363
impl MetaItem {
364-
fn token_trees_and_joints(&self) -> Vec<TreeAndJoint> {
364+
fn token_trees_and_spacings(&self) -> Vec<TreeAndSpacing> {
365365
let mut idents = vec![];
366366
let mut last_pos = BytePos(0 as u32);
367367
for (i, segment) in self.path.segments.iter().enumerate() {
@@ -374,7 +374,7 @@ impl MetaItem {
374374
idents.push(TokenTree::Token(Token::from_ast_ident(segment.ident)).into());
375375
last_pos = segment.ident.span.hi();
376376
}
377-
idents.extend(self.kind.token_trees_and_joints(self.span));
377+
idents.extend(self.kind.token_trees_and_spacings(self.span));
378378
idents
379379
}
380380

@@ -447,7 +447,7 @@ impl MetaItemKind {
447447
if i > 0 {
448448
tts.push(TokenTree::token(token::Comma, span).into());
449449
}
450-
tts.extend(item.token_trees_and_joints())
450+
tts.extend(item.token_trees_and_spacings())
451451
}
452452
MacArgs::Delimited(
453453
DelimSpan::from_single(span),
@@ -458,7 +458,7 @@ impl MetaItemKind {
458458
}
459459
}
460460

461-
fn token_trees_and_joints(&self, span: Span) -> Vec<TreeAndJoint> {
461+
fn token_trees_and_spacings(&self, span: Span) -> Vec<TreeAndSpacing> {
462462
match *self {
463463
MetaItemKind::Word => vec![],
464464
MetaItemKind::NameValue(ref lit) => {
@@ -470,7 +470,7 @@ impl MetaItemKind {
470470
if i > 0 {
471471
tokens.push(TokenTree::token(token::Comma, span).into());
472472
}
473-
tokens.extend(item.token_trees_and_joints())
473+
tokens.extend(item.token_trees_and_spacings())
474474
}
475475
vec![
476476
TokenTree::Delimited(
@@ -553,9 +553,9 @@ impl NestedMetaItem {
553553
}
554554
}
555555

556-
fn token_trees_and_joints(&self) -> Vec<TreeAndJoint> {
556+
fn token_trees_and_spacings(&self) -> Vec<TreeAndSpacing> {
557557
match *self {
558-
NestedMetaItem::MetaItem(ref item) => item.token_trees_and_joints(),
558+
NestedMetaItem::MetaItem(ref item) => item.token_trees_and_spacings(),
559559
NestedMetaItem::Literal(ref lit) => vec![lit.token_tree().into()],
560560
}
561561
}

compiler/rustc_ast/src/tokenstream.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl TokenTree {
8383
}
8484

8585
pub fn joint(self) -> TokenStream {
86-
TokenStream::new(vec![(self, Joint)])
86+
TokenStream::new(vec![(self, Spacing::Joint)])
8787
}
8888

8989
pub fn token(kind: TokenKind, span: Span) -> TokenTree {
@@ -125,22 +125,20 @@ where
125125
/// instead of a representation of the abstract syntax tree.
126126
/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for back-compat.
127127
#[derive(Clone, Debug, Default, Encodable, Decodable)]
128-
pub struct TokenStream(pub Lrc<Vec<TreeAndJoint>>);
128+
pub struct TokenStream(pub Lrc<Vec<TreeAndSpacing>>);
129129

130-
pub type TreeAndJoint = (TokenTree, IsJoint);
130+
pub type TreeAndSpacing = (TokenTree, Spacing);
131131

132132
// `TokenStream` is used a lot. Make sure it doesn't unintentionally get bigger.
133133
#[cfg(target_arch = "x86_64")]
134134
rustc_data_structures::static_assert_size!(TokenStream, 8);
135135

136136
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable)]
137-
pub enum IsJoint {
137+
pub enum Spacing {
138+
Alone,
138139
Joint,
139-
NonJoint,
140140
}
141141

142-
use IsJoint::*;
143-
144142
impl TokenStream {
145143
/// Given a `TokenStream` with a `Stream` of only two arguments, return a new `TokenStream`
146144
/// separating the two arguments with a comma for diagnostic suggestions.
@@ -153,7 +151,7 @@ impl TokenStream {
153151
let sp = match (&ts, &next) {
154152
(_, (TokenTree::Token(Token { kind: token::Comma, .. }), _)) => continue,
155153
(
156-
(TokenTree::Token(token_left), NonJoint),
154+
(TokenTree::Token(token_left), Spacing::Alone),
157155
(TokenTree::Token(token_right), _),
158156
) if ((token_left.is_ident() && !token_left.is_reserved_ident())
159157
|| token_left.is_lit())
@@ -162,11 +160,11 @@ impl TokenStream {
162160
{
163161
token_left.span
164162
}
165-
((TokenTree::Delimited(sp, ..), NonJoint), _) => sp.entire(),
163+
((TokenTree::Delimited(sp, ..), Spacing::Alone), _) => sp.entire(),
166164
_ => continue,
167165
};
168166
let sp = sp.shrink_to_hi();
169-
let comma = (TokenTree::token(token::Comma, sp), NonJoint);
167+
let comma = (TokenTree::token(token::Comma, sp), Spacing::Alone);
170168
suggestion = Some((pos, comma, sp));
171169
}
172170
}
@@ -184,19 +182,19 @@ impl TokenStream {
184182

185183
impl From<TokenTree> for TokenStream {
186184
fn from(tree: TokenTree) -> TokenStream {
187-
TokenStream::new(vec![(tree, NonJoint)])
185+
TokenStream::new(vec![(tree, Spacing::Alone)])
188186
}
189187
}
190188

191-
impl From<TokenTree> for TreeAndJoint {
192-
fn from(tree: TokenTree) -> TreeAndJoint {
193-
(tree, NonJoint)
189+
impl From<TokenTree> for TreeAndSpacing {
190+
fn from(tree: TokenTree) -> TreeAndSpacing {
191+
(tree, Spacing::Alone)
194192
}
195193
}
196194

197195
impl iter::FromIterator<TokenTree> for TokenStream {
198196
fn from_iter<I: IntoIterator<Item = TokenTree>>(iter: I) -> Self {
199-
TokenStream::new(iter.into_iter().map(Into::into).collect::<Vec<TreeAndJoint>>())
197+
TokenStream::new(iter.into_iter().map(Into::into).collect::<Vec<TreeAndSpacing>>())
200198
}
201199
}
202200

@@ -209,7 +207,7 @@ impl PartialEq<TokenStream> for TokenStream {
209207
}
210208

211209
impl TokenStream {
212-
pub fn new(streams: Vec<TreeAndJoint>) -> TokenStream {
210+
pub fn new(streams: Vec<TreeAndSpacing>) -> TokenStream {
213211
TokenStream(Lrc::new(streams))
214212
}
215213

@@ -320,11 +318,11 @@ impl TokenStreamBuilder {
320318
// If `self` is not empty and the last tree within the last stream is a
321319
// token tree marked with `Joint`...
322320
if let Some(TokenStream(ref mut last_stream_lrc)) = self.0.last_mut() {
323-
if let Some((TokenTree::Token(last_token), Joint)) = last_stream_lrc.last() {
321+
if let Some((TokenTree::Token(last_token), Spacing::Joint)) = last_stream_lrc.last() {
324322
// ...and `stream` is not empty and the first tree within it is
325323
// a token tree...
326324
let TokenStream(ref mut stream_lrc) = stream;
327-
if let Some((TokenTree::Token(token), is_joint)) = stream_lrc.first() {
325+
if let Some((TokenTree::Token(token), spacing)) = stream_lrc.first() {
328326
// ...and the two tokens can be glued together...
329327
if let Some(glued_tok) = last_token.glue(&token) {
330328
// ...then do so, by overwriting the last token
@@ -337,8 +335,7 @@ impl TokenStreamBuilder {
337335
// Overwrite the last token tree with the merged
338336
// token.
339337
let last_vec_mut = Lrc::make_mut(last_stream_lrc);
340-
*last_vec_mut.last_mut().unwrap() =
341-
(TokenTree::Token(glued_tok), *is_joint);
338+
*last_vec_mut.last_mut().unwrap() = (TokenTree::Token(glued_tok), *spacing);
342339

343340
// Remove the first token tree from `stream`. (This
344341
// is almost always the only tree in `stream`.)
@@ -375,7 +372,7 @@ impl Iterator for Cursor {
375372
type Item = TokenTree;
376373

377374
fn next(&mut self) -> Option<TokenTree> {
378-
self.next_with_joint().map(|(tree, _)| tree)
375+
self.next_with_spacing().map(|(tree, _)| tree)
379376
}
380377
}
381378

@@ -384,7 +381,7 @@ impl Cursor {
384381
Cursor { stream, index: 0 }
385382
}
386383

387-
pub fn next_with_joint(&mut self) -> Option<TreeAndJoint> {
384+
pub fn next_with_spacing(&mut self) -> Option<TreeAndSpacing> {
388385
if self.index < self.stream.len() {
389386
self.index += 1;
390387
Some(self.stream.0[self.index - 1].clone())

compiler/rustc_expand/src/mbe/transcribe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedMatch};
44

55
use rustc_ast::mut_visit::{self, MutVisitor};
66
use rustc_ast::token::{self, NtTT, Token};
7-
use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
7+
use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndSpacing};
88
use rustc_ast::MacCall;
99
use rustc_data_structures::fx::FxHashMap;
1010
use rustc_data_structures::sync::Lrc;
@@ -111,7 +111,7 @@ pub(super) fn transcribe<'a>(
111111
//
112112
// Thus, if we try to pop the `result_stack` and it is empty, we have reached the top-level
113113
// again, and we are done transcribing.
114-
let mut result: Vec<TreeAndJoint> = Vec::new();
114+
let mut result: Vec<TreeAndSpacing> = Vec::new();
115115
let mut result_stack = Vec::new();
116116
let mut marker = Marker(cx.current_expansion.id, transparency);
117117

compiler/rustc_expand/src/proc_macro_server.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::base::ExtCtxt;
22

33
use rustc_ast as ast;
44
use rustc_ast::token;
5-
use rustc_ast::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
5+
use rustc_ast::tokenstream::{self, DelimSpan, Spacing::*, TokenStream, TreeAndSpacing};
66
use rustc_ast_pretty::pprust;
77
use rustc_data_structures::sync::Lrc;
88
use rustc_errors::Diagnostic;
@@ -47,15 +47,15 @@ impl ToInternal<token::DelimToken> for Delimiter {
4747
}
4848
}
4949

50-
impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
50+
impl FromInternal<(TreeAndSpacing, &'_ ParseSess, &'_ mut Vec<Self>)>
5151
for TokenTree<Group, Punct, Ident, Literal>
5252
{
5353
fn from_internal(
54-
((tree, is_joint), sess, stack): (TreeAndJoint, &ParseSess, &mut Vec<Self>),
54+
((tree, spacing), sess, stack): (TreeAndSpacing, &ParseSess, &mut Vec<Self>),
5555
) -> Self {
5656
use rustc_ast::token::*;
5757

58-
let joint = is_joint == Joint;
58+
let joint = spacing == Joint;
5959
let Token { kind, span } = match tree {
6060
tokenstream::TokenTree::Delimited(span, delim, tts) => {
6161
let delimiter = Delimiter::from_internal(delim);
@@ -261,7 +261,7 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
261261
};
262262

263263
let tree = tokenstream::TokenTree::token(kind, span);
264-
TokenStream::new(vec![(tree, if joint { Joint } else { NonJoint })])
264+
TokenStream::new(vec![(tree, if joint { Joint } else { Alone })])
265265
}
266266
}
267267

@@ -444,7 +444,7 @@ impl server::TokenStreamIter for Rustc<'_> {
444444
) -> Option<TokenTree<Self::Group, Self::Punct, Self::Ident, Self::Literal>> {
445445
loop {
446446
let tree = iter.stack.pop().or_else(|| {
447-
let next = iter.cursor.next_with_joint()?;
447+
let next = iter.cursor.next_with_spacing()?;
448448
Some(TokenTree::from_internal((next, self.sess, &mut iter.stack)))
449449
})?;
450450
// A hack used to pass AST fragments to attribute and derive macros

compiler/rustc_parse/src/lexer/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast::ast::AttrStyle;
22
use rustc_ast::token::{self, CommentKind, Token, TokenKind};
3-
use rustc_ast::tokenstream::{IsJoint, TokenStream};
3+
use rustc_ast::tokenstream::{Spacing, TokenStream};
44
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, FatalError, PResult};
55
use rustc_lexer::unescape::{self, Mode};
66
use rustc_lexer::{Base, DocStyle, RawStrError};
@@ -54,8 +54,8 @@ impl<'a> StringReader<'a> {
5454
}
5555

5656
/// Returns the next token, and info about preceding whitespace, if any.
57-
fn next_token(&mut self) -> (IsJoint, Token) {
58-
let mut is_joint = IsJoint::Joint;
57+
fn next_token(&mut self) -> (Spacing, Token) {
58+
let mut spacing = Spacing::Joint;
5959

6060
// Skip `#!` at the start of the file
6161
let start_src_index = self.src_index(self.pos);
@@ -64,7 +64,7 @@ impl<'a> StringReader<'a> {
6464
if is_beginning_of_file {
6565
if let Some(shebang_len) = rustc_lexer::strip_shebang(text) {
6666
self.pos = self.pos + BytePos::from_usize(shebang_len);
67-
is_joint = IsJoint::NonJoint;
67+
spacing = Spacing::Alone;
6868
}
6969
}
7070

@@ -75,7 +75,7 @@ impl<'a> StringReader<'a> {
7575

7676
if text.is_empty() {
7777
let span = self.mk_sp(self.pos, self.pos);
78-
return (is_joint, Token::new(token::Eof, span));
78+
return (spacing, Token::new(token::Eof, span));
7979
}
8080

8181
let token = rustc_lexer::first_token(text);
@@ -88,9 +88,9 @@ impl<'a> StringReader<'a> {
8888
match self.cook_lexer_token(token.kind, start) {
8989
Some(kind) => {
9090
let span = self.mk_sp(start, self.pos);
91-
return (is_joint, Token::new(kind, span));
91+
return (spacing, Token::new(kind, span));
9292
}
93-
None => is_joint = IsJoint::NonJoint,
93+
None => spacing = Spacing::Alone,
9494
}
9595
}
9696
}

compiler/rustc_parse/src/lexer/tokentrees.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use super::{StringReader, UnmatchedBrace};
33
use rustc_ast::token::{self, DelimToken, Token};
44
use rustc_ast::tokenstream::{
55
DelimSpan,
6-
IsJoint::{self, *},
7-
TokenStream, TokenTree, TreeAndJoint,
6+
Spacing::{self, *},
7+
TokenStream, TokenTree, TreeAndSpacing,
88
};
99
use rustc_ast_pretty::pprust::token_to_string;
1010
use rustc_data_structures::fx::FxHashMap;
@@ -77,7 +77,7 @@ impl<'a> TokenTreesReader<'a> {
7777
}
7878
}
7979

80-
fn parse_token_tree(&mut self) -> PResult<'a, TreeAndJoint> {
80+
fn parse_token_tree(&mut self) -> PResult<'a, TreeAndSpacing> {
8181
let sm = self.string_reader.sess.source_map();
8282

8383
match self.token.kind {
@@ -262,29 +262,29 @@ impl<'a> TokenTreesReader<'a> {
262262
}
263263
_ => {
264264
let tt = TokenTree::Token(self.token.take());
265-
let mut is_joint = self.bump();
265+
let mut spacing = self.bump();
266266
if !self.token.is_op() {
267-
is_joint = NonJoint;
267+
spacing = Alone;
268268
}
269-
Ok((tt, is_joint))
269+
Ok((tt, spacing))
270270
}
271271
}
272272
}
273273

274-
fn bump(&mut self) -> IsJoint {
275-
let (joint_to_prev, token) = self.string_reader.next_token();
274+
fn bump(&mut self) -> Spacing {
275+
let (spacing, token) = self.string_reader.next_token();
276276
self.token = token;
277-
joint_to_prev
277+
spacing
278278
}
279279
}
280280

281281
#[derive(Default)]
282282
struct TokenStreamBuilder {
283-
buf: Vec<TreeAndJoint>,
283+
buf: Vec<TreeAndSpacing>,
284284
}
285285

286286
impl TokenStreamBuilder {
287-
fn push(&mut self, (tree, joint): TreeAndJoint) {
287+
fn push(&mut self, (tree, joint): TreeAndSpacing) {
288288
if let Some((TokenTree::Token(prev_token), Joint)) = self.buf.last() {
289289
if let TokenTree::Token(token) = &tree {
290290
if let Some(glued) = prev_token.glue(token) {

compiler/rustc_parse/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use rustc_ast as ast;
1010
use rustc_ast::token::{self, DelimToken, Nonterminal, Token, TokenKind};
11-
use rustc_ast::tokenstream::{self, IsJoint, TokenStream, TokenTree};
11+
use rustc_ast::tokenstream::{self, Spacing, TokenStream, TokenTree};
1212
use rustc_ast_pretty::pprust;
1313
use rustc_data_structures::sync::Lrc;
1414
use rustc_errors::{Diagnostic, FatalError, Level, PResult};
@@ -437,7 +437,7 @@ pub fn tokenstream_probably_equal_for_proc_macro(
437437
// issue #75734 tracks resolving this.
438438
nt_to_tokenstream(nt, sess, *span).into_trees()
439439
} else {
440-
TokenStream::new(vec![(tree, IsJoint::NonJoint)]).into_trees()
440+
TokenStream::new(vec![(tree, Spacing::Alone)]).into_trees()
441441
}
442442
};
443443

0 commit comments

Comments
 (0)