1
- use crate :: base:: { DummyResult , ExpansionData , ExtCtxt , MacResult , TTMacroExpander } ;
1
+ use crate :: base:: { DummyResult , ExtCtxt , MacResult , TTMacroExpander } ;
2
2
use crate :: base:: { SyntaxExtension , SyntaxExtensionKind } ;
3
3
use crate :: expand:: { ensure_complete_parse, parse_ast_fragment, AstFragment , AstFragmentKind } ;
4
4
use crate :: mbe;
@@ -18,7 +18,6 @@ use rustc_data_structures::sync::Lrc;
18
18
use rustc_errors:: { Applicability , DiagnosticBuilder , FatalError } ;
19
19
use rustc_feature:: Features ;
20
20
use rustc_parse:: parser:: Parser ;
21
- use rustc_parse:: Directory ;
22
21
use rustc_session:: parse:: ParseSess ;
23
22
use rustc_span:: edition:: Edition ;
24
23
use rustc_span:: hygiene:: Transparency ;
@@ -182,6 +181,8 @@ fn generic_extension<'cx>(
182
181
lhses : & [ mbe:: TokenTree ] ,
183
182
rhses : & [ mbe:: TokenTree ] ,
184
183
) -> Box < dyn MacResult + ' cx > {
184
+ let sess = cx. parse_sess ;
185
+
185
186
if cx. trace_macros ( ) {
186
187
let msg = format ! ( "expanding `{}! {{ {} }}`" , name, pprust:: tts_to_string( arg. clone( ) ) ) ;
187
188
trace_macros_note ( & mut cx. expansions , sp, msg) ;
@@ -209,7 +210,7 @@ fn generic_extension<'cx>(
209
210
// hacky, but speeds up the `html5ever` benchmark significantly. (Issue
210
211
// 68836 suggests a more comprehensive but more complex change to deal with
211
212
// 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 ( ) ) ;
213
214
214
215
for ( i, lhs) in lhses. iter ( ) . enumerate ( ) {
215
216
// try each arm's matchers
@@ -222,14 +223,13 @@ fn generic_extension<'cx>(
222
223
// This is used so that if a matcher is not `Success(..)`ful,
223
224
// then the spans which became gated when parsing the unsuccessful matcher
224
225
// 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 ( ) ) ;
227
227
228
228
match parse_tt ( & mut Cow :: Borrowed ( & parser) , lhs_tt) {
229
229
Success ( named_matches) => {
230
230
// The matcher was `Success(..)`ful.
231
231
// 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) ;
233
233
234
234
let rhs = match rhses[ i] {
235
235
// ignore delimiters
@@ -258,11 +258,7 @@ fn generic_extension<'cx>(
258
258
trace_macros_note ( & mut cx. expansions , sp, msg) ;
259
259
}
260
260
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 ) ;
266
262
p. root_module_name =
267
263
cx. current_expansion . module . mod_path . last ( ) . map ( |id| id. to_string ( ) ) ;
268
264
p. last_type_ascription = cx. current_expansion . prior_type_ascription ;
@@ -289,7 +285,7 @@ fn generic_extension<'cx>(
289
285
290
286
// The matcher was not `Success(..)`ful.
291
287
// 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 ( ) ) ;
293
289
}
294
290
drop ( parser) ;
295
291
@@ -309,8 +305,7 @@ fn generic_extension<'cx>(
309
305
mbe:: TokenTree :: Delimited ( _, ref delim) => & delim. tts [ ..] ,
310
306
_ => continue ,
311
307
} ;
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) {
314
309
Success ( _) => {
315
310
if comma_span. is_dummy ( ) {
316
311
err. note ( "you might be missing a comma" ) ;
@@ -392,7 +387,7 @@ pub fn compile_declarative_macro(
392
387
) ,
393
388
] ;
394
389
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 ) ;
396
391
let argument_map = match parse_tt ( & mut Cow :: Borrowed ( & parser) , & argument_gram) {
397
392
Success ( m) => m,
398
393
Failure ( token, msg) => {
@@ -1209,16 +1204,8 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
1209
1204
}
1210
1205
}
1211
1206
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 )
1222
1209
}
1223
1210
1224
1211
/// Generates an appropriate parsing failure message. For EOF, this is "unexpected end...". For
0 commit comments