From d4449945a069d26035afe9d8627414f6dfc8bf0a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 16 Mar 2019 15:45:21 +0300 Subject: hack around non-terminating macro expansion --- crates/ra_mbe/src/mbe_expander.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'crates') 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 return Err(ExpandError::UnexpectedToken), }, crate::TokenTree::Repeat(crate::Repeat { subtree, kind: _, separator }) => { + // Dirty hack to make macro-expansion terminate. + // This should be replaced by a propper macro-by-example implementation + let mut limit = 128; while let Ok(nested) = match_lhs(subtree, input) { + limit -= 1; + if limit == 0 { + break; + } res.push_nested(nested)?; if let Some(separator) = *separator { if !input.is_eof() { @@ -196,7 +203,14 @@ fn expand_tt( crate::TokenTree::Repeat(repeat) => { let mut token_trees = Vec::new(); nesting.push(0); + // Dirty hack to make macro-expansion terminate. + // This should be replaced by a propper macro-by-example implementation + let mut limit = 128; while let Ok(t) = expand_subtree(&repeat.subtree, bindings, nesting) { + limit -= 1; + if limit == 0 { + break; + } let idx = nesting.pop().unwrap(); nesting.push(idx + 1); token_trees.push(t.into()) -- cgit v1.2.3