mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Eliminate TokenTreeOrTokenTreeSlice
.
As its name suggests, `TokenTreeOrTokenTreeSlice` is either a single `TokenTree` or a slice of them. It has methods `len` and `get_tt` that let it be treated much like an ordinary slice. The reason it isn't an ordinary slice is that for `TokenTree::Delimited` the open and close delimiters are represented implicitly, and when they are needed they are constructed on the fly with `Delimited::{open,close}_tt`, rather than being present in memory. This commit changes `Delimited` so the open and close delimiters are represented explicitly. As a result, `TokenTreeOrTokenTreeSlice` is no longer needed and `MatcherPos` and `MatcherTtFrame` can just use an ordinary slice. `TokenTree::{len,get_tt}` are also removed, because they were only needed to support `TokenTreeOrTokenTreeSlice`. The change makes the code shorter and a little bit faster on benchmarks that use macro expansion heavily, partly because `MatcherPos` is a lot smaller (less data to `memcpy`) and partly because ordinary slice operations are faster than `TokenTreeOrTokenTreeSlice::{len,get_tt}`.
This commit is contained in:
parent
754dc8e66f
commit
31df680789
@ -17,23 +17,48 @@ use rustc_data_structures::sync::Lrc;
|
|||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
/// Contains the sub-token-trees of a "delimited" token tree, such as the contents of `(`. Note
|
/// Contains the sub-token-trees of a "delimited" token tree such as `(a b c)`. The delimiter itself
|
||||||
/// that the delimiter itself might be `NoDelim`.
|
/// might be `NoDelim`.
|
||||||
#[derive(Clone, PartialEq, Encodable, Decodable, Debug)]
|
#[derive(Clone, PartialEq, Encodable, Decodable, Debug)]
|
||||||
struct Delimited {
|
struct Delimited {
|
||||||
delim: token::DelimToken,
|
delim: token::DelimToken,
|
||||||
tts: Vec<TokenTree>,
|
/// Note: This contains the opening and closing delimiters tokens (e.g. `(` and `)`). Note that
|
||||||
|
/// these could be `NoDelim`. These token kinds must match `delim`, and the methods below
|
||||||
|
/// debug_assert this.
|
||||||
|
all_tts: Vec<TokenTree>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Delimited {
|
impl Delimited {
|
||||||
/// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
|
/// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter. Panics if
|
||||||
fn open_tt(&self, span: DelimSpan) -> TokenTree {
|
/// the delimiter is `NoDelim`.
|
||||||
TokenTree::token(token::OpenDelim(self.delim), span.open)
|
fn open_tt(&self) -> &TokenTree {
|
||||||
|
let tt = self.all_tts.first().unwrap();
|
||||||
|
debug_assert!(matches!(
|
||||||
|
tt,
|
||||||
|
&TokenTree::Token(token::Token { kind: token::OpenDelim(d), .. }) if d == self.delim
|
||||||
|
));
|
||||||
|
tt
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter.
|
/// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter. Panics if
|
||||||
fn close_tt(&self, span: DelimSpan) -> TokenTree {
|
/// the delimeter is `NoDelim`.
|
||||||
TokenTree::token(token::CloseDelim(self.delim), span.close)
|
fn close_tt(&self) -> &TokenTree {
|
||||||
|
let tt = self.all_tts.last().unwrap();
|
||||||
|
debug_assert!(matches!(
|
||||||
|
tt,
|
||||||
|
&TokenTree::Token(token::Token { kind: token::CloseDelim(d), .. }) if d == self.delim
|
||||||
|
));
|
||||||
|
tt
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the tts excluding the outer delimiters.
|
||||||
|
///
|
||||||
|
/// FIXME: #67062 has details about why this is sub-optimal.
|
||||||
|
fn inner_tts(&self) -> &[TokenTree] {
|
||||||
|
// These functions are called for the assertions within them.
|
||||||
|
let _open_tt = self.open_tt();
|
||||||
|
let _close_tt = self.close_tt();
|
||||||
|
&self.all_tts[1..self.all_tts.len() - 1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,35 +98,24 @@ enum KleeneOp {
|
|||||||
ZeroOrOne,
|
ZeroOrOne,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Similar to `tokenstream::TokenTree`, except that `$i`, `$i:ident`, `$(...)`,
|
/// Similar to `tokenstream::TokenTree`, except that `Sequence`, `MetaVar`, `MetaVarDecl`, and
|
||||||
/// and `${...}` are "first-class" token trees. Useful for parsing macros.
|
/// `MetaVarExpr` are "first-class" token trees. Useful for parsing macros.
|
||||||
#[derive(Debug, Clone, PartialEq, Encodable, Decodable)]
|
#[derive(Debug, Clone, PartialEq, Encodable, Decodable)]
|
||||||
enum TokenTree {
|
enum TokenTree {
|
||||||
Token(Token),
|
Token(Token),
|
||||||
|
/// A delimited sequence, e.g. `($e:expr)` (RHS) or `{ $e }` (LHS).
|
||||||
Delimited(DelimSpan, Lrc<Delimited>),
|
Delimited(DelimSpan, Lrc<Delimited>),
|
||||||
/// A kleene-style repetition sequence
|
/// A kleene-style repetition sequence, e.g. `$($e:expr)*` (RHS) or `$($e),*` (LHS).
|
||||||
Sequence(DelimSpan, Lrc<SequenceRepetition>),
|
Sequence(DelimSpan, Lrc<SequenceRepetition>),
|
||||||
/// e.g., `$var`
|
/// e.g., `$var`.
|
||||||
MetaVar(Span, Ident),
|
MetaVar(Span, Ident),
|
||||||
/// e.g., `$var:expr`. This is only used in the left hand side of MBE macros.
|
/// e.g., `$var:expr`. Only appears on the LHS.
|
||||||
MetaVarDecl(Span, Ident /* name to bind */, Option<NonterminalKind>),
|
MetaVarDecl(Span, Ident /* name to bind */, Option<NonterminalKind>),
|
||||||
/// A meta-variable expression inside `${...}`
|
/// A meta-variable expression inside `${...}`.
|
||||||
MetaVarExpr(DelimSpan, MetaVarExpr),
|
MetaVarExpr(DelimSpan, MetaVarExpr),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TokenTree {
|
impl TokenTree {
|
||||||
/// Return the number of tokens in the tree.
|
|
||||||
fn len(&self) -> usize {
|
|
||||||
match *self {
|
|
||||||
TokenTree::Delimited(_, ref delimed) => match delimed.delim {
|
|
||||||
token::NoDelim => delimed.tts.len(),
|
|
||||||
_ => delimed.tts.len() + 2,
|
|
||||||
},
|
|
||||||
TokenTree::Sequence(_, ref seq) => seq.tts.len(),
|
|
||||||
_ => 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if the given token tree is delimited.
|
/// Returns `true` if the given token tree is delimited.
|
||||||
fn is_delimited(&self) -> bool {
|
fn is_delimited(&self) -> bool {
|
||||||
matches!(*self, TokenTree::Delimited(..))
|
matches!(*self, TokenTree::Delimited(..))
|
||||||
@ -115,26 +129,6 @@ impl TokenTree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the `index`-th sub-token-tree. This only makes sense for delimited trees and sequences.
|
|
||||||
fn get_tt(&self, index: usize) -> TokenTree {
|
|
||||||
match (self, index) {
|
|
||||||
(&TokenTree::Delimited(_, ref delimed), _) if delimed.delim == token::NoDelim => {
|
|
||||||
delimed.tts[index].clone()
|
|
||||||
}
|
|
||||||
(&TokenTree::Delimited(span, ref delimed), _) => {
|
|
||||||
if index == 0 {
|
|
||||||
return delimed.open_tt(span);
|
|
||||||
}
|
|
||||||
if index == delimed.tts.len() + 1 {
|
|
||||||
return delimed.close_tt(span);
|
|
||||||
}
|
|
||||||
delimed.tts[index - 1].clone()
|
|
||||||
}
|
|
||||||
(&TokenTree::Sequence(_, ref seq), _) => seq.tts[index].clone(),
|
|
||||||
_ => panic!("Cannot expand a token tree"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves the `TokenTree`'s span.
|
/// Retrieves the `TokenTree`'s span.
|
||||||
fn span(&self) -> Span {
|
fn span(&self) -> Span {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -281,7 +281,7 @@ fn check_binders(
|
|||||||
// `MetaVarExpr` can not appear in the LHS of a macro arm
|
// `MetaVarExpr` can not appear in the LHS of a macro arm
|
||||||
TokenTree::MetaVarExpr(..) => {}
|
TokenTree::MetaVarExpr(..) => {}
|
||||||
TokenTree::Delimited(_, ref del) => {
|
TokenTree::Delimited(_, ref del) => {
|
||||||
for tt in &del.tts {
|
for tt in del.inner_tts() {
|
||||||
check_binders(sess, node_id, tt, macros, binders, ops, valid);
|
check_binders(sess, node_id, tt, macros, binders, ops, valid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -344,7 +344,7 @@ fn check_occurrences(
|
|||||||
check_ops_is_prefix(sess, node_id, macros, binders, ops, dl.entire(), name);
|
check_ops_is_prefix(sess, node_id, macros, binders, ops, dl.entire(), name);
|
||||||
}
|
}
|
||||||
TokenTree::Delimited(_, ref del) => {
|
TokenTree::Delimited(_, ref del) => {
|
||||||
check_nested_occurrences(sess, node_id, &del.tts, macros, binders, ops, valid);
|
check_nested_occurrences(sess, node_id, del.inner_tts(), macros, binders, ops, valid);
|
||||||
}
|
}
|
||||||
TokenTree::Sequence(_, ref seq) => {
|
TokenTree::Sequence(_, ref seq) => {
|
||||||
let ops = ops.push(seq.kleene);
|
let ops = ops.push(seq.kleene);
|
||||||
@ -431,14 +431,20 @@ fn check_nested_occurrences(
|
|||||||
{
|
{
|
||||||
let macro_rules = state == NestedMacroState::MacroRulesNotName;
|
let macro_rules = state == NestedMacroState::MacroRulesNotName;
|
||||||
state = NestedMacroState::Empty;
|
state = NestedMacroState::Empty;
|
||||||
let rest =
|
let rest = check_nested_macro(
|
||||||
check_nested_macro(sess, node_id, macro_rules, &del.tts, &nested_macros, valid);
|
sess,
|
||||||
|
node_id,
|
||||||
|
macro_rules,
|
||||||
|
del.inner_tts(),
|
||||||
|
&nested_macros,
|
||||||
|
valid,
|
||||||
|
);
|
||||||
// If we did not check the whole macro definition, then check the rest as if outside
|
// If we did not check the whole macro definition, then check the rest as if outside
|
||||||
// the macro definition.
|
// the macro definition.
|
||||||
check_nested_occurrences(
|
check_nested_occurrences(
|
||||||
sess,
|
sess,
|
||||||
node_id,
|
node_id,
|
||||||
&del.tts[rest..],
|
&del.inner_tts()[rest..],
|
||||||
macros,
|
macros,
|
||||||
binders,
|
binders,
|
||||||
ops,
|
ops,
|
||||||
|
@ -72,9 +72,8 @@
|
|||||||
|
|
||||||
crate use NamedMatch::*;
|
crate use NamedMatch::*;
|
||||||
crate use ParseResult::*;
|
crate use ParseResult::*;
|
||||||
use TokenTreeOrTokenTreeSlice::*;
|
|
||||||
|
|
||||||
use crate::mbe::{self, DelimSpan, SequenceRepetition, TokenTree};
|
use crate::mbe::{self, SequenceRepetition, TokenTree};
|
||||||
|
|
||||||
use rustc_ast::token::{self, DocComment, Nonterminal, Token};
|
use rustc_ast::token::{self, DocComment, Nonterminal, Token};
|
||||||
use rustc_parse::parser::Parser;
|
use rustc_parse::parser::Parser;
|
||||||
@ -90,35 +89,6 @@ use std::borrow::Cow;
|
|||||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
// To avoid costly uniqueness checks, we require that `MatchSeq` always has a nonempty body.
|
|
||||||
|
|
||||||
/// Either a slice of token trees or a single one. This is used as the representation of the
|
|
||||||
/// token trees that make up a matcher.
|
|
||||||
#[derive(Clone)]
|
|
||||||
enum TokenTreeOrTokenTreeSlice<'tt> {
|
|
||||||
Tt(TokenTree),
|
|
||||||
TtSlice(&'tt [TokenTree]),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tt> TokenTreeOrTokenTreeSlice<'tt> {
|
|
||||||
/// Returns the number of constituent top-level token trees of `self` (top-level in that it
|
|
||||||
/// will not recursively descend into subtrees).
|
|
||||||
fn len(&self) -> usize {
|
|
||||||
match *self {
|
|
||||||
TtSlice(ref v) => v.len(),
|
|
||||||
Tt(ref tt) => tt.len(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The `index`-th token tree of `self`.
|
|
||||||
fn get_tt(&self, index: usize) -> TokenTree {
|
|
||||||
match *self {
|
|
||||||
TtSlice(ref v) => v[index].clone(),
|
|
||||||
Tt(ref tt) => tt.get_tt(index),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An unzipping of `TokenTree`s... see the `stack` field of `MatcherPos`.
|
/// An unzipping of `TokenTree`s... see the `stack` field of `MatcherPos`.
|
||||||
///
|
///
|
||||||
/// This is used by `parse_tt_inner` to keep track of delimited submatchers that we have
|
/// This is used by `parse_tt_inner` to keep track of delimited submatchers that we have
|
||||||
@ -126,7 +96,7 @@ impl<'tt> TokenTreeOrTokenTreeSlice<'tt> {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct MatcherTtFrame<'tt> {
|
struct MatcherTtFrame<'tt> {
|
||||||
/// The "parent" matcher that we are descending into.
|
/// The "parent" matcher that we are descending into.
|
||||||
elts: TokenTreeOrTokenTreeSlice<'tt>,
|
elts: &'tt [TokenTree],
|
||||||
/// The position of the "dot" in `elts` at the time we descended.
|
/// The position of the "dot" in `elts` at the time we descended.
|
||||||
idx: usize,
|
idx: usize,
|
||||||
}
|
}
|
||||||
@ -138,7 +108,7 @@ type NamedMatchVec = SmallVec<[NamedMatch; 4]>;
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct MatcherPos<'tt> {
|
struct MatcherPos<'tt> {
|
||||||
/// The token or slice of tokens that make up the matcher. `elts` is short for "elements".
|
/// The token or slice of tokens that make up the matcher. `elts` is short for "elements".
|
||||||
top_elts: TokenTreeOrTokenTreeSlice<'tt>,
|
top_elts: &'tt [TokenTree],
|
||||||
|
|
||||||
/// The position of the "dot" in this matcher
|
/// The position of the "dot" in this matcher
|
||||||
idx: usize,
|
idx: usize,
|
||||||
@ -183,7 +153,7 @@ struct MatcherPos<'tt> {
|
|||||||
|
|
||||||
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
|
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||||
rustc_data_structures::static_assert_size!(MatcherPos<'_>, 232);
|
rustc_data_structures::static_assert_size!(MatcherPos<'_>, 136);
|
||||||
|
|
||||||
impl<'tt> MatcherPos<'tt> {
|
impl<'tt> MatcherPos<'tt> {
|
||||||
/// `len` `Vec`s (initially shared and empty) that will store matches of metavars.
|
/// `len` `Vec`s (initially shared and empty) that will store matches of metavars.
|
||||||
@ -203,7 +173,7 @@ impl<'tt> MatcherPos<'tt> {
|
|||||||
let match_idx_hi = count_names(ms);
|
let match_idx_hi = count_names(ms);
|
||||||
MatcherPos {
|
MatcherPos {
|
||||||
// Start with the top level matcher given to us.
|
// Start with the top level matcher given to us.
|
||||||
top_elts: TtSlice(ms),
|
top_elts: ms,
|
||||||
|
|
||||||
// The "dot" is before the first token of the matcher.
|
// The "dot" is before the first token of the matcher.
|
||||||
idx: 0,
|
idx: 0,
|
||||||
@ -224,9 +194,9 @@ impl<'tt> MatcherPos<'tt> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn repetition(up: Box<MatcherPos<'tt>>, sp: DelimSpan, seq: Lrc<SequenceRepetition>) -> Self {
|
fn repetition(up: Box<MatcherPos<'tt>>, seq: &'tt SequenceRepetition) -> Self {
|
||||||
MatcherPos {
|
MatcherPos {
|
||||||
stack: smallvec![],
|
top_elts: &seq.tts,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
matches: Self::create_matches(up.matches.len()),
|
matches: Self::create_matches(up.matches.len()),
|
||||||
match_lo: up.match_cur,
|
match_lo: up.match_cur,
|
||||||
@ -237,7 +207,7 @@ impl<'tt> MatcherPos<'tt> {
|
|||||||
sep: seq.separator.clone(),
|
sep: seq.separator.clone(),
|
||||||
seq_op: seq.kleene.op,
|
seq_op: seq.kleene.op,
|
||||||
}),
|
}),
|
||||||
top_elts: Tt(TokenTree::Sequence(sp, seq)),
|
stack: smallvec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,8 +258,8 @@ crate type NamedParseResult = ParseResult<FxHashMap<MacroRulesNormalizedIdent, N
|
|||||||
pub(super) fn count_names(ms: &[TokenTree]) -> usize {
|
pub(super) fn count_names(ms: &[TokenTree]) -> usize {
|
||||||
ms.iter().fold(0, |count, elt| {
|
ms.iter().fold(0, |count, elt| {
|
||||||
count
|
count
|
||||||
+ match *elt {
|
+ match elt {
|
||||||
TokenTree::Delimited(_, ref delim) => count_names(&delim.tts),
|
TokenTree::Delimited(_, delim) => count_names(delim.inner_tts()),
|
||||||
TokenTree::MetaVar(..) => 0,
|
TokenTree::MetaVar(..) => 0,
|
||||||
TokenTree::MetaVarDecl(..) => 1,
|
TokenTree::MetaVarDecl(..) => 1,
|
||||||
// Panicking here would abort execution because `parse_tree` makes use of this
|
// Panicking here would abort execution because `parse_tree` makes use of this
|
||||||
@ -298,7 +268,7 @@ pub(super) fn count_names(ms: &[TokenTree]) -> usize {
|
|||||||
// `0` is still returned to inform that no meta-variable was found. `Meta-variables
|
// `0` is still returned to inform that no meta-variable was found. `Meta-variables
|
||||||
// != Meta-variable expressions`
|
// != Meta-variable expressions`
|
||||||
TokenTree::MetaVarExpr(..) => 0,
|
TokenTree::MetaVarExpr(..) => 0,
|
||||||
TokenTree::Sequence(_, ref seq) => seq.num_captures,
|
TokenTree::Sequence(_, seq) => seq.num_captures,
|
||||||
TokenTree::Token(..) => 0,
|
TokenTree::Token(..) => 0,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -382,7 +352,7 @@ fn nameize<I: Iterator<Item = NamedMatch>>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
TokenTree::Delimited(_, ref delim) => {
|
TokenTree::Delimited(_, ref delim) => {
|
||||||
for next_m in &delim.tts {
|
for next_m in delim.inner_tts() {
|
||||||
n_rec(sess, next_m, res.by_ref(), ret_val)?;
|
n_rec(sess, next_m, res.by_ref(), ret_val)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,8 +416,8 @@ pub struct TtParser<'tt> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tt> TtParser<'tt> {
|
impl<'tt> TtParser<'tt> {
|
||||||
pub(super) fn new(macro_name: Ident) -> Self {
|
pub(super) fn new(macro_name: Ident) -> TtParser<'tt> {
|
||||||
Self { macro_name, cur_items: vec![], next_items: vec![], bb_items: vec![] }
|
TtParser { macro_name, cur_items: vec![], next_items: vec![], bb_items: vec![] }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process the matcher positions of `cur_items` until it is empty. In the process, this will
|
/// Process the matcher positions of `cur_items` until it is empty. In the process, this will
|
||||||
@ -492,8 +462,8 @@ impl<'tt> TtParser<'tt> {
|
|||||||
if idx < len {
|
if idx < len {
|
||||||
// We are in the middle of a matcher. Compare the matcher's current tt against
|
// We are in the middle of a matcher. Compare the matcher's current tt against
|
||||||
// `token`.
|
// `token`.
|
||||||
match item.top_elts.get_tt(idx) {
|
match &item.top_elts[idx] {
|
||||||
TokenTree::Sequence(sp, seq) => {
|
TokenTree::Sequence(_sp, seq) => {
|
||||||
let op = seq.kleene.op;
|
let op = seq.kleene.op;
|
||||||
if op == mbe::KleeneOp::ZeroOrMore || op == mbe::KleeneOp::ZeroOrOne {
|
if op == mbe::KleeneOp::ZeroOrMore || op == mbe::KleeneOp::ZeroOrOne {
|
||||||
// Allow for the possibility of zero matches of this sequence.
|
// Allow for the possibility of zero matches of this sequence.
|
||||||
@ -507,17 +477,17 @@ impl<'tt> TtParser<'tt> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allow for the possibility of one or more matches of this sequence.
|
// Allow for the possibility of one or more matches of this sequence.
|
||||||
self.cur_items.push(box MatcherPos::repetition(item, sp, seq));
|
self.cur_items.push(box MatcherPos::repetition(item, &seq));
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenTree::MetaVarDecl(span, _, None) => {
|
&TokenTree::MetaVarDecl(span, _, None) => {
|
||||||
// E.g. `$e` instead of `$e:expr`.
|
// E.g. `$e` instead of `$e:expr`.
|
||||||
if sess.missing_fragment_specifiers.borrow_mut().remove(&span).is_some() {
|
if sess.missing_fragment_specifiers.borrow_mut().remove(&span).is_some() {
|
||||||
return Some(Error(span, "missing fragment specifier".to_string()));
|
return Some(Error(span, "missing fragment specifier".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenTree::MetaVarDecl(_, _, Some(kind)) => {
|
&TokenTree::MetaVarDecl(_, _, Some(kind)) => {
|
||||||
// Built-in nonterminals never start with these tokens, so we can eliminate
|
// Built-in nonterminals never start with these tokens, so we can eliminate
|
||||||
// them from consideration.
|
// them from consideration.
|
||||||
//
|
//
|
||||||
@ -528,13 +498,14 @@ impl<'tt> TtParser<'tt> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
seq @ TokenTree::Delimited(..) => {
|
TokenTree::Delimited(_, delimited) => {
|
||||||
// To descend into a delimited submatcher, we push the current matcher onto
|
// To descend into a delimited submatcher, we push the current matcher onto
|
||||||
// a stack and push a new item containing the submatcher onto `cur_items`.
|
// a stack and push a new item containing the submatcher onto `cur_items`.
|
||||||
//
|
//
|
||||||
// At the beginning of the loop, if we reach the end of the delimited
|
// At the beginning of the loop, if we reach the end of the delimited
|
||||||
// submatcher, we pop the stack to backtrack out of the descent.
|
// submatcher, we pop the stack to backtrack out of the descent. Note that
|
||||||
let lower_elts = mem::replace(&mut item.top_elts, Tt(seq));
|
// we use `all_tts` to include the open and close delimiter tokens.
|
||||||
|
let lower_elts = mem::replace(&mut item.top_elts, &delimited.all_tts);
|
||||||
let idx = item.idx;
|
let idx = item.idx;
|
||||||
item.stack.push(MatcherTtFrame { elts: lower_elts, idx });
|
item.stack.push(MatcherTtFrame { elts: lower_elts, idx });
|
||||||
item.idx = 0;
|
item.idx = 0;
|
||||||
@ -560,7 +531,6 @@ impl<'tt> TtParser<'tt> {
|
|||||||
} else if let Some(repetition) = &item.repetition {
|
} else if let Some(repetition) = &item.repetition {
|
||||||
// We are past the end of a repetition.
|
// We are past the end of a repetition.
|
||||||
debug_assert!(idx <= len + 1);
|
debug_assert!(idx <= len + 1);
|
||||||
debug_assert!(matches!(item.top_elts, Tt(TokenTree::Sequence(..))));
|
|
||||||
|
|
||||||
if idx == len {
|
if idx == len {
|
||||||
// Add all matches from the sequence to `up`, and move the "dot" past the
|
// Add all matches from the sequence to `up`, and move the "dot" past the
|
||||||
@ -678,9 +648,7 @@ impl<'tt> TtParser<'tt> {
|
|||||||
(0, 1) => {
|
(0, 1) => {
|
||||||
// We need to call the black-box parser to get some nonterminal.
|
// We need to call the black-box parser to get some nonterminal.
|
||||||
let mut item = self.bb_items.pop().unwrap();
|
let mut item = self.bb_items.pop().unwrap();
|
||||||
if let TokenTree::MetaVarDecl(span, _, Some(kind)) =
|
if let TokenTree::MetaVarDecl(span, _, Some(kind)) = item.top_elts[item.idx] {
|
||||||
item.top_elts.get_tt(item.idx)
|
|
||||||
{
|
|
||||||
let match_cur = item.match_cur;
|
let match_cur = item.match_cur;
|
||||||
// We use the span of the metavariable declaration to determine any
|
// We use the span of the metavariable declaration to determine any
|
||||||
// edition-specific matching behavior for non-terminals.
|
// edition-specific matching behavior for non-terminals.
|
||||||
@ -720,7 +688,7 @@ impl<'tt> TtParser<'tt> {
|
|||||||
let nts = self
|
let nts = self
|
||||||
.bb_items
|
.bb_items
|
||||||
.iter()
|
.iter()
|
||||||
.map(|item| match item.top_elts.get_tt(item.idx) {
|
.map(|item| match item.top_elts[item.idx] {
|
||||||
TokenTree::MetaVarDecl(_, bind, Some(kind)) => {
|
TokenTree::MetaVarDecl(_, bind, Some(kind)) => {
|
||||||
format!("{} ('{}')", kind, bind)
|
format!("{} ('{}')", kind, bind)
|
||||||
}
|
}
|
||||||
|
@ -203,15 +203,15 @@ fn trace_macros_note(cx_expansions: &mut FxHashMap<Span, Vec<String>>, sp: Span,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Given `lhses` and `rhses`, this is the new macro we create
|
/// Given `lhses` and `rhses`, this is the new macro we create
|
||||||
fn generic_extension<'cx>(
|
fn generic_extension<'cx, 'tt>(
|
||||||
cx: &'cx mut ExtCtxt<'_>,
|
cx: &'cx mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
def_span: Span,
|
def_span: Span,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
transparency: Transparency,
|
transparency: Transparency,
|
||||||
arg: TokenStream,
|
arg: TokenStream,
|
||||||
lhses: &[mbe::TokenTree],
|
lhses: &'tt [mbe::TokenTree],
|
||||||
rhses: &[mbe::TokenTree],
|
rhses: &'tt [mbe::TokenTree],
|
||||||
is_local: bool,
|
is_local: bool,
|
||||||
) -> Box<dyn MacResult + 'cx> {
|
) -> Box<dyn MacResult + 'cx> {
|
||||||
let sess = &cx.sess.parse_sess;
|
let sess = &cx.sess.parse_sess;
|
||||||
@ -245,31 +245,30 @@ fn generic_extension<'cx>(
|
|||||||
// this situation.)
|
// this situation.)
|
||||||
let parser = parser_from_cx(sess, arg.clone());
|
let parser = parser_from_cx(sess, arg.clone());
|
||||||
|
|
||||||
|
// A matcher is always delimited, but the delimiters are ignored.
|
||||||
|
let delimited_inner_tts = |tt: &'tt mbe::TokenTree| -> &'tt [mbe::TokenTree] {
|
||||||
|
match tt {
|
||||||
|
mbe::TokenTree::Delimited(_, delimited) => delimited.inner_tts(),
|
||||||
|
_ => cx.span_bug(sp, "malformed macro lhs"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Try each arm's matchers.
|
||||||
let mut tt_parser = TtParser::new(name);
|
let mut tt_parser = TtParser::new(name);
|
||||||
for (i, lhs) in lhses.iter().enumerate() {
|
for (i, lhs) in lhses.iter().enumerate() {
|
||||||
// try each arm's matchers
|
|
||||||
let lhs_tt = match *lhs {
|
|
||||||
mbe::TokenTree::Delimited(_, ref delim) => &delim.tts,
|
|
||||||
_ => cx.span_bug(sp, "malformed macro lhs"),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Take a snapshot of the state of pre-expansion gating at this point.
|
// Take a snapshot of the state of pre-expansion gating at this point.
|
||||||
// This is used so that if a matcher is not `Success(..)`ful,
|
// This is used so that if a matcher is not `Success(..)`ful,
|
||||||
// then the spans which became gated when parsing the unsuccessful matcher
|
// then the spans which became gated when parsing the unsuccessful matcher
|
||||||
// are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
|
// are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
|
||||||
let mut gated_spans_snapshot = mem::take(&mut *sess.gated_spans.spans.borrow_mut());
|
let mut gated_spans_snapshot = mem::take(&mut *sess.gated_spans.spans.borrow_mut());
|
||||||
|
|
||||||
match tt_parser.parse_tt(&mut Cow::Borrowed(&parser), lhs_tt) {
|
match tt_parser.parse_tt(&mut Cow::Borrowed(&parser), delimited_inner_tts(lhs)) {
|
||||||
Success(named_matches) => {
|
Success(named_matches) => {
|
||||||
// The matcher was `Success(..)`ful.
|
// The matcher was `Success(..)`ful.
|
||||||
// Merge the gated spans from parsing the matcher with the pre-existing ones.
|
// Merge the gated spans from parsing the matcher with the pre-existing ones.
|
||||||
sess.gated_spans.merge(gated_spans_snapshot);
|
sess.gated_spans.merge(gated_spans_snapshot);
|
||||||
|
|
||||||
let rhs = match rhses[i] {
|
let rhs = delimited_inner_tts(&rhses[i]).to_vec().clone();
|
||||||
// ignore delimiters
|
|
||||||
mbe::TokenTree::Delimited(_, ref delimed) => delimed.tts.clone(),
|
|
||||||
_ => cx.span_bug(sp, "malformed macro rhs"),
|
|
||||||
};
|
|
||||||
let arm_span = rhses[i].span();
|
let arm_span = rhses[i].span();
|
||||||
|
|
||||||
let rhs_spans = rhs.iter().map(|t| t.span()).collect::<Vec<_>>();
|
let rhs_spans = rhs.iter().map(|t| t.span()).collect::<Vec<_>>();
|
||||||
@ -347,14 +346,10 @@ fn generic_extension<'cx>(
|
|||||||
// Check whether there's a missing comma in this macro call, like `println!("{}" a);`
|
// Check whether there's a missing comma in this macro call, like `println!("{}" a);`
|
||||||
if let Some((arg, comma_span)) = arg.add_comma() {
|
if let Some((arg, comma_span)) = arg.add_comma() {
|
||||||
for lhs in lhses {
|
for lhs in lhses {
|
||||||
// try each arm's matchers
|
if let Success(_) = tt_parser.parse_tt(
|
||||||
let lhs_tt = match *lhs {
|
&mut Cow::Borrowed(&parser_from_cx(sess, arg.clone())),
|
||||||
mbe::TokenTree::Delimited(_, ref delim) => &delim.tts,
|
delimited_inner_tts(lhs),
|
||||||
_ => continue,
|
) {
|
||||||
};
|
|
||||||
if let Success(_) =
|
|
||||||
tt_parser.parse_tt(&mut Cow::Borrowed(&parser_from_cx(sess, arg.clone())), lhs_tt)
|
|
||||||
{
|
|
||||||
if comma_span.is_dummy() {
|
if comma_span.is_dummy() {
|
||||||
err.note("you might be missing a comma");
|
err.note("you might be missing a comma");
|
||||||
} else {
|
} else {
|
||||||
@ -477,16 +472,17 @@ pub fn compile_declarative_macro(
|
|||||||
.map(|m| {
|
.map(|m| {
|
||||||
if let MatchedNonterminal(ref nt) = *m {
|
if let MatchedNonterminal(ref nt) = *m {
|
||||||
if let NtTT(ref tt) = **nt {
|
if let NtTT(ref tt) = **nt {
|
||||||
let tt = mbe::quoted::parse(
|
let mut tts = vec![];
|
||||||
|
mbe::quoted::parse(
|
||||||
tt.clone().into(),
|
tt.clone().into(),
|
||||||
true,
|
true,
|
||||||
&sess.parse_sess,
|
&sess.parse_sess,
|
||||||
def.id,
|
def.id,
|
||||||
features,
|
features,
|
||||||
edition,
|
edition,
|
||||||
)
|
&mut tts,
|
||||||
.pop()
|
);
|
||||||
.unwrap();
|
let tt = tts.pop().unwrap();
|
||||||
valid &= check_lhs_nt_follows(&sess.parse_sess, features, &def, &tt);
|
valid &= check_lhs_nt_follows(&sess.parse_sess, features, &def, &tt);
|
||||||
return tt;
|
return tt;
|
||||||
}
|
}
|
||||||
@ -503,16 +499,17 @@ pub fn compile_declarative_macro(
|
|||||||
.map(|m| {
|
.map(|m| {
|
||||||
if let MatchedNonterminal(ref nt) = *m {
|
if let MatchedNonterminal(ref nt) = *m {
|
||||||
if let NtTT(ref tt) = **nt {
|
if let NtTT(ref tt) = **nt {
|
||||||
return mbe::quoted::parse(
|
let mut tts = vec![];
|
||||||
|
mbe::quoted::parse(
|
||||||
tt.clone().into(),
|
tt.clone().into(),
|
||||||
false,
|
false,
|
||||||
&sess.parse_sess,
|
&sess.parse_sess,
|
||||||
def.id,
|
def.id,
|
||||||
features,
|
features,
|
||||||
edition,
|
edition,
|
||||||
)
|
&mut tts,
|
||||||
.pop()
|
);
|
||||||
.unwrap();
|
return tts.pop().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs")
|
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs")
|
||||||
@ -564,8 +561,8 @@ fn check_lhs_nt_follows(
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
// lhs is going to be like TokenTree::Delimited(...), where the
|
// lhs is going to be like TokenTree::Delimited(...), where the
|
||||||
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
|
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
|
||||||
if let mbe::TokenTree::Delimited(_, ref tts) = *lhs {
|
if let mbe::TokenTree::Delimited(_, delimited) = lhs {
|
||||||
check_matcher(sess, features, def, &tts.tts)
|
check_matcher(sess, features, def, delimited.inner_tts())
|
||||||
} else {
|
} else {
|
||||||
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
|
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
|
||||||
sess.span_diagnostic.span_err(lhs.span(), msg);
|
sess.span_diagnostic.span_err(lhs.span(), msg);
|
||||||
@ -586,7 +583,7 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[mbe::TokenTree]) -> bool {
|
|||||||
| TokenTree::MetaVarDecl(..)
|
| TokenTree::MetaVarDecl(..)
|
||||||
| TokenTree::MetaVarExpr(..) => (),
|
| TokenTree::MetaVarExpr(..) => (),
|
||||||
TokenTree::Delimited(_, ref del) => {
|
TokenTree::Delimited(_, ref del) => {
|
||||||
if !check_lhs_no_empty_seq(sess, &del.tts) {
|
if !check_lhs_no_empty_seq(sess, del.inner_tts()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -681,9 +678,9 @@ impl FirstSets {
|
|||||||
| TokenTree::MetaVarExpr(..) => {
|
| TokenTree::MetaVarExpr(..) => {
|
||||||
first.replace_with(tt.clone());
|
first.replace_with(tt.clone());
|
||||||
}
|
}
|
||||||
TokenTree::Delimited(span, ref delimited) => {
|
TokenTree::Delimited(_span, ref delimited) => {
|
||||||
build_recur(sets, &delimited.tts);
|
build_recur(sets, delimited.inner_tts());
|
||||||
first.replace_with(delimited.open_tt(span));
|
first.replace_with(delimited.open_tt().clone());
|
||||||
}
|
}
|
||||||
TokenTree::Sequence(sp, ref seq_rep) => {
|
TokenTree::Sequence(sp, ref seq_rep) => {
|
||||||
let subfirst = build_recur(sets, &seq_rep.tts);
|
let subfirst = build_recur(sets, &seq_rep.tts);
|
||||||
@ -747,8 +744,8 @@ impl FirstSets {
|
|||||||
first.add_one(tt.clone());
|
first.add_one(tt.clone());
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
TokenTree::Delimited(span, ref delimited) => {
|
TokenTree::Delimited(_span, ref delimited) => {
|
||||||
first.add_one(delimited.open_tt(span));
|
first.add_one(delimited.open_tt().clone());
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
TokenTree::Sequence(sp, ref seq_rep) => {
|
TokenTree::Sequence(sp, ref seq_rep) => {
|
||||||
@ -934,9 +931,9 @@ fn check_matcher_core(
|
|||||||
suffix_first = build_suffix_first();
|
suffix_first = build_suffix_first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TokenTree::Delimited(span, ref d) => {
|
TokenTree::Delimited(_span, ref d) => {
|
||||||
let my_suffix = TokenSet::singleton(d.close_tt(span));
|
let my_suffix = TokenSet::singleton(d.close_tt().clone());
|
||||||
check_matcher_core(sess, features, def, first_sets, &d.tts, &my_suffix);
|
check_matcher_core(sess, features, def, first_sets, d.inner_tts(), &my_suffix);
|
||||||
// don't track non NT tokens
|
// don't track non NT tokens
|
||||||
last.replace_with_irrelevant();
|
last.replace_with_irrelevant();
|
||||||
|
|
||||||
|
@ -45,10 +45,8 @@ pub(super) fn parse(
|
|||||||
node_id: NodeId,
|
node_id: NodeId,
|
||||||
features: &Features,
|
features: &Features,
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
) -> Vec<TokenTree> {
|
result: &mut Vec<TokenTree>,
|
||||||
// Will contain the final collection of `self::TokenTree`
|
) {
|
||||||
let mut result = Vec::new();
|
|
||||||
|
|
||||||
// For each token tree in `input`, parse the token into a `self::TokenTree`, consuming
|
// For each token tree in `input`, parse the token into a `self::TokenTree`, consuming
|
||||||
// additional trees if need be.
|
// additional trees if need be.
|
||||||
let mut trees = input.trees();
|
let mut trees = input.trees();
|
||||||
@ -115,7 +113,6 @@ pub(super) fn parse(
|
|||||||
_ => result.push(tree),
|
_ => result.push(tree),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asks for the `macro_metavar_expr` feature if it is not already declared
|
/// Asks for the `macro_metavar_expr` feature if it is not already declared
|
||||||
@ -208,7 +205,8 @@ fn parse_tree(
|
|||||||
// If we didn't find a metavar expression above, then we must have a
|
// If we didn't find a metavar expression above, then we must have a
|
||||||
// repetition sequence in the macro (e.g. `$(pat)*`). Parse the
|
// repetition sequence in the macro (e.g. `$(pat)*`). Parse the
|
||||||
// contents of the sequence itself
|
// contents of the sequence itself
|
||||||
let sequence = parse(tts, parsing_patterns, sess, node_id, features, edition);
|
let mut sequence = vec![];
|
||||||
|
parse(tts, parsing_patterns, sess, node_id, features, edition, &mut sequence);
|
||||||
// Get the Kleene operator and optional separator
|
// Get the Kleene operator and optional separator
|
||||||
let (separator, kleene) =
|
let (separator, kleene) =
|
||||||
parse_sep_and_kleene_op(&mut trees, delim_span.entire(), sess);
|
parse_sep_and_kleene_op(&mut trees, delim_span.entire(), sess);
|
||||||
@ -225,8 +223,8 @@ fn parse_tree(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate` special
|
// `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate`
|
||||||
// metavariable that names the crate of the invocation.
|
// special metavariable that names the crate of the invocation.
|
||||||
Some(tokenstream::TokenTree::Token(token)) if token.is_ident() => {
|
Some(tokenstream::TokenTree::Token(token)) if token.is_ident() => {
|
||||||
let (ident, is_raw) = token.ident().unwrap();
|
let (ident, is_raw) = token.ident().unwrap();
|
||||||
let span = ident.span.with_lo(span.lo());
|
let span = ident.span.with_lo(span.lo());
|
||||||
@ -270,13 +268,15 @@ fn parse_tree(
|
|||||||
|
|
||||||
// `tree` is the beginning of a delimited set of tokens (e.g., `(` or `{`). We need to
|
// `tree` is the beginning of a delimited set of tokens (e.g., `(` or `{`). We need to
|
||||||
// descend into the delimited set and further parse it.
|
// descend into the delimited set and further parse it.
|
||||||
tokenstream::TokenTree::Delimited(span, delim, tts) => TokenTree::Delimited(
|
tokenstream::TokenTree::Delimited(span, delim, tts) => {
|
||||||
span,
|
let mut all_tts = vec![];
|
||||||
Lrc::new(Delimited {
|
// Add the explicit open and close delimiters, which
|
||||||
delim,
|
// `tokenstream::TokenTree::Delimited` lacks.
|
||||||
tts: parse(tts, parsing_patterns, sess, node_id, features, edition),
|
all_tts.push(TokenTree::token(token::OpenDelim(delim), span.open));
|
||||||
}),
|
parse(tts, parsing_patterns, sess, node_id, features, edition, &mut all_tts);
|
||||||
),
|
all_tts.push(TokenTree::token(token::CloseDelim(delim), span.close));
|
||||||
|
TokenTree::Delimited(span, Lrc::new(Delimited { delim, all_tts }))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ use rustc_errors::{pluralize, PResult};
|
|||||||
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
||||||
use rustc_span::hygiene::{LocalExpnId, Transparency};
|
use rustc_span::hygiene::{LocalExpnId, Transparency};
|
||||||
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
|
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
|
||||||
use rustc_span::Span;
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
@ -34,8 +34,14 @@ enum Frame {
|
|||||||
|
|
||||||
impl Frame {
|
impl Frame {
|
||||||
/// Construct a new frame around the delimited set of tokens.
|
/// Construct a new frame around the delimited set of tokens.
|
||||||
fn new(tts: Vec<mbe::TokenTree>) -> Frame {
|
fn new(mut tts: Vec<mbe::TokenTree>) -> Frame {
|
||||||
let forest = Lrc::new(mbe::Delimited { delim: token::NoDelim, tts });
|
// Need to add empty delimeters.
|
||||||
|
let open_tt = mbe::TokenTree::token(token::OpenDelim(token::NoDelim), DUMMY_SP);
|
||||||
|
let close_tt = mbe::TokenTree::token(token::CloseDelim(token::NoDelim), DUMMY_SP);
|
||||||
|
tts.insert(0, open_tt);
|
||||||
|
tts.push(close_tt);
|
||||||
|
|
||||||
|
let forest = Lrc::new(mbe::Delimited { delim: token::NoDelim, all_tts: tts });
|
||||||
Frame::Delimited { forest, idx: 0, span: DelimSpan::dummy() }
|
Frame::Delimited { forest, idx: 0, span: DelimSpan::dummy() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,12 +52,14 @@ impl Iterator for Frame {
|
|||||||
fn next(&mut self) -> Option<mbe::TokenTree> {
|
fn next(&mut self) -> Option<mbe::TokenTree> {
|
||||||
match *self {
|
match *self {
|
||||||
Frame::Delimited { ref forest, ref mut idx, .. } => {
|
Frame::Delimited { ref forest, ref mut idx, .. } => {
|
||||||
|
let res = forest.inner_tts().get(*idx).cloned();
|
||||||
*idx += 1;
|
*idx += 1;
|
||||||
forest.tts.get(*idx - 1).cloned()
|
res
|
||||||
}
|
}
|
||||||
Frame::Sequence { ref forest, ref mut idx, .. } => {
|
Frame::Sequence { ref forest, ref mut idx, .. } => {
|
||||||
|
let res = forest.tts.get(*idx).cloned();
|
||||||
*idx += 1;
|
*idx += 1;
|
||||||
forest.tts.get(*idx - 1).cloned()
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -376,8 +384,8 @@ fn lockstep_iter_size(
|
|||||||
) -> LockstepIterSize {
|
) -> LockstepIterSize {
|
||||||
use mbe::TokenTree;
|
use mbe::TokenTree;
|
||||||
match *tree {
|
match *tree {
|
||||||
TokenTree::Delimited(_, ref delimed) => {
|
TokenTree::Delimited(_, ref delimited) => {
|
||||||
delimed.tts.iter().fold(LockstepIterSize::Unconstrained, |size, tt| {
|
delimited.inner_tts().iter().fold(LockstepIterSize::Unconstrained, |size, tt| {
|
||||||
size.with(lockstep_iter_size(tt, interpolations, repeats))
|
size.with(lockstep_iter_size(tt, interpolations, repeats))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user