diff options
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 2dd97b665..2dafd68f6 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -155,7 +155,14 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings, | |||
155 | _ => return Err(ExpandError::UnexpectedToken), | 155 | _ => return Err(ExpandError::UnexpectedToken), |
156 | }, | 156 | }, |
157 | crate::TokenTree::Repeat(crate::Repeat { subtree, kind: _, separator }) => { | 157 | crate::TokenTree::Repeat(crate::Repeat { subtree, kind: _, separator }) => { |
158 | // Dirty hack to make macro-expansion terminate. | ||
159 | // This should be replaced by a propper macro-by-example implementation | ||
160 | let mut limit = 128; | ||
158 | while let Ok(nested) = match_lhs(subtree, input) { | 161 | while let Ok(nested) = match_lhs(subtree, input) { |
162 | limit -= 1; | ||
163 | if limit == 0 { | ||
164 | break; | ||
165 | } | ||
159 | res.push_nested(nested)?; | 166 | res.push_nested(nested)?; |
160 | if let Some(separator) = *separator { | 167 | if let Some(separator) = *separator { |
161 | if !input.is_eof() { | 168 | if !input.is_eof() { |
@@ -196,7 +203,14 @@ fn expand_tt( | |||
196 | crate::TokenTree::Repeat(repeat) => { | 203 | crate::TokenTree::Repeat(repeat) => { |
197 | let mut token_trees = Vec::new(); | 204 | let mut token_trees = Vec::new(); |
198 | nesting.push(0); | 205 | nesting.push(0); |
206 | // Dirty hack to make macro-expansion terminate. | ||
207 | // This should be replaced by a propper macro-by-example implementation | ||
208 | let mut limit = 128; | ||
199 | while let Ok(t) = expand_subtree(&repeat.subtree, bindings, nesting) { | 209 | while let Ok(t) = expand_subtree(&repeat.subtree, bindings, nesting) { |
210 | limit -= 1; | ||
211 | if limit == 0 { | ||
212 | break; | ||
213 | } | ||
200 | let idx = nesting.pop().unwrap(); | 214 | let idx = nesting.pop().unwrap(); |
201 | nesting.push(idx + 1); | 215 | nesting.push(idx + 1); |
202 | token_trees.push(t.into()) | 216 | token_trees.push(t.into()) |