mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-16 15:14:02 +00:00
Merge #6929
6929: Handle $_ in mbe r=edwin0cheng a=lnicola Fixes #6926 Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
87886e8986
4 changed files with 18 additions and 3 deletions
|
@ -97,7 +97,7 @@ fn expand_subtree(
|
||||||
err = err.or(e);
|
err = err.or(e);
|
||||||
arena.push(tt.into());
|
arena.push(tt.into());
|
||||||
}
|
}
|
||||||
Op::Var { name, kind: _ } => {
|
Op::Var { name, .. } => {
|
||||||
let ExpandResult { value: fragment, err: e } = expand_var(ctx, name);
|
let ExpandResult { value: fragment, err: e } = expand_var(ctx, name);
|
||||||
err = err.or(e);
|
err = err.or(e);
|
||||||
push_fragment(arena, fragment);
|
push_fragment(arena, fragment);
|
||||||
|
|
|
@ -101,7 +101,9 @@ fn next_op<'a>(
|
||||||
Op::Repeat { subtree, separator, kind }
|
Op::Repeat { subtree, separator, kind }
|
||||||
}
|
}
|
||||||
tt::TokenTree::Leaf(leaf) => match leaf {
|
tt::TokenTree::Leaf(leaf) => match leaf {
|
||||||
tt::Leaf::Punct(..) => return Err(ExpandError::UnexpectedToken),
|
tt::Leaf::Punct(_) => {
|
||||||
|
return Err(ExpandError::UnexpectedToken);
|
||||||
|
}
|
||||||
tt::Leaf::Ident(ident) => {
|
tt::Leaf::Ident(ident) => {
|
||||||
let name = &ident.text;
|
let name = &ident.text;
|
||||||
let kind = eat_fragment_kind(src, mode)?;
|
let kind = eat_fragment_kind(src, mode)?;
|
||||||
|
|
|
@ -313,7 +313,7 @@ trait TokenConvertor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.push(if k.is_punct() {
|
result.push(if k.is_punct() && k != UNDERSCORE {
|
||||||
assert_eq!(range.len(), TextSize::of('.'));
|
assert_eq!(range.len(), TextSize::of('.'));
|
||||||
let delim = match k {
|
let delim = match k {
|
||||||
T!['('] => Some((tt::DelimiterKind::Parenthesis, T![')'])),
|
T!['('] => Some((tt::DelimiterKind::Parenthesis, T![')'])),
|
||||||
|
@ -378,6 +378,7 @@ trait TokenConvertor {
|
||||||
let leaf: tt::Leaf = match k {
|
let leaf: tt::Leaf = match k {
|
||||||
T![true] | T![false] => make_leaf!(Ident),
|
T![true] | T![false] => make_leaf!(Ident),
|
||||||
IDENT => make_leaf!(Ident),
|
IDENT => make_leaf!(Ident),
|
||||||
|
UNDERSCORE => make_leaf!(Ident),
|
||||||
k if k.is_keyword() => make_leaf!(Ident),
|
k if k.is_keyword() => make_leaf!(Ident),
|
||||||
k if k.is_literal() => make_leaf!(Literal),
|
k if k.is_literal() => make_leaf!(Literal),
|
||||||
LIFETIME_IDENT => {
|
LIFETIME_IDENT => {
|
||||||
|
|
|
@ -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]
|
#[test]
|
||||||
fn test_lifetime() {
|
fn test_lifetime() {
|
||||||
parse_macro(
|
parse_macro(
|
||||||
|
|
Loading…
Reference in a new issue