8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ use ast:: NodeId ;
12
+ use early_buffered_lints:: BufferedEarlyLintId ;
11
13
use ext:: tt:: macro_parser;
12
14
use feature_gate:: { self , emit_feature_err, Features , GateIssue } ;
13
15
use parse:: { token, ParseSess } ;
@@ -175,6 +177,7 @@ impl TokenTree {
175
177
/// - `features`, `attrs`: language feature flags and attributes so that we know whether to use
176
178
/// unstable features or not.
177
179
/// - `edition`: which edition are we in.
180
+ /// - `macro_node_id`: the NodeId of the macro we are parsing.
178
181
///
179
182
/// # Returns
180
183
///
@@ -186,6 +189,7 @@ pub fn parse(
186
189
features : & Features ,
187
190
attrs : & [ ast:: Attribute ] ,
188
191
edition : Edition ,
192
+ macro_node_id : NodeId ,
189
193
) -> Vec < TokenTree > {
190
194
// Will contain the final collection of `self::TokenTree`
191
195
let mut result = Vec :: new ( ) ;
@@ -204,6 +208,7 @@ pub fn parse(
204
208
features,
205
209
attrs,
206
210
edition,
211
+ macro_node_id,
207
212
) ;
208
213
match tree {
209
214
TokenTree :: MetaVar ( start_sp, ident) if expect_matchers => {
@@ -265,6 +270,7 @@ fn parse_tree<I>(
265
270
features : & Features ,
266
271
attrs : & [ ast:: Attribute ] ,
267
272
edition : Edition ,
273
+ macro_node_id : NodeId ,
268
274
) -> TokenTree
269
275
where
270
276
I : Iterator < Item = tokenstream:: TokenTree > ,
@@ -290,10 +296,19 @@ where
290
296
features,
291
297
attrs,
292
298
edition,
299
+ macro_node_id,
293
300
) ;
294
301
// Get the Kleene operator and optional separator
295
302
let ( separator, op) =
296
- parse_sep_and_kleene_op ( trees, span, sess, features, attrs, edition) ;
303
+ parse_sep_and_kleene_op (
304
+ trees,
305
+ span,
306
+ sess,
307
+ features,
308
+ attrs,
309
+ edition,
310
+ macro_node_id,
311
+ ) ;
297
312
// Count the number of captured "names" (i.e. named metavars)
298
313
let name_captures = macro_parser:: count_names ( & sequence) ;
299
314
TokenTree :: Sequence (
@@ -350,6 +365,7 @@ where
350
365
features,
351
366
attrs,
352
367
edition,
368
+ macro_node_id,
353
369
) ,
354
370
} ) ,
355
371
) ,
@@ -413,12 +429,20 @@ fn parse_sep_and_kleene_op<I>(
413
429
features : & Features ,
414
430
attrs : & [ ast:: Attribute ] ,
415
431
edition : Edition ,
432
+ macro_node_id : NodeId ,
416
433
) -> ( Option < token:: Token > , KleeneOp )
417
434
where
418
435
I : Iterator < Item = tokenstream:: TokenTree > ,
419
436
{
420
437
match edition {
421
- Edition :: Edition2015 => parse_sep_and_kleene_op_2015 ( input, span, sess, features, attrs) ,
438
+ Edition :: Edition2015 => parse_sep_and_kleene_op_2015 (
439
+ input,
440
+ span,
441
+ sess,
442
+ features,
443
+ attrs,
444
+ macro_node_id,
445
+ ) ,
422
446
Edition :: Edition2018 => parse_sep_and_kleene_op_2018 ( input, span, sess, features, attrs) ,
423
447
_ => unimplemented ! ( ) ,
424
448
}
@@ -431,6 +455,7 @@ fn parse_sep_and_kleene_op_2015<I>(
431
455
sess : & ParseSess ,
432
456
_features : & Features ,
433
457
_attrs : & [ ast:: Attribute ] ,
458
+ macro_node_id : NodeId ,
434
459
) -> ( Option < token:: Token > , KleeneOp )
435
460
where
436
461
I : Iterator < Item = tokenstream:: TokenTree > ,
@@ -474,8 +499,10 @@ where
474
499
// #2 is a Kleene op, which is the the only valid option
475
500
Ok ( Ok ( ( op, _) ) ) => {
476
501
// Warn that `?` as a separator will be deprecated
477
- sess. span_diagnostic . span_warn (
502
+ sess. buffer_lint (
503
+ BufferedEarlyLintId :: QuestionMarkMacroSep ,
478
504
op1_span,
505
+ macro_node_id,
479
506
"using `?` as a separator is deprecated and will be \
480
507
a hard error in an upcoming edition",
481
508
) ;
0 commit comments