@@ -17,7 +17,7 @@ mod tt_iter;
1717#[ cfg( test) ]
1818mod benchmark;
1919
20- use span:: Span ;
20+ use span:: { Edition , Span , SyntaxContextId } ;
2121use stdx:: impl_from;
2222
2323use std:: fmt;
@@ -129,9 +129,6 @@ impl fmt::Display for CountError {
129129#[ derive( Clone , Debug , PartialEq , Eq ) ]
130130pub struct DeclarativeMacro {
131131 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 ,
135132 err : Option < Box < ParseError > > ,
136133}
137134
@@ -142,14 +139,14 @@ struct Rule {
142139}
143140
144141impl 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) ) }
147144 }
148145
149146 /// The old, `macro_rules! m {}` flavor.
150147 pub fn parse_macro_rules (
151148 tt : & tt:: Subtree < Span > ,
152- is_2021 : bool ,
149+ edition : impl Copy + Fn ( SyntaxContextId ) -> Edition ,
153150 // FIXME: Remove this once we drop support for rust 1.76 (defaults to true then)
154151 new_meta_vars : bool ,
155152 ) -> DeclarativeMacro {
@@ -161,7 +158,7 @@ impl DeclarativeMacro {
161158 let mut err = None ;
162159
163160 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) {
165162 Ok ( it) => it,
166163 Err ( e) => {
167164 err = Some ( Box :: new ( e) ) ;
@@ -184,13 +181,13 @@ impl DeclarativeMacro {
184181 }
185182 }
186183
187- DeclarativeMacro { rules : rules. into_boxed_slice ( ) , is_2021 , err }
184+ DeclarativeMacro { rules : rules. into_boxed_slice ( ) , err }
188185 }
189186
190187 /// The new, unstable `macro m {}` flavor.
191188 pub fn parse_macro2 (
192189 tt : & tt:: Subtree < Span > ,
193- is_2021 : bool ,
190+ edition : impl Copy + Fn ( SyntaxContextId ) -> Edition ,
194191 // FIXME: Remove this once we drop support for rust 1.76 (defaults to true then)
195192 new_meta_vars : bool ,
196193 ) -> DeclarativeMacro {
@@ -201,7 +198,7 @@ impl DeclarativeMacro {
201198 if tt:: DelimiterKind :: Brace == tt. delimiter . kind {
202199 cov_mark:: hit!( parse_macro_def_rules) ;
203200 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) {
205202 Ok ( it) => it,
206203 Err ( e) => {
207204 err = Some ( Box :: new ( e) ) ;
@@ -220,7 +217,7 @@ impl DeclarativeMacro {
220217 }
221218 } else {
222219 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) {
224221 Ok ( rule) => {
225222 if src. len ( ) != 0 {
226223 err = Some ( Box :: new ( ParseError :: expected ( "remaining tokens in macro def" ) ) ) ;
@@ -240,7 +237,7 @@ impl DeclarativeMacro {
240237 }
241238 }
242239
243- DeclarativeMacro { rules : rules. into_boxed_slice ( ) , is_2021 , err }
240+ DeclarativeMacro { rules : rules. into_boxed_slice ( ) , err }
244241 }
245242
246243 pub fn err ( & self ) -> Option < & ParseError > {
@@ -254,12 +251,13 @@ impl DeclarativeMacro {
254251 new_meta_vars : bool ,
255252 call_site : Span ,
256253 ) -> 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)
258255 }
259256}
260257
261258impl Rule {
262259 fn parse (
260+ edition : impl Copy + Fn ( SyntaxContextId ) -> Edition ,
263261 src : & mut TtIter < ' _ , Span > ,
264262 expect_arrow : bool ,
265263 new_meta_vars : bool ,
@@ -271,8 +269,8 @@ impl Rule {
271269 }
272270 let rhs = src. expect_subtree ( ) . map_err ( |( ) | ParseError :: expected ( "expected subtree" ) ) ?;
273271
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) ?;
276274
277275 Ok ( crate :: Rule { lhs, rhs } )
278276 }
0 commit comments