diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-01-14 12:42:00 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-01-17 08:17:28 +0000 |
| commit | 57c0ed097ce150fa1d684b5b3b5479a5dedd2b7b (patch) | |
| tree | 5415d467292eac15b8ef9472834d53ec5fb2f479 /src/libsyntax | |
| parent | 6a9248fc1525e619d4ffb2b895a8d15c4bf90de8 (diff) | |
| download | rust-57c0ed097ce150fa1d684b5b3b5479a5dedd2b7b.tar.gz rust-57c0ed097ce150fa1d684b5b3b5479a5dedd2b7b.zip | |
Avoid interpolated token trees.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 26 |
3 files changed, 9 insertions, 37 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 46ffc93d2ee..834ece97af5 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -480,23 +480,8 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal { match name { "tt" => { p.quote_depth += 1; //but in theory, non-quoted tts might be useful - let mut tt = panictry!(p.parse_token_tree()); + let tt = panictry!(p.parse_token_tree()); p.quote_depth -= 1; - while let TokenTree::Token(sp, token::Interpolated(nt)) = tt { - if let token::NtTT(..) = *nt { - match Rc::try_unwrap(nt) { - Ok(token::NtTT(sub_tt)) => tt = sub_tt, - Ok(_) => unreachable!(), - Err(nt_rc) => match *nt_rc { - token::NtTT(ref sub_tt) => tt = sub_tt.clone(), - _ => unreachable!(), - }, - } - } else { - tt = TokenTree::Token(sp, token::Interpolated(nt.clone())); - break - } - } return token::NtTT(tt); } _ => {} diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index bf6851ec1dc..38becbe7b1d 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -12,7 +12,7 @@ use self::LockstepIterSize::*; use ast::Ident; use errors::Handler; use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; -use parse::token::{self, MatchNt, SubstNt, Token, NtIdent}; +use parse::token::{self, MatchNt, SubstNt, Token, NtIdent, NtTT}; use syntax_pos::{Span, DUMMY_SP}; use tokenstream::{self, TokenTree}; use util::small_vector::SmallVector; @@ -241,6 +241,7 @@ fn tt_next_token(r: &mut TtReader, prev_span: Span) -> Option<TokenTree> { NtIdent(ref sn) => { return Some(TokenTree::Token(sn.span, token::Ident(sn.node))); } + NtTT(ref tt) => return Some(tt.clone()), _ => { // FIXME(pcwalton): Bad copy return Some(TokenTree::Token(sp, token::Interpolated(nt.clone()))); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 608f8688e88..f958cedd286 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -306,8 +306,8 @@ impl<'a> Parser<'a> { } fn next_tok(&mut self) -> TokenAndSpan { - 'outer: loop { - let mut tok = if let Some((tts, i)) = self.tts.pop() { + loop { + let tok = if let Some((tts, i)) = self.tts.pop() { let tt = tts.get_tt(i); if i + 1 < tts.len() { self.tts.push((tts, i + 1)); @@ -322,25 +322,11 @@ impl<'a> Parser<'a> { TokenAndSpan { tok: token::Eof, sp: self.span } }; - loop { - let nt = match tok.tok { - token::Interpolated(ref nt) => nt.clone(), - token::DocComment(name) if self.desugar_doc_comments => { - self.tts.push((TokenTree::Token(tok.sp, token::DocComment(name)), 0)); - continue 'outer - } - _ => return tok, - }; - match *nt { - token::NtTT(TokenTree::Token(sp, ref t)) => { - tok = TokenAndSpan { tok: t.clone(), sp: sp }; - } - token::NtTT(ref tt) => { - self.tts.push((tt.clone(), 0)); - continue 'outer - } - _ => return tok, + match tok.tok { + token::DocComment(name) if self.desugar_doc_comments => { + self.tts.push((TokenTree::Token(tok.sp, token::DocComment(name)), 0)); } + _ => return tok, } } } |
