aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tt/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-22 10:39:20 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-22 10:39:20 +0100
commit76e0129a21661029dc6cdbea2412ab53efe33aa1 (patch)
tree8da626b89a277722edd445798679339234596956 /crates/ra_tt/src/lib.rs
parentbbc5c1d24e1a641b134f634516828301e8cfc320 (diff)
parentad1c3b5bd605942c85e4488b0483a0f50dc60942 (diff)
Merge #1192
1192: Add mbe expand limit and poision macro set r=maklad a=edwin0cheng As discussed in Zulip, this PR add a token expansion limit in `parse_macro` and a "poison" macro set in `CrateDefMap` to prevent stack over flow and limit a mbe macro size. Note: Right now it only handle a poison macro in a single crate, such that if other crate try to call that macro, the whole process will do again until it became poisoned in that crate. Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_tt/src/lib.rs')
-rw-r--r--crates/ra_tt/src/lib.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs
index 0b0b9b4d2..62c5ac52a 100644
--- a/crates/ra_tt/src/lib.rs
+++ b/crates/ra_tt/src/lib.rs
@@ -149,3 +149,19 @@ impl fmt::Display for Punct {
149 fmt::Display::fmt(&self.char, f) 149 fmt::Display::fmt(&self.char, f)
150 } 150 }
151} 151}
152
153impl Subtree {
154 /// Count the number of tokens recursively
155 pub fn count(&self) -> usize {
156 let children_count = self
157 .token_trees
158 .iter()
159 .map(|c| match c {
160 TokenTree::Subtree(c) => c.count(),
161 _ => 0,
162 })
163 .sum::<usize>();
164
165 self.token_trees.len() + children_count
166 }
167}