File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
hir_def/src/macro_expansion_tests Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -313,6 +313,40 @@ fn main() { "foor0bar\nfalse"; }
313
313
) ;
314
314
}
315
315
316
+ #[ test]
317
+ fn test_concat_with_captured_expr ( ) {
318
+ check (
319
+ r##"
320
+ #[rustc_builtin_macro]
321
+ macro_rules! concat {}
322
+
323
+ macro_rules! surprise {
324
+ () => { "s" };
325
+ }
326
+
327
+ macro_rules! stuff {
328
+ ($string:expr) => { concat!($string) };
329
+ }
330
+
331
+ fn main() { concat!(surprise!()); }
332
+ "## ,
333
+ expect ! [ [ r##"
334
+ #[rustc_builtin_macro]
335
+ macro_rules! concat {}
336
+
337
+ macro_rules! surprise {
338
+ () => { "s" };
339
+ }
340
+
341
+ macro_rules! stuff {
342
+ ($string:expr) => { concat!($string) };
343
+ }
344
+
345
+ fn main() { "s"; }
346
+ "## ] ] ,
347
+ ) ;
348
+ }
349
+
316
350
#[ test]
317
351
fn test_concat_idents_expand ( ) {
318
352
check (
Original file line number Diff line number Diff line change @@ -386,7 +386,18 @@ fn concat_expand(
386
386
) -> ExpandResult < Option < ExpandedEager > > {
387
387
let mut err = None ;
388
388
let mut text = String :: new ( ) ;
389
- for ( i, t) in tt. token_trees . iter ( ) . enumerate ( ) {
389
+ for ( i, mut t) in tt. token_trees . iter ( ) . enumerate ( ) {
390
+ // FIXME: hack on top of a hack: `$e:expr` captures get surrounded in parentheses
391
+ // to ensure the right parsing order, so skip the parentheses here. Ideally we'd
392
+ // implement rustc's model. cc https://github.com/rust-analyzer/rust-analyzer/pull/10623
393
+ if let tt:: TokenTree :: Subtree ( tt:: Subtree { delimiter : Some ( delim) , token_trees } ) = t {
394
+ if let [ tt] = & * * token_trees {
395
+ if delim. kind == tt:: DelimiterKind :: Parenthesis {
396
+ t = tt;
397
+ }
398
+ }
399
+ }
400
+
390
401
match t {
391
402
tt:: TokenTree :: Leaf ( tt:: Leaf :: Literal ( it) ) if i % 2 == 0 => {
392
403
// concat works with string and char literals, so remove any quotes.
You can’t perform that action at this time.
0 commit comments