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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 19 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 2 additions & 3 deletions
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
};

0 commit comments

Comments
 (0)