Skip to content

Commit b37434e

Browse files
committed
Remove token::FlattenGroup
1 parent a5764de commit b37434e

File tree

18 files changed

+42
-64
lines changed

18 files changed

+42
-64
lines changed

src/librustc_ast/attr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl MetaItem {
475475
let span = span.with_hi(segments.last().unwrap().ident.span.hi());
476476
Path { span, segments }
477477
}
478-
Some(TokenTree::Token(Token { kind: token::Interpolated(nt, _), .. })) => match *nt {
478+
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. })) => match *nt {
479479
token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span),
480480
token::Nonterminal::NtPath(ref path) => path.clone(),
481481
_ => return None,

src/librustc_ast/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ pub fn noop_visit_token<T: MutVisitor>(t: &mut Token, vis: &mut T) {
656656
*span = ident.span;
657657
return; // Avoid visiting the span for the second time.
658658
}
659-
token::Interpolated(nt, _) => {
659+
token::Interpolated(nt) => {
660660
let mut nt = Lrc::make_mut(nt);
661661
vis.visit_interpolated(&mut nt);
662662
}

src/librustc_ast/token.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,6 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool {
182182
.contains(&name)
183183
}
184184

185-
/// A hack used to pass AST fragments to attribute and derive macros
186-
/// as a single nonterminal token instead of a token stream.
187-
/// FIXME: It needs to be removed, but there are some compatibility issues (see #73345).
188-
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
189-
pub enum FlattenGroup {
190-
Yes,
191-
No,
192-
}
193-
194185
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
195186
pub enum TokenKind {
196187
/* Expression-operator symbols. */
@@ -245,7 +236,7 @@ pub enum TokenKind {
245236
/// treat regular and interpolated lifetime identifiers in the same way.
246237
Lifetime(Symbol),
247238

248-
Interpolated(Lrc<Nonterminal>, FlattenGroup),
239+
Interpolated(Lrc<Nonterminal>),
249240

250241
// Can be expanded into several tokens.
251242
/// A doc comment.
@@ -352,7 +343,7 @@ impl Token {
352343
/// if they keep spans or perform edition checks.
353344
pub fn uninterpolated_span(&self) -> Span {
354345
match &self.kind {
355-
Interpolated(nt, _) => nt.span(),
346+
Interpolated(nt) => nt.span(),
356347
_ => self.span,
357348
}
358349
}
@@ -391,7 +382,7 @@ impl Token {
391382
ModSep | // global path
392383
Lifetime(..) | // labeled loop
393384
Pound => true, // expression attributes
394-
Interpolated(ref nt, _) => match **nt {
385+
Interpolated(ref nt) => match **nt {
395386
NtLiteral(..) |
396387
NtExpr(..) |
397388
NtBlock(..) |
@@ -417,7 +408,7 @@ impl Token {
417408
Lifetime(..) | // lifetime bound in trait object
418409
Lt | BinOp(Shl) | // associated path
419410
ModSep => true, // global path
420-
Interpolated(ref nt, _) => match **nt {
411+
Interpolated(ref nt) => match **nt {
421412
NtTy(..) | NtPath(..) => true,
422413
_ => false,
423414
},
@@ -429,7 +420,7 @@ impl Token {
429420
pub fn can_begin_const_arg(&self) -> bool {
430421
match self.kind {
431422
OpenDelim(Brace) => true,
432-
Interpolated(ref nt, _) => match **nt {
423+
Interpolated(ref nt) => match **nt {
433424
NtExpr(..) | NtBlock(..) | NtLiteral(..) => true,
434425
_ => false,
435426
},
@@ -464,7 +455,7 @@ impl Token {
464455
match self.uninterpolate().kind {
465456
Literal(..) | BinOp(Minus) => true,
466457
Ident(name, false) if name.is_bool_lit() => true,
467-
Interpolated(ref nt, _) => match &**nt {
458+
Interpolated(ref nt) => match &**nt {
468459
NtLiteral(_) => true,
469460
NtExpr(e) => match &e.kind {
470461
ast::ExprKind::Lit(_) => true,
@@ -485,7 +476,7 @@ impl Token {
485476
// otherwise returns the original token.
486477
pub fn uninterpolate(&self) -> Cow<'_, Token> {
487478
match &self.kind {
488-
Interpolated(nt, _) => match **nt {
479+
Interpolated(nt) => match **nt {
489480
NtIdent(ident, is_raw) => {
490481
Cow::Owned(Token::new(Ident(ident.name, is_raw), ident.span))
491482
}
@@ -532,7 +523,7 @@ impl Token {
532523

533524
/// Returns `true` if the token is an interpolated path.
534525
fn is_path(&self) -> bool {
535-
if let Interpolated(ref nt, _) = self.kind {
526+
if let Interpolated(ref nt) = self.kind {
536527
if let NtPath(..) = **nt {
537528
return true;
538529
}
@@ -544,7 +535,7 @@ impl Token {
544535
/// That is, is this a pre-parsed expression dropped into the token stream
545536
/// (which happens while parsing the result of macro expansion)?
546537
pub fn is_whole_expr(&self) -> bool {
547-
if let Interpolated(ref nt, _) = self.kind {
538+
if let Interpolated(ref nt) = self.kind {
548539
if let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtIdent(..) | NtBlock(_) = **nt {
549540
return true;
550541
}
@@ -555,7 +546,7 @@ impl Token {
555546

556547
// Is the token an interpolated block (`$b:block`)?
557548
pub fn is_whole_block(&self) -> bool {
558-
if let Interpolated(ref nt, _) = self.kind {
549+
if let Interpolated(ref nt) = self.kind {
559550
if let NtBlock(..) = **nt {
560551
return true;
561552
}

src/librustc_ast/util/literal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl Lit {
205205
token::Lit::new(token::Bool, name, None)
206206
}
207207
token::Literal(lit) => lit,
208-
token::Interpolated(ref nt, _) => {
208+
token::Interpolated(ref nt) => {
209209
if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt {
210210
if let ast::ExprKind::Lit(lit) = &expr.kind {
211211
return Ok(lit.clone());

src/librustc_ast_lowering/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10271027

10281028
fn lower_token(&mut self, token: Token) -> TokenStream {
10291029
match token.kind {
1030-
token::Interpolated(nt, _) => {
1030+
token::Interpolated(nt) => {
10311031
let tts = (self.nt_to_tokenstream)(&nt, &self.sess.parse_sess, token.span);
10321032
self.lower_token_stream(tts)
10331033
}

src/librustc_ast_pretty/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
278278
token::Shebang(s) => format!("/* shebang: {}*/", s),
279279
token::Unknown(s) => s.to_string(),
280280

281-
token::Interpolated(ref nt, _) => nonterminal_to_string(nt),
281+
token::Interpolated(ref nt) => nonterminal_to_string(nt),
282282
}
283283
}
284284

src/librustc_expand/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ where
371371
impl MutVisitor for AvoidInterpolatedIdents {
372372
fn visit_tt(&mut self, tt: &mut tokenstream::TokenTree) {
373373
if let tokenstream::TokenTree::Token(token) = tt {
374-
if let token::Interpolated(nt, _) = &token.kind {
374+
if let token::Interpolated(nt) = &token.kind {
375375
if let token::NtIdent(ident, is_raw) = **nt {
376376
*tt = tokenstream::TokenTree::token(
377377
token::Ident(ident.name, is_raw),

src/librustc_expand/mbe/macro_parser.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ fn may_begin_with(token: &Token, name: Symbol) -> bool {
790790
},
791791
sym::block => match token.kind {
792792
token::OpenDelim(token::Brace) => true,
793-
token::Interpolated(ref nt, _) => match **nt {
793+
token::Interpolated(ref nt) => match **nt {
794794
token::NtItem(_)
795795
| token::NtPat(_)
796796
| token::NtTy(_)
@@ -804,7 +804,7 @@ fn may_begin_with(token: &Token, name: Symbol) -> bool {
804804
},
805805
sym::path | sym::meta => match token.kind {
806806
token::ModSep | token::Ident(..) => true,
807-
token::Interpolated(ref nt, _) => match **nt {
807+
token::Interpolated(ref nt) => match **nt {
808808
token::NtPath(_) | token::NtMeta(_) => true,
809809
_ => may_be_ident(&nt),
810810
},
@@ -823,12 +823,12 @@ fn may_begin_with(token: &Token, name: Symbol) -> bool {
823823
token::ModSep | // path
824824
token::Lt | // path (UFCS constant)
825825
token::BinOp(token::Shl) => true, // path (double UFCS)
826-
token::Interpolated(ref nt, _) => may_be_ident(nt),
826+
token::Interpolated(ref nt) => may_be_ident(nt),
827827
_ => false,
828828
},
829829
sym::lifetime => match token.kind {
830830
token::Lifetime(_) => true,
831-
token::Interpolated(ref nt, _) => match **nt {
831+
token::Interpolated(ref nt) => match **nt {
832832
token::NtLifetime(_) | token::NtTT(_) => true,
833833
_ => false,
834834
},

src/librustc_expand/mbe/transcribe.rs

+2-5
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::ast::MacCall;
66
use rustc_ast::mut_visit::{self, MutVisitor};
7-
use rustc_ast::token::{self, FlattenGroup, NtTT, Token};
7+
use rustc_ast::token::{self, NtTT, Token};
88
use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
99
use rustc_data_structures::fx::FxHashMap;
1010
use rustc_data_structures::sync::Lrc;
@@ -240,10 +240,7 @@ pub(super) fn transcribe<'a>(
240240
result.push(tt.clone().into());
241241
} else {
242242
marker.visit_span(&mut sp);
243-
let token = TokenTree::token(
244-
token::Interpolated(nt.clone(), FlattenGroup::No),
245-
sp,
246-
);
243+
let token = TokenTree::token(token::Interpolated(nt.clone()), sp);
247244
result.push(token.into());
248245
}
249246
} else {

src/librustc_expand/proc_macro.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::base::{self, *};
22
use crate::proc_macro_server;
33

44
use rustc_ast::ast::{self, ItemKind, MetaItemKind, NestedMetaItem};
5-
use rustc_ast::token::{self, FlattenGroup};
5+
use rustc_ast::token;
66
use rustc_ast::tokenstream::{TokenStream, TokenTree};
77
use rustc_data_structures::sync::Lrc;
88
use rustc_errors::{Applicability, ErrorReported};
@@ -105,8 +105,7 @@ impl MultiItemModifier for ProcMacroDerive {
105105

106106
let item = token::NtItem(item);
107107
let input = if item.pretty_printing_compatibility_hack() {
108-
TokenTree::token(token::Interpolated(Lrc::new(item), FlattenGroup::Yes), DUMMY_SP)
109-
.into()
108+
TokenTree::token(token::Interpolated(Lrc::new(item)), DUMMY_SP).into()
110109
} else {
111110
nt_to_tokenstream(&item, ecx.parse_sess, DUMMY_SP)
112111
};

src/librustc_expand/proc_macro_server.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::base::ExtCtxt;
22

33
use rustc_ast::ast;
4-
use rustc_ast::token::{self, FlattenGroup};
4+
use rustc_ast::token;
55
use rustc_ast::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
66
use rustc_ast::util::comments;
77
use rustc_ast_pretty::pprust;
@@ -60,12 +60,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
6060
let Token { kind, span } = match tree {
6161
tokenstream::TokenTree::Delimited(span, delim, tts) => {
6262
let delimiter = Delimiter::from_internal(delim);
63-
return TokenTree::Group(Group {
64-
delimiter,
65-
stream: tts,
66-
span,
67-
flatten: FlattenGroup::No,
68-
});
63+
return TokenTree::Group(Group { delimiter, stream: tts, span, flatten: false });
6964
}
7065
tokenstream::TokenTree::Token(token) => token,
7166
};
@@ -172,25 +167,21 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
172167
delimiter: Delimiter::Bracket,
173168
stream,
174169
span: DelimSpan::from_single(span),
175-
flatten: FlattenGroup::No,
170+
flatten: false,
176171
}));
177172
if style == ast::AttrStyle::Inner {
178173
stack.push(tt!(Punct::new('!', false)));
179174
}
180175
tt!(Punct::new('#', false))
181176
}
182177

183-
Interpolated(nt, _) => {
178+
Interpolated(nt) => {
184179
let stream = nt_to_tokenstream(&nt, sess, span);
185180
TokenTree::Group(Group {
186181
delimiter: Delimiter::None,
187182
stream,
188183
span: DelimSpan::from_single(span),
189-
flatten: if nt.pretty_printing_compatibility_hack() {
190-
FlattenGroup::Yes
191-
} else {
192-
FlattenGroup::No
193-
},
184+
flatten: nt.pretty_printing_compatibility_hack(),
194185
})
195186
}
196187

@@ -297,7 +288,7 @@ pub struct Group {
297288
/// A hack used to pass AST fragments to attribute and derive macros
298289
/// as a single nonterminal token instead of a token stream.
299290
/// FIXME: It needs to be removed, but there are some compatibility issues (see #73345).
300-
flatten: FlattenGroup,
291+
flatten: bool,
301292
}
302293

303294
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
@@ -457,7 +448,7 @@ impl server::TokenStreamIter for Rustc<'_> {
457448
// Such token needs to be "unwrapped" and not represented as a delimited group.
458449
// FIXME: It needs to be removed, but there are some compatibility issues (see #73345).
459450
if let TokenTree::Group(ref group) = tree {
460-
if matches!(group.flatten, FlattenGroup::Yes) {
451+
if group.flatten {
461452
iter.cursor.append(group.stream.clone());
462453
continue;
463454
}
@@ -473,7 +464,7 @@ impl server::Group for Rustc<'_> {
473464
delimiter,
474465
stream,
475466
span: DelimSpan::from_single(server::Span::call_site(self)),
476-
flatten: FlattenGroup::No,
467+
flatten: false,
477468
}
478469
}
479470
fn delimiter(&mut self, group: &Self::Group) -> Delimiter {

src/librustc_parse/parser/attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a> Parser<'a> {
155155
/// The delimiters or `=` are still put into the resulting token stream.
156156
pub fn parse_attr_item(&mut self) -> PResult<'a, ast::AttrItem> {
157157
let item = match self.token.kind {
158-
token::Interpolated(ref nt, _) => match **nt {
158+
token::Interpolated(ref nt) => match **nt {
159159
Nonterminal::NtMeta(ref item) => Some(item.clone().into_inner()),
160160
_ => None,
161161
},
@@ -254,7 +254,7 @@ impl<'a> Parser<'a> {
254254
/// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
255255
pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> {
256256
let nt_meta = match self.token.kind {
257-
token::Interpolated(ref nt, _) => match **nt {
257+
token::Interpolated(ref nt) => match **nt {
258258
token::NtMeta(ref e) => Some(e.clone()),
259259
_ => None,
260260
},

src/librustc_parse/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::mem;
2626
/// `token::Interpolated` tokens.
2727
macro_rules! maybe_whole_expr {
2828
($p:expr) => {
29-
if let token::Interpolated(nt, _) = &$p.token.kind {
29+
if let token::Interpolated(nt) = &$p.token.kind {
3030
match &**nt {
3131
token::NtExpr(e) | token::NtLiteral(e) => {
3232
let e = e.clone();

src/librustc_parse/parser/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ impl<'a> Parser<'a> {
17801780

17811781
fn is_named_param(&self) -> bool {
17821782
let offset = match self.token.kind {
1783-
token::Interpolated(ref nt, _) => match **nt {
1783+
token::Interpolated(ref nt) => match **nt {
17841784
token::NtPat(..) => return self.look_ahead(1, |t| t == &token::Colon),
17851785
_ => 0,
17861786
},

src/librustc_parse/parser/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum BlockMode {
5454
#[macro_export]
5555
macro_rules! maybe_whole {
5656
($p:expr, $constructor:ident, |$x:ident| $e:expr) => {
57-
if let token::Interpolated(nt, _) = &$p.token.kind {
57+
if let token::Interpolated(nt) = &$p.token.kind {
5858
if let token::$constructor(x) = &**nt {
5959
let $x = x.clone();
6060
$p.bump();
@@ -69,7 +69,7 @@ macro_rules! maybe_whole {
6969
macro_rules! maybe_recover_from_interpolated_ty_qpath {
7070
($self: expr, $allow_qpath_recovery: expr) => {
7171
if $allow_qpath_recovery && $self.look_ahead(1, |t| t == &token::ModSep) {
72-
if let token::Interpolated(nt, _) = &$self.token.kind {
72+
if let token::Interpolated(nt) = &$self.token.kind {
7373
if let token::NtTy(ty) = &**nt {
7474
let ty = ty.clone();
7575
$self.bump();
@@ -922,7 +922,7 @@ impl<'a> Parser<'a> {
922922
if self.eat(&token::Eq) {
923923
let eq_span = self.prev_token.span;
924924
let mut is_interpolated_expr = false;
925-
if let token::Interpolated(nt, _) = &self.token.kind {
925+
if let token::Interpolated(nt) = &self.token.kind {
926926
if let token::NtExpr(..) = **nt {
927927
is_interpolated_expr = true;
928928
}

src/librustc_parse/parser/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ impl<'a> Parser<'a> {
515515
self.recover_additional_muts();
516516

517517
// Make sure we don't allow e.g. `let mut $p;` where `$p:pat`.
518-
if let token::Interpolated(ref nt, _) = self.token.kind {
518+
if let token::Interpolated(ref nt) = self.token.kind {
519519
if let token::NtPat(_) = **nt {
520520
self.expected_ident_found().emit();
521521
}

src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
13251325
}
13261326

13271327
fn visit_token(&mut self, t: Token) {
1328-
if let token::Interpolated(nt, _) = t.kind {
1328+
if let token::Interpolated(nt) = t.kind {
13291329
if let token::NtExpr(ref expr) = *nt {
13301330
if let ast::ExprKind::MacCall(..) = expr.kind {
13311331
self.visit_invoc(expr.id);

0 commit comments

Comments
 (0)