Skip to content

Commit 57c0ed0

Browse files
committed
Avoid interpolated token trees.
1 parent 6a9248f commit 57c0ed0

File tree

3 files changed

+9
-37
lines changed

3 files changed

+9
-37
lines changed

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,23 +480,8 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
480480
match name {
481481
"tt" => {
482482
p.quote_depth += 1; //but in theory, non-quoted tts might be useful
483-
let mut tt = panictry!(p.parse_token_tree());
483+
let tt = panictry!(p.parse_token_tree());
484484
p.quote_depth -= 1;
485-
while let TokenTree::Token(sp, token::Interpolated(nt)) = tt {
486-
if let token::NtTT(..) = *nt {
487-
match Rc::try_unwrap(nt) {
488-
Ok(token::NtTT(sub_tt)) => tt = sub_tt,
489-
Ok(_) => unreachable!(),
490-
Err(nt_rc) => match *nt_rc {
491-
token::NtTT(ref sub_tt) => tt = sub_tt.clone(),
492-
_ => unreachable!(),
493-
},
494-
}
495-
} else {
496-
tt = TokenTree::Token(sp, token::Interpolated(nt.clone()));
497-
break
498-
}
499-
}
500485
return token::NtTT(tt);
501486
}
502487
_ => {}

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use self::LockstepIterSize::*;
1212
use ast::Ident;
1313
use errors::Handler;
1414
use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
15-
use parse::token::{self, MatchNt, SubstNt, Token, NtIdent};
15+
use parse::token::{self, MatchNt, SubstNt, Token, NtIdent, NtTT};
1616
use syntax_pos::{Span, DUMMY_SP};
1717
use tokenstream::{self, TokenTree};
1818
use util::small_vector::SmallVector;
@@ -241,6 +241,7 @@ fn tt_next_token(r: &mut TtReader, prev_span: Span) -> Option<TokenTree> {
241241
NtIdent(ref sn) => {
242242
return Some(TokenTree::Token(sn.span, token::Ident(sn.node)));
243243
}
244+
NtTT(ref tt) => return Some(tt.clone()),
244245
_ => {
245246
// FIXME(pcwalton): Bad copy
246247
return Some(TokenTree::Token(sp, token::Interpolated(nt.clone())));

src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ impl<'a> Parser<'a> {
306306
}
307307

308308
fn next_tok(&mut self) -> TokenAndSpan {
309-
'outer: loop {
310-
let mut tok = if let Some((tts, i)) = self.tts.pop() {
309+
loop {
310+
let tok = if let Some((tts, i)) = self.tts.pop() {
311311
let tt = tts.get_tt(i);
312312
if i + 1 < tts.len() {
313313
self.tts.push((tts, i + 1));
@@ -322,25 +322,11 @@ impl<'a> Parser<'a> {
322322
TokenAndSpan { tok: token::Eof, sp: self.span }
323323
};
324324

325-
loop {
326-
let nt = match tok.tok {
327-
token::Interpolated(ref nt) => nt.clone(),
328-
token::DocComment(name) if self.desugar_doc_comments => {
329-
self.tts.push((TokenTree::Token(tok.sp, token::DocComment(name)), 0));
330-
continue 'outer
331-
}
332-
_ => return tok,
333-
};
334-
match *nt {
335-
token::NtTT(TokenTree::Token(sp, ref t)) => {
336-
tok = TokenAndSpan { tok: t.clone(), sp: sp };
337-
}
338-
token::NtTT(ref tt) => {
339-
self.tts.push((tt.clone(), 0));
340-
continue 'outer
341-
}
342-
_ => return tok,
325+
match tok.tok {
326+
token::DocComment(name) if self.desugar_doc_comments => {
327+
self.tts.push((TokenTree::Token(tok.sp, token::DocComment(name)), 0));
343328
}
329+
_ => return tok,
344330
}
345331
}
346332
}

0 commit comments

Comments
 (0)