hack around non-terminating macro expansion
This commit is contained in:
parent
b2a6c17362
commit
d4449945a0
1 changed files with 14 additions and 0 deletions
|
@ -155,7 +155,14 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
|
||||||
_ => return Err(ExpandError::UnexpectedToken),
|
_ => return Err(ExpandError::UnexpectedToken),
|
||||||
},
|
},
|
||||||
crate::TokenTree::Repeat(crate::Repeat { subtree, kind: _, separator }) => {
|
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) {
|
while let Ok(nested) = match_lhs(subtree, input) {
|
||||||
|
limit -= 1;
|
||||||
|
if limit == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
res.push_nested(nested)?;
|
res.push_nested(nested)?;
|
||||||
if let Some(separator) = *separator {
|
if let Some(separator) = *separator {
|
||||||
if !input.is_eof() {
|
if !input.is_eof() {
|
||||||
|
@ -196,7 +203,14 @@ fn expand_tt(
|
||||||
crate::TokenTree::Repeat(repeat) => {
|
crate::TokenTree::Repeat(repeat) => {
|
||||||
let mut token_trees = Vec::new();
|
let mut token_trees = Vec::new();
|
||||||
nesting.push(0);
|
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) {
|
while let Ok(t) = expand_subtree(&repeat.subtree, bindings, nesting) {
|
||||||
|
limit -= 1;
|
||||||
|
if limit == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let idx = nesting.pop().unwrap();
|
let idx = nesting.pop().unwrap();
|
||||||
nesting.push(idx + 1);
|
nesting.push(idx + 1);
|
||||||
token_trees.push(t.into())
|
token_trees.push(t.into())
|
||||||
|
|
Loading…
Add table
Reference in a new issue