Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/mbe/src/mbe_expander/transcriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn expand_subtree(
err = err.or(e);
arena.push(tt.into());
}
Op::Var { name, kind: _ } => {
Op::Var { name, .. } => {
let ExpandResult { value: fragment, err: e } = expand_var(ctx, name);
err = err.or(e);
push_fragment(arena, fragment);
Expand Down
4 changes: 3 additions & 1 deletion crates/mbe/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ fn next_op<'a>(
Op::Repeat { subtree, separator, kind }
}
tt::TokenTree::Leaf(leaf) => match leaf {
tt::Leaf::Punct(..) => return Err(ExpandError::UnexpectedToken),
tt::Leaf::Punct(_) => {
return Err(ExpandError::UnexpectedToken);
}
tt::Leaf::Ident(ident) => {
let name = &ident.text;
let kind = eat_fragment_kind(src, mode)?;
Expand Down
3 changes: 2 additions & 1 deletion crates/mbe/src/syntax_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ trait TokenConvertor {
return;
}

result.push(if k.is_punct() {
result.push(if k.is_punct() && k != UNDERSCORE {
assert_eq!(range.len(), TextSize::of('.'));
let delim = match k {
T!['('] => Some((tt::DelimiterKind::Parenthesis, T![')'])),
Expand Down Expand Up @@ -378,6 +378,7 @@ trait TokenConvertor {
let leaf: tt::Leaf = match k {
T![true] | T![false] => make_leaf!(Ident),
IDENT => make_leaf!(Ident),
UNDERSCORE => make_leaf!(Ident),
k if k.is_keyword() => make_leaf!(Ident),
k if k.is_literal() => make_leaf!(Literal),
LIFETIME_IDENT => {
Expand Down
12 changes: 12 additions & 0 deletions crates/mbe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,18 @@ fn test_tt_composite2() {
);
}

#[test]
fn test_underscore() {
parse_macro(
r#"
macro_rules! foo {
($_:tt) => { 0 }
}
"#,
)
.assert_expand_items(r#"foo! { => }"#, r#"0"#);
}

#[test]
fn test_lifetime() {
parse_macro(
Expand Down