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/lib.rs') 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 From ad1c3b5bd605942c85e4488b0483a0f50dc60942 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 22 Apr 2019 17:37:27 +0800 Subject: Use map, sum in Subtree::coount instead of fold --- crates/ra_tt/src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'crates/ra_tt/src/lib.rs') diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 9cc646140..62c5ac52a 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs @@ -153,11 +153,15 @@ impl fmt::Display for Punct { 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 { + let children_count = self + .token_trees + .iter() + .map(|c| match c { TokenTree::Subtree(c) => c.count(), _ => 0, - } - }) + }) + .sum::(); + + self.token_trees.len() + children_count } } -- cgit v1.2.3