@@ -456,7 +456,10 @@ fn concat_expand(
456
456
Some ( _) => ( ) ,
457
457
None => span = Some ( s) ,
458
458
} ;
459
- for ( i, mut t) in tt. iter ( ) . enumerate ( ) {
459
+
460
+ let mut i = 0 ;
461
+ let mut iter = tt. iter ( ) ;
462
+ while let Some ( mut t) = iter. next ( ) {
460
463
// FIXME: hack on top of a hack: `$e:expr` captures get surrounded in parentheses
461
464
// to ensure the right parsing order, so skip the parentheses here. Ideally we'd
462
465
// implement rustc's model. cc https://github.com/rust-lang/rust-analyzer/pull/10623
@@ -508,10 +511,40 @@ fn concat_expand(
508
511
record_span ( id. span ) ;
509
512
}
510
513
TtElement :: Leaf ( tt:: Leaf :: Punct ( punct) ) if i % 2 == 1 && punct. char == ',' => ( ) ,
514
+ // handle negative numbers
515
+ TtElement :: Leaf ( tt:: Leaf :: Punct ( punct) ) if i % 2 == 0 && punct. char == '-' => {
516
+ let t = match iter. next ( ) {
517
+ Some ( t) => t,
518
+ None => {
519
+ err. get_or_insert ( ExpandError :: other (
520
+ call_site,
521
+ "unexpected end of input after '-'" ,
522
+ ) ) ;
523
+ break ;
524
+ }
525
+ } ;
526
+
527
+ match t {
528
+ TtElement :: Leaf ( tt:: Leaf :: Literal ( it) )
529
+ if matches ! ( it. kind, tt:: LitKind :: Integer | tt:: LitKind :: Float ) =>
530
+ {
531
+ format_to ! ( text, "-{}" , it. symbol. as_str( ) ) ;
532
+ record_span ( punct. span . cover ( it. span ) ) ;
533
+ }
534
+ _ => {
535
+ err. get_or_insert ( ExpandError :: other (
536
+ call_site,
537
+ "expected number after '-'" ,
538
+ ) ) ;
539
+ break ;
540
+ }
541
+ }
542
+ }
511
543
_ => {
512
544
err. get_or_insert ( ExpandError :: other ( call_site, "unexpected token" ) ) ;
513
545
}
514
546
}
547
+ i += 1 ;
515
548
}
516
549
let span = span. unwrap_or_else ( || tt. top_subtree ( ) . delimiter . open ) ;
517
550
ExpandResult { value : quote ! ( span =>#text) , err }
0 commit comments