@@ -136,16 +136,27 @@ impl Lit {
136
136
}
137
137
}
138
138
139
- /// Keep this in sync with `Token::can_begin_literal_maybe_minus` excluding unary negation.
139
+ /// Keep this in sync with `Token::can_begin_literal_maybe_minus` and
140
+ /// `Parser::maybe_parse_token_lit` (excluding unary negation).
140
141
pub fn from_token ( token : & Token ) -> Option < Lit > {
141
142
match token. uninterpolate ( ) . kind {
142
143
Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
143
144
Literal ( token_lit) => Some ( token_lit) ,
144
- Interpolated ( ref nt)
145
- if let NtExpr ( expr) | NtLiteral ( expr) = & * * nt
146
- && let ast:: ExprKind :: Lit ( token_lit) = expr. kind =>
147
- {
148
- Some ( token_lit)
145
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( NonterminalKind :: Literal ) ) ) => {
146
+ panic ! ( "njn: FROM_TOKEN (1)" ) ;
147
+ // if let NtExpr(expr) | NtLiteral(expr) = &**nt
148
+ // && let ast::ExprKind::Lit(token_lit) = expr.kind =>
149
+ // {
150
+ // Some(token_lit)
151
+ // }
152
+ }
153
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( NonterminalKind :: Expr ( _) ) ) ) => {
154
+ panic ! ( "njn: FROM_TOKEN (2)" ) ;
155
+ // if let NtExpr(expr) | NtLiteral(expr) = &**nt
156
+ // && let ast::ExprKind::Lit(token_lit) = expr.kind =>
157
+ // {
158
+ // Some(token_lit)
159
+ // }
149
160
}
150
161
_ => None ,
151
162
}
@@ -478,6 +489,7 @@ impl Token {
478
489
Token :: new ( Ident ( ident. name , ident. is_raw_guess ( ) . into ( ) ) , ident. span )
479
490
}
480
491
492
+ /// njn: phase this out in favour of Parser::uninterpolated_token_span?
481
493
/// For interpolated tokens, returns a span of the fragment to which the interpolated
482
494
/// token refers. For all other tokens this is just a regular span.
483
495
/// It is particularly important to use this for identifiers and lifetimes
@@ -533,9 +545,7 @@ impl Token {
533
545
PathSep | // global path
534
546
Lifetime ( ..) | // labeled loop
535
547
Pound => true , // expression attributes
536
- Interpolated ( ref nt) => matches ! ( & * * nt, NtLiteral ( ..) |
537
- NtExpr ( ..) |
538
- NtBlock ( ..) ) ,
548
+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
539
549
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
540
550
NonterminalKind :: Block |
541
551
NonterminalKind :: Expr ( _) |
@@ -562,7 +572,7 @@ impl Token {
562
572
| DotDot | DotDotDot | DotDotEq // ranges
563
573
| Lt | BinOp ( Shl ) // associated path
564
574
| PathSep => true , // global path
565
- Interpolated ( ref nt) => matches ! ( & * * nt, NtLiteral ( .. ) | NtBlock ( ..) ) ,
575
+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
566
576
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
567
577
NonterminalKind :: Block |
568
578
NonterminalKind :: Pat ( _) |
@@ -603,7 +613,7 @@ impl Token {
603
613
match self . kind {
604
614
OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
605
615
Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
606
- Interpolated ( ref nt) => matches ! ( & * * nt, NtExpr ( .. ) | NtBlock ( .. ) | NtLiteral ( ..) ) ,
616
+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
607
617
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
608
618
NonterminalKind :: Expr ( _) | NonterminalKind :: Block | NonterminalKind :: Literal ,
609
619
) ) ) => true ,
@@ -647,22 +657,24 @@ impl Token {
647
657
///
648
658
/// In other words, would this token be a valid start of `parse_literal_maybe_minus`?
649
659
///
650
- /// Keep this in sync with and `Lit::from_token`, excluding unary negation.
660
+ /// Keep this in sync with `Lit::from_token` and
661
+ /// `Parser::maybe_parse_token_lit` (excluding unary negation).
651
662
pub fn can_begin_literal_maybe_minus ( & self ) -> bool {
652
663
match self . uninterpolate ( ) . kind {
653
664
Literal ( ..) | BinOp ( Minus ) => true ,
654
665
Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
655
- Interpolated ( ref nt) => match & * * nt {
656
- NtLiteral ( _) => true ,
657
- NtExpr ( e) => match & e. kind {
658
- ast:: ExprKind :: Lit ( _) => true ,
659
- ast:: ExprKind :: Unary ( ast:: UnOp :: Neg , e) => {
660
- matches ! ( & e. kind, ast:: ExprKind :: Lit ( _) )
661
- }
662
- _ => false ,
663
- } ,
664
- _ => false ,
665
- } ,
666
+ // njn: fix up
667
+ // Interpolated(ref nt) => match &**nt {
668
+ // NtLiteral(_) => true,
669
+ // NtExpr(e) => match &e.kind {
670
+ // ast::ExprKind::Lit(_) => true,
671
+ // ast::ExprKind::Unary(ast::UnOp::Neg, e) => {
672
+ // matches!(&e.kind, ast::ExprKind::Lit(_))
673
+ // }
674
+ // _ => false,
675
+ // },
676
+ // _ => false,
677
+ // },
666
678
// njn: too simple compared to what's above?
667
679
OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
668
680
NonterminalKind :: Literal | NonterminalKind :: Expr ( _) ,
@@ -674,14 +686,19 @@ impl Token {
674
686
pub fn can_begin_string_literal ( & self ) -> bool {
675
687
match self . uninterpolate ( ) . kind {
676
688
Literal ( ..) => true ,
677
- Interpolated ( ref nt) => match & * * nt {
678
- NtLiteral ( _) => true ,
679
- NtExpr ( e) => match & e. kind {
680
- ast:: ExprKind :: Lit ( _) => true ,
681
- _ => false ,
682
- } ,
683
- _ => false ,
684
- } ,
689
+ // njn: fix up
690
+ // Interpolated(ref nt) => match &**nt {
691
+ // NtLiteral(_) => true,
692
+ // NtExpr(e) => match &e.kind {
693
+ // ast::ExprKind::Lit(_) => true,
694
+ // _ => false,
695
+ // },
696
+ // _ => false,
697
+ // },
698
+ // njn: too simple compared to what's above?
699
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
700
+ NonterminalKind :: Literal | NonterminalKind :: Expr ( _) ,
701
+ ) ) ) => true ,
685
702
_ => false ,
686
703
}
687
704
}
@@ -736,16 +753,19 @@ impl Token {
736
753
self . ident ( ) . is_some_and ( |( ident, _) | ident. name == name)
737
754
}
738
755
739
- /// Would `maybe_whole_expr ` in `parser.rs` return `Ok(..)`?
756
+ /// Would `maybe_reparse_metavar_expr ` in `parser.rs` return `Ok(..)`?
740
757
/// That is, is this a pre-parsed expression dropped into the token stream
741
758
/// (which happens while parsing the result of macro expansion)?
742
- pub fn is_whole_expr ( & self ) -> bool {
743
- #[ allow( irrefutable_let_patterns) ] // njn: temp
759
+ pub fn is_metavar_expr ( & self ) -> bool {
760
+ #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
744
761
if let Interpolated ( nt) = & self . kind
745
- && let NtExpr ( _ ) | NtLiteral ( _) = & * * nt
762
+ && let NtBlock ( _) = & * * nt
746
763
{
747
764
true
748
- } else if matches ! ( self . is_metavar_seq( ) , Some ( NonterminalKind :: Path ) ) {
765
+ } else if matches ! (
766
+ self . is_metavar_seq( ) ,
767
+ Some ( NonterminalKind :: Expr ( _) | NonterminalKind :: Literal | NonterminalKind :: Path )
768
+ ) {
749
769
true
750
770
} else {
751
771
false
@@ -754,6 +774,7 @@ impl Token {
754
774
755
775
/// Is the token an interpolated block (`$b:block`)?
756
776
pub fn is_whole_block ( & self ) -> bool {
777
+ #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
757
778
if let Interpolated ( nt) = & self . kind
758
779
&& let NtBlock ( ..) = & * * nt
759
780
{
@@ -947,8 +968,6 @@ pub enum NtExprKind {
947
968
/// For interpolation during macro expansion.
948
969
pub enum Nonterminal {
949
970
NtBlock ( P < ast:: Block > ) ,
950
- NtExpr ( P < ast:: Expr > ) ,
951
- NtLiteral ( P < ast:: Expr > ) ,
952
971
}
953
972
954
973
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
@@ -1038,15 +1057,12 @@ impl Nonterminal {
1038
1057
pub fn use_span ( & self ) -> Span {
1039
1058
match self {
1040
1059
NtBlock ( block) => block. span ,
1041
- NtExpr ( expr) | NtLiteral ( expr) => expr. span ,
1042
1060
}
1043
1061
}
1044
1062
1045
1063
pub fn descr ( & self ) -> & ' static str {
1046
1064
match self {
1047
1065
NtBlock ( ..) => "block" ,
1048
- NtExpr ( ..) => "expression" ,
1049
- NtLiteral ( ..) => "literal" ,
1050
1066
}
1051
1067
}
1052
1068
}
@@ -1065,8 +1081,6 @@ impl fmt::Debug for Nonterminal {
1065
1081
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1066
1082
match * self {
1067
1083
NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1068
- NtExpr ( ..) => f. pad ( "NtExpr(..)" ) ,
1069
- NtLiteral ( ..) => f. pad ( "NtLiteral(..)" ) ,
1070
1084
}
1071
1085
}
1072
1086
}
@@ -1088,7 +1102,7 @@ mod size_asserts {
1088
1102
// tidy-alphabetical-start
1089
1103
static_assert_size ! ( Lit , 12 ) ;
1090
1104
static_assert_size ! ( LitKind , 2 ) ;
1091
- static_assert_size ! ( Nonterminal , 16 ) ;
1105
+ static_assert_size ! ( Nonterminal , 8 ) ;
1092
1106
static_assert_size ! ( Token , 24 ) ;
1093
1107
static_assert_size ! ( TokenKind , 16 ) ;
1094
1108
// tidy-alphabetical-end
0 commit comments