@@ -17,7 +17,7 @@ mod tt_iter;
17
17
#[ cfg( test) ]
18
18
mod benchmark;
19
19
20
- use span:: Span ;
20
+ use span:: { Edition , Span , SyntaxContextId } ;
21
21
use stdx:: impl_from;
22
22
23
23
use std:: fmt;
@@ -129,9 +129,6 @@ impl fmt::Display for CountError {
129
129
#[ derive( Clone , Debug , PartialEq , Eq ) ]
130
130
pub struct DeclarativeMacro {
131
131
rules : Box < [ Rule ] > ,
132
- // This is used for correctly determining the behavior of the pat fragment
133
- // FIXME: This should be tracked by hygiene of the fragment identifier!
134
- is_2021 : bool ,
135
132
err : Option < Box < ParseError > > ,
136
133
}
137
134
@@ -142,14 +139,14 @@ struct Rule {
142
139
}
143
140
144
141
impl DeclarativeMacro {
145
- pub fn from_err ( err : ParseError , is_2021 : bool ) -> DeclarativeMacro {
146
- DeclarativeMacro { rules : Box :: default ( ) , is_2021 , err : Some ( Box :: new ( err) ) }
142
+ pub fn from_err ( err : ParseError ) -> DeclarativeMacro {
143
+ DeclarativeMacro { rules : Box :: default ( ) , err : Some ( Box :: new ( err) ) }
147
144
}
148
145
149
146
/// The old, `macro_rules! m {}` flavor.
150
147
pub fn parse_macro_rules (
151
148
tt : & tt:: Subtree < Span > ,
152
- is_2021 : bool ,
149
+ edition : impl Copy + Fn ( SyntaxContextId ) -> Edition ,
153
150
// FIXME: Remove this once we drop support for rust 1.76 (defaults to true then)
154
151
new_meta_vars : bool ,
155
152
) -> DeclarativeMacro {
@@ -161,7 +158,7 @@ impl DeclarativeMacro {
161
158
let mut err = None ;
162
159
163
160
while src. len ( ) > 0 {
164
- let rule = match Rule :: parse ( & mut src, true , new_meta_vars) {
161
+ let rule = match Rule :: parse ( edition , & mut src, true , new_meta_vars) {
165
162
Ok ( it) => it,
166
163
Err ( e) => {
167
164
err = Some ( Box :: new ( e) ) ;
@@ -184,13 +181,13 @@ impl DeclarativeMacro {
184
181
}
185
182
}
186
183
187
- DeclarativeMacro { rules : rules. into_boxed_slice ( ) , is_2021 , err }
184
+ DeclarativeMacro { rules : rules. into_boxed_slice ( ) , err }
188
185
}
189
186
190
187
/// The new, unstable `macro m {}` flavor.
191
188
pub fn parse_macro2 (
192
189
tt : & tt:: Subtree < Span > ,
193
- is_2021 : bool ,
190
+ edition : impl Copy + Fn ( SyntaxContextId ) -> Edition ,
194
191
// FIXME: Remove this once we drop support for rust 1.76 (defaults to true then)
195
192
new_meta_vars : bool ,
196
193
) -> DeclarativeMacro {
@@ -201,7 +198,7 @@ impl DeclarativeMacro {
201
198
if tt:: DelimiterKind :: Brace == tt. delimiter . kind {
202
199
cov_mark:: hit!( parse_macro_def_rules) ;
203
200
while src. len ( ) > 0 {
204
- let rule = match Rule :: parse ( & mut src, true , new_meta_vars) {
201
+ let rule = match Rule :: parse ( edition , & mut src, true , new_meta_vars) {
205
202
Ok ( it) => it,
206
203
Err ( e) => {
207
204
err = Some ( Box :: new ( e) ) ;
@@ -220,7 +217,7 @@ impl DeclarativeMacro {
220
217
}
221
218
} else {
222
219
cov_mark:: hit!( parse_macro_def_simple) ;
223
- match Rule :: parse ( & mut src, false , new_meta_vars) {
220
+ match Rule :: parse ( edition , & mut src, false , new_meta_vars) {
224
221
Ok ( rule) => {
225
222
if src. len ( ) != 0 {
226
223
err = Some ( Box :: new ( ParseError :: expected ( "remaining tokens in macro def" ) ) ) ;
@@ -240,7 +237,7 @@ impl DeclarativeMacro {
240
237
}
241
238
}
242
239
243
- DeclarativeMacro { rules : rules. into_boxed_slice ( ) , is_2021 , err }
240
+ DeclarativeMacro { rules : rules. into_boxed_slice ( ) , err }
244
241
}
245
242
246
243
pub fn err ( & self ) -> Option < & ParseError > {
@@ -254,12 +251,13 @@ impl DeclarativeMacro {
254
251
new_meta_vars : bool ,
255
252
call_site : Span ,
256
253
) -> ExpandResult < tt:: Subtree < Span > > {
257
- expander:: expand_rules ( & self . rules , tt, marker, self . is_2021 , new_meta_vars, call_site)
254
+ expander:: expand_rules ( & self . rules , tt, marker, new_meta_vars, call_site)
258
255
}
259
256
}
260
257
261
258
impl Rule {
262
259
fn parse (
260
+ edition : impl Copy + Fn ( SyntaxContextId ) -> Edition ,
263
261
src : & mut TtIter < ' _ , Span > ,
264
262
expect_arrow : bool ,
265
263
new_meta_vars : bool ,
@@ -271,8 +269,8 @@ impl Rule {
271
269
}
272
270
let rhs = src. expect_subtree ( ) . map_err ( |( ) | ParseError :: expected ( "expected subtree" ) ) ?;
273
271
274
- let lhs = MetaTemplate :: parse_pattern ( lhs) ?;
275
- let rhs = MetaTemplate :: parse_template ( rhs, new_meta_vars) ?;
272
+ let lhs = MetaTemplate :: parse_pattern ( edition , lhs) ?;
273
+ let rhs = MetaTemplate :: parse_template ( edition , rhs, new_meta_vars) ?;
276
274
277
275
Ok ( crate :: Rule { lhs, rhs } )
278
276
}
0 commit comments