1- use crate :: base:: { DummyResult , ExpansionData , ExtCtxt , MacResult , TTMacroExpander } ;
1+ use crate :: base:: { DummyResult , ExtCtxt , MacResult , TTMacroExpander } ;
22use crate :: base:: { SyntaxExtension , SyntaxExtensionKind } ;
33use crate :: expand:: { ensure_complete_parse, parse_ast_fragment, AstFragment , AstFragmentKind } ;
44use crate :: mbe;
@@ -18,7 +18,6 @@ use rustc_data_structures::sync::Lrc;
1818use rustc_errors:: { Applicability , DiagnosticBuilder , FatalError } ;
1919use rustc_feature:: Features ;
2020use rustc_parse:: parser:: Parser ;
21- use rustc_parse:: Directory ;
2221use rustc_session:: parse:: ParseSess ;
2322use rustc_span:: edition:: Edition ;
2423use rustc_span:: hygiene:: Transparency ;
@@ -182,6 +181,8 @@ fn generic_extension<'cx>(
182181 lhses : & [ mbe:: TokenTree ] ,
183182 rhses : & [ mbe:: TokenTree ] ,
184183) -> Box < dyn MacResult + ' cx > {
184+ let sess = cx. parse_sess ;
185+
185186 if cx. trace_macros ( ) {
186187 let msg = format ! ( "expanding `{}! {{ {} }}`" , name, pprust:: tts_to_string( arg. clone( ) ) ) ;
187188 trace_macros_note ( & mut cx. expansions , sp, msg) ;
@@ -209,7 +210,7 @@ fn generic_extension<'cx>(
209210 // hacky, but speeds up the `html5ever` benchmark significantly. (Issue
210211 // 68836 suggests a more comprehensive but more complex change to deal with
211212 // this situation.)
212- let parser = parser_from_cx ( & cx . current_expansion , & cx . parse_sess , arg. clone ( ) ) ;
213+ let parser = parser_from_cx ( sess , arg. clone ( ) ) ;
213214
214215 for ( i, lhs) in lhses. iter ( ) . enumerate ( ) {
215216 // try each arm's matchers
@@ -222,14 +223,13 @@ fn generic_extension<'cx>(
222223 // This is used so that if a matcher is not `Success(..)`ful,
223224 // then the spans which became gated when parsing the unsuccessful matcher
224225 // are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
225- let mut gated_spans_snapshot =
226- mem:: take ( & mut * cx. parse_sess . gated_spans . spans . borrow_mut ( ) ) ;
226+ let mut gated_spans_snapshot = mem:: take ( & mut * sess. gated_spans . spans . borrow_mut ( ) ) ;
227227
228228 match parse_tt ( & mut Cow :: Borrowed ( & parser) , lhs_tt) {
229229 Success ( named_matches) => {
230230 // The matcher was `Success(..)`ful.
231231 // Merge the gated spans from parsing the matcher with the pre-existing ones.
232- cx . parse_sess . gated_spans . merge ( gated_spans_snapshot) ;
232+ sess . gated_spans . merge ( gated_spans_snapshot) ;
233233
234234 let rhs = match rhses[ i] {
235235 // ignore delimiters
@@ -258,11 +258,7 @@ fn generic_extension<'cx>(
258258 trace_macros_note ( & mut cx. expansions , sp, msg) ;
259259 }
260260
261- let directory = Directory {
262- path : cx. current_expansion . module . directory . clone ( ) ,
263- ownership : cx. current_expansion . directory_ownership ,
264- } ;
265- let mut p = Parser :: new ( cx. parse_sess ( ) , tts, Some ( directory) , true , false , None ) ;
261+ let mut p = Parser :: new ( sess, tts, false , None ) ;
266262 p. root_module_name =
267263 cx. current_expansion . module . mod_path . last ( ) . map ( |id| id. to_string ( ) ) ;
268264 p. last_type_ascription = cx. current_expansion . prior_type_ascription ;
@@ -289,7 +285,7 @@ fn generic_extension<'cx>(
289285
290286 // The matcher was not `Success(..)`ful.
291287 // Restore to the state before snapshotting and maybe try again.
292- mem:: swap ( & mut gated_spans_snapshot, & mut cx . parse_sess . gated_spans . spans . borrow_mut ( ) ) ;
288+ mem:: swap ( & mut gated_spans_snapshot, & mut sess . gated_spans . spans . borrow_mut ( ) ) ;
293289 }
294290 drop ( parser) ;
295291
@@ -309,8 +305,7 @@ fn generic_extension<'cx>(
309305 mbe:: TokenTree :: Delimited ( _, ref delim) => & delim. tts [ ..] ,
310306 _ => continue ,
311307 } ;
312- let parser = parser_from_cx ( & cx. current_expansion , & cx. parse_sess , arg. clone ( ) ) ;
313- match parse_tt ( & mut Cow :: Borrowed ( & parser) , lhs_tt) {
308+ match parse_tt ( & mut Cow :: Borrowed ( & parser_from_cx ( sess, arg. clone ( ) ) ) , lhs_tt) {
314309 Success ( _) => {
315310 if comma_span. is_dummy ( ) {
316311 err. note ( "you might be missing a comma" ) ;
@@ -392,7 +387,7 @@ pub fn compile_declarative_macro(
392387 ) ,
393388 ] ;
394389
395- let parser = Parser :: new ( sess, body, None , true , true , rustc_parse:: MACRO_ARGUMENTS ) ;
390+ let parser = Parser :: new ( sess, body, true , rustc_parse:: MACRO_ARGUMENTS ) ;
396391 let argument_map = match parse_tt ( & mut Cow :: Borrowed ( & parser) , & argument_gram) {
397392 Success ( m) => m,
398393 Failure ( token, msg) => {
@@ -1209,16 +1204,8 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
12091204 }
12101205}
12111206
1212- fn parser_from_cx < ' cx > (
1213- current_expansion : & ' cx ExpansionData ,
1214- sess : & ' cx ParseSess ,
1215- tts : TokenStream ,
1216- ) -> Parser < ' cx > {
1217- let directory = Directory {
1218- path : current_expansion. module . directory . clone ( ) ,
1219- ownership : current_expansion. directory_ownership ,
1220- } ;
1221- Parser :: new ( sess, tts, Some ( directory) , true , true , rustc_parse:: MACRO_ARGUMENTS )
1207+ fn parser_from_cx ( sess : & ParseSess , tts : TokenStream ) -> Parser < ' _ > {
1208+ Parser :: new ( sess, tts, true , rustc_parse:: MACRO_ARGUMENTS )
12221209}
12231210
12241211/// Generates an appropriate parsing failure message. For EOF, this is "unexpected end...". For
0 commit comments