From b177813f3bef708636ec4be271e376b111c36a59 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 22 Apr 2019 15:33:55 +0800 Subject: Add mbe expand limit and poision macro set --- crates/ra_tt/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/ra_tt/src') diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 0b0b9b4d2..9cc646140 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs @@ -149,3 +149,15 @@ impl fmt::Display for Punct { fmt::Display::fmt(&self.char, f) } } + +impl Subtree { + /// Count the number of tokens recursively + pub fn count(&self) -> usize { + self.token_trees.iter().fold(self.token_trees.len(), |acc, c| { + acc + match c { + TokenTree::Subtree(c) => c.count(), + _ => 0, + } + }) + } +} -- cgit v1.2.3