@@ -16,6 +16,8 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
16
16
17
17
let mut current = buffer. cursor ( ) ;
18
18
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) ) ;
19
21
20
22
while !current. eof ( ) {
21
23
let tt = current. token_tree ( ) ;
@@ -25,8 +27,8 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
25
27
if punct. char == '\'' {
26
28
current. bump ( ) ;
27
29
match current. token_tree ( ) {
28
- Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( _ident ) ) ) => {
29
- res. push ( LIFETIME_IDENT ) ;
30
+ Some ( tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident ) ) ) => {
31
+ res. push ( LIFETIME_IDENT , ctx_edition ( ident . span . ctx ) ) ;
30
32
current. bump ( ) ;
31
33
continue ;
32
34
}
@@ -51,7 +53,7 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
51
53
tt:: LitKind :: CStr | tt:: LitKind :: CStrRaw ( _) => SyntaxKind :: C_STRING ,
52
54
tt:: LitKind :: Err ( _) => SyntaxKind :: ERROR ,
53
55
} ;
54
- res. push ( kind) ;
56
+ res. push ( kind, ctx_edition ( lit . span . ctx ) ) ;
55
57
56
58
if kind == FLOAT_NUMBER && !lit. symbol . as_str ( ) . ends_with ( '.' ) {
57
59
// 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>(
61
63
}
62
64
}
63
65
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 ) ;
67
67
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 ) ,
71
71
text => match SyntaxKind :: from_keyword ( text, edition) {
72
- Some ( kind) => res. push ( kind) ,
72
+ Some ( kind) => res. push ( kind, edition ) ,
73
73
None => {
74
74
let contextual_keyword =
75
75
SyntaxKind :: from_contextual_keyword ( text, edition)
76
76
. unwrap_or ( SyntaxKind :: IDENT ) ;
77
- res. push_ident ( contextual_keyword) ;
77
+ res. push_ident ( contextual_keyword, edition ) ;
78
78
}
79
79
} ,
80
80
}
81
81
}
82
82
tt:: Leaf :: Punct ( punct) => {
83
83
let kind = SyntaxKind :: from_char ( punct. char )
84
84
. unwrap_or_else ( || panic ! ( "{punct:#?} is not a valid punct" ) ) ;
85
- res. push ( kind) ;
85
+ res. push ( kind, ctx_edition ( punct . span . ctx ) ) ;
86
86
if punct. spacing == tt:: Spacing :: Joint {
87
87
res. was_joint ( ) ;
88
88
}
@@ -97,7 +97,7 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
97
97
tt:: DelimiterKind :: Bracket => Some ( T ! [ '[' ] ) ,
98
98
tt:: DelimiterKind :: Invisible => None ,
99
99
} {
100
- res. push ( kind) ;
100
+ res. push ( kind, ctx_edition ( subtree . delimiter . open . ctx ) ) ;
101
101
}
102
102
current. bump ( ) ;
103
103
}
@@ -109,7 +109,7 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
109
109
tt:: DelimiterKind :: Bracket => Some ( T ! [ ']' ] ) ,
110
110
tt:: DelimiterKind :: Invisible => None ,
111
111
} {
112
- res. push ( kind) ;
112
+ res. push ( kind, ctx_edition ( subtree . delimiter . close . ctx ) ) ;
113
113
}
114
114
}
115
115
} ;
0 commit comments