@@ -118,6 +118,7 @@ register_builtin! {
118
118
EAGER :
119
119
( compile_error, CompileError ) => compile_error_expand,
120
120
( concat, Concat ) => concat_expand,
121
+ ( concat_idents, ConcatIdents ) => concat_idents_expand,
121
122
( include, Include ) => include_expand,
122
123
( include_bytes, IncludeBytes ) => include_bytes_expand,
123
124
( include_str, IncludeStr ) => include_str_expand,
@@ -373,6 +374,28 @@ fn concat_expand(
373
374
ExpandResult { value : Some ( ExpandedEager :: new ( quote ! ( #text) , FragmentKind :: Expr ) ) , err }
374
375
}
375
376
377
+ fn concat_idents_expand (
378
+ _db : & dyn AstDatabase ,
379
+ _arg_id : EagerMacroId ,
380
+ tt : & tt:: Subtree ,
381
+ ) -> ExpandResult < Option < ExpandedEager > > {
382
+ let mut err = None ;
383
+ let mut ident = String :: new ( ) ;
384
+ for ( i, t) in tt. token_trees . iter ( ) . enumerate ( ) {
385
+ match t {
386
+ tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( id) ) => {
387
+ ident. push_str ( id. text . as_str ( ) ) ;
388
+ }
389
+ tt:: TokenTree :: Leaf ( tt:: Leaf :: Punct ( punct) ) if i % 2 == 1 && punct. char == ',' => ( ) ,
390
+ _ => {
391
+ err. get_or_insert ( mbe:: ExpandError :: UnexpectedToken ) ;
392
+ }
393
+ }
394
+ }
395
+ let ident = tt:: Ident { text : ident. into ( ) , id : tt:: TokenId :: unspecified ( ) } ;
396
+ ExpandResult { value : Some ( ExpandedEager :: new ( quote ! ( #ident) , FragmentKind :: Expr ) ) , err }
397
+ }
398
+
376
399
fn relative_file (
377
400
db : & dyn AstDatabase ,
378
401
call_id : MacroCallId ,
@@ -794,4 +817,16 @@ mod tests {
794
817
expect ! [ [ r#""foor0bar\nfalse""# ] ] ,
795
818
) ;
796
819
}
820
+
821
+ #[ test]
822
+ fn test_concat_idents_expand ( ) {
823
+ check_expansion (
824
+ r##"
825
+ #[rustc_builtin_macro]
826
+ macro_rules! concat_idents {}
827
+ concat_idents!(foo, bar);
828
+ "## ,
829
+ expect ! [ [ r#"foobar"# ] ] ,
830
+ ) ;
831
+ }
797
832
}
0 commit comments