diff options
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 27 |
1 files changed, 2 insertions, 25 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index db05c6253..78df96880 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -354,20 +354,6 @@ fn expand_subtree( | |||
354 | Ok(tt::Subtree { delimiter: template.delimiter, token_trees: buf }) | 354 | Ok(tt::Subtree { delimiter: template.delimiter, token_trees: buf }) |
355 | } | 355 | } |
356 | 356 | ||
357 | /// Reduce single token subtree to single token | ||
358 | /// In `tt` matcher case, all tt tokens will be braced by a Delimiter::None | ||
359 | /// which makes all sort of problems. | ||
360 | fn reduce_single_token(mut subtree: tt::Subtree) -> tt::TokenTree { | ||
361 | if subtree.delimiter != tt::Delimiter::None || subtree.token_trees.len() != 1 { | ||
362 | return subtree.into(); | ||
363 | } | ||
364 | |||
365 | match subtree.token_trees.pop().unwrap() { | ||
366 | tt::TokenTree::Subtree(subtree) => reduce_single_token(subtree), | ||
367 | tt::TokenTree::Leaf(token) => token.into(), | ||
368 | } | ||
369 | } | ||
370 | |||
371 | fn expand_tt(template: &crate::TokenTree, ctx: &mut ExpandCtx) -> Result<Fragment, ExpandError> { | 357 | fn expand_tt(template: &crate::TokenTree, ctx: &mut ExpandCtx) -> Result<Fragment, ExpandError> { |
372 | let res: tt::TokenTree = match template { | 358 | let res: tt::TokenTree = match template { |
373 | crate::TokenTree::Subtree(subtree) => expand_subtree(subtree, ctx)?.into(), | 359 | crate::TokenTree::Subtree(subtree) => expand_subtree(subtree, ctx)?.into(), |
@@ -454,7 +440,7 @@ fn expand_tt(template: &crate::TokenTree, ctx: &mut ExpandCtx) -> Result<Fragmen | |||
454 | 440 | ||
455 | // Check if it is a single token subtree without any delimiter | 441 | // Check if it is a single token subtree without any delimiter |
456 | // e.g {Delimiter:None> ['>'] /Delimiter:None>} | 442 | // e.g {Delimiter:None> ['>'] /Delimiter:None>} |
457 | reduce_single_token(tt::Subtree { delimiter: tt::Delimiter::None, token_trees: buf }) | 443 | tt::Subtree { delimiter: tt::Delimiter::None, token_trees: buf }.into() |
458 | } | 444 | } |
459 | crate::TokenTree::Leaf(leaf) => match leaf { | 445 | crate::TokenTree::Leaf(leaf) => match leaf { |
460 | crate::Leaf::Ident(ident) => { | 446 | crate::Leaf::Ident(ident) => { |
@@ -497,16 +483,7 @@ fn expand_tt(template: &crate::TokenTree, ctx: &mut ExpandCtx) -> Result<Fragmen | |||
497 | } else { | 483 | } else { |
498 | let fragment = ctx.bindings.get(&v.text, &ctx.nesting)?.clone(); | 484 | let fragment = ctx.bindings.get(&v.text, &ctx.nesting)?.clone(); |
499 | ctx.var_expanded = true; | 485 | ctx.var_expanded = true; |
500 | match fragment { | 486 | return Ok(fragment); |
501 | Fragment::Tokens(tt) => { | ||
502 | if let tt::TokenTree::Subtree(subtree) = tt { | ||
503 | reduce_single_token(subtree) | ||
504 | } else { | ||
505 | tt | ||
506 | } | ||
507 | } | ||
508 | Fragment::Ast(_) => return Ok(fragment), | ||
509 | } | ||
510 | } | 487 | } |
511 | } | 488 | } |
512 | crate::Leaf::Literal(l) => tt::Leaf::from(tt::Literal { text: l.text.clone() }).into(), | 489 | crate::Leaf::Literal(l) => tt::Leaf::from(tt::Literal { text: l.text.clone() }).into(), |