mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Implement concat_idents
This commit is contained in:
parent
9a431c26f4
commit
bbc151ef32
2 changed files with 36 additions and 0 deletions
|
@ -118,6 +118,7 @@ register_builtin! {
|
||||||
EAGER:
|
EAGER:
|
||||||
(compile_error, CompileError) => compile_error_expand,
|
(compile_error, CompileError) => compile_error_expand,
|
||||||
(concat, Concat) => concat_expand,
|
(concat, Concat) => concat_expand,
|
||||||
|
(concat_idents, ConcatIdents) => concat_idents_expand,
|
||||||
(include, Include) => include_expand,
|
(include, Include) => include_expand,
|
||||||
(include_bytes, IncludeBytes) => include_bytes_expand,
|
(include_bytes, IncludeBytes) => include_bytes_expand,
|
||||||
(include_str, IncludeStr) => include_str_expand,
|
(include_str, IncludeStr) => include_str_expand,
|
||||||
|
@ -373,6 +374,28 @@ fn concat_expand(
|
||||||
ExpandResult { value: Some(ExpandedEager::new(quote!(#text), FragmentKind::Expr)), err }
|
ExpandResult { value: Some(ExpandedEager::new(quote!(#text), FragmentKind::Expr)), err }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn concat_idents_expand(
|
||||||
|
_db: &dyn AstDatabase,
|
||||||
|
_arg_id: EagerMacroId,
|
||||||
|
tt: &tt::Subtree,
|
||||||
|
) -> ExpandResult<Option<ExpandedEager>> {
|
||||||
|
let mut err = None;
|
||||||
|
let mut ident = String::new();
|
||||||
|
for (i, t) in tt.token_trees.iter().enumerate() {
|
||||||
|
match t {
|
||||||
|
tt::TokenTree::Leaf(tt::Leaf::Ident(id)) => {
|
||||||
|
ident.push_str(id.text.as_str());
|
||||||
|
}
|
||||||
|
tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (),
|
||||||
|
_ => {
|
||||||
|
err.get_or_insert(mbe::ExpandError::UnexpectedToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let ident = tt::Ident { text: ident.into(), id: tt::TokenId::unspecified() };
|
||||||
|
ExpandResult { value: Some(ExpandedEager::new(quote!(#ident), FragmentKind::Expr)), err }
|
||||||
|
}
|
||||||
|
|
||||||
fn relative_file(
|
fn relative_file(
|
||||||
db: &dyn AstDatabase,
|
db: &dyn AstDatabase,
|
||||||
call_id: MacroCallId,
|
call_id: MacroCallId,
|
||||||
|
@ -794,4 +817,16 @@ mod tests {
|
||||||
expect![[r#""foor0bar\nfalse""#]],
|
expect![[r#""foor0bar\nfalse""#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_concat_idents_expand() {
|
||||||
|
check_expansion(
|
||||||
|
r##"
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
macro_rules! concat_idents {}
|
||||||
|
concat_idents!(foo, bar);
|
||||||
|
"##,
|
||||||
|
expect![[r#"foobar"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,6 +212,7 @@ pub mod known {
|
||||||
std_panic,
|
std_panic,
|
||||||
stringify,
|
stringify,
|
||||||
concat,
|
concat,
|
||||||
|
concat_idents,
|
||||||
include,
|
include,
|
||||||
include_bytes,
|
include_bytes,
|
||||||
include_str,
|
include_str,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue