@@ -16,6 +16,8 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
1616
1717 let mut current = buffer. cursor ( ) ;
1818 let mut syntax_context_to_edition_cache = FxHashMap :: default ( ) ;
19+ let mut ctx_edition =
20+ |ctx| * syntax_context_to_edition_cache. entry ( ctx) . or_insert_with ( || span_to_edition ( ctx) ) ;
1921
2022 while !current. eof ( ) {
2123 let tt = current. token_tree ( ) ;
@@ -26,8 +28,8 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
2628 {
2729 current. bump ( ) ;
2830 match current. token_tree ( ) {
29- Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( _ident ) ) ) => {
30- res. push ( LIFETIME_IDENT ) ;
31+ Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident ) ) ) => {
32+ res. push ( LIFETIME_IDENT , ctx_edition ( ident . span . ctx ) ) ;
3133 current. bump ( ) ;
3234 continue ;
3335 }
@@ -51,7 +53,7 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
5153 tt:: LitKind :: CStr | tt:: LitKind :: CStrRaw ( _) => SyntaxKind :: C_STRING ,
5254 tt:: LitKind :: Err ( _) => SyntaxKind :: ERROR ,
5355 } ;
54- res. push ( kind) ;
56+ res. push ( kind, ctx_edition ( lit . span . ctx ) ) ;
5557
5658 if kind == FLOAT_NUMBER && !lit. symbol . as_str ( ) . ends_with ( '.' ) {
5759 // Tag the token as joint if it is float with a fractional part
@@ -61,28 +63,26 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
6163 }
6264 }
6365 tt:: Leaf :: Ident ( ident) => {
64- let edition = * syntax_context_to_edition_cache
65- . entry ( ident. span . ctx )
66- . or_insert_with ( || span_to_edition ( ident. span . ctx ) ) ;
66+ let edition = ctx_edition ( ident. span . ctx ) ;
6767 match ident. sym . as_str ( ) {
68- "_" => res. push ( T ! [ _] ) ,
69- i if i. starts_with ( '\'' ) => res. push ( LIFETIME_IDENT ) ,
70- _ if ident. is_raw . yes ( ) => res. push ( IDENT ) ,
68+ "_" => res. push ( T ! [ _] , edition ) ,
69+ i if i. starts_with ( '\'' ) => res. push ( LIFETIME_IDENT , edition ) ,
70+ _ if ident. is_raw . yes ( ) => res. push ( IDENT , edition ) ,
7171 text => match SyntaxKind :: from_keyword ( text, edition) {
72- Some ( kind) => res. push ( kind) ,
72+ Some ( kind) => res. push ( kind, edition ) ,
7373 None => {
7474 let contextual_keyword =
7575 SyntaxKind :: from_contextual_keyword ( text, edition)
7676 . unwrap_or ( SyntaxKind :: IDENT ) ;
77- res. push_ident ( contextual_keyword) ;
77+ res. push_ident ( contextual_keyword, edition ) ;
7878 }
7979 } ,
8080 }
8181 }
8282 tt:: Leaf :: Punct ( punct) => {
8383 let kind = SyntaxKind :: from_char ( punct. char )
8484 . unwrap_or_else ( || panic ! ( "{punct:#?} is not a valid punct" ) ) ;
85- res. push ( kind) ;
85+ res. push ( kind, ctx_edition ( punct . span . ctx ) ) ;
8686 if punct. spacing == tt:: Spacing :: Joint {
8787 res. was_joint ( ) ;
8888 }
@@ -97,7 +97,7 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
9797 tt:: DelimiterKind :: Bracket => Some ( T ! [ '[' ] ) ,
9898 tt:: DelimiterKind :: Invisible => None ,
9999 } {
100- res. push ( kind) ;
100+ res. push ( kind, ctx_edition ( subtree . delimiter . open . ctx ) ) ;
101101 }
102102 current. bump ( ) ;
103103 }
@@ -109,7 +109,7 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
109109 tt:: DelimiterKind :: Bracket => Some ( T ! [ ']' ] ) ,
110110 tt:: DelimiterKind :: Invisible => None ,
111111 } {
112- res. push ( kind) ;
112+ res. push ( kind, ctx_edition ( subtree . delimiter . close . ctx ) ) ;
113113 }
114114 }
115115 } ;
0 commit comments