88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11+ use ast:: NodeId ;
12+ use early_buffered_lints:: BufferedEarlyLintId ;
1113use ext:: tt:: macro_parser;
1214use feature_gate:: { self , emit_feature_err, Features , GateIssue } ;
1315use parse:: { token, ParseSess } ;
@@ -175,6 +177,7 @@ impl TokenTree {
175177/// - `features`, `attrs`: language feature flags and attributes so that we know whether to use
176178/// unstable features or not.
177179/// - `edition`: which edition are we in.
180+ /// - `macro_node_id`: the NodeId of the macro we are parsing.
178181///
179182/// # Returns
180183///
@@ -186,6 +189,7 @@ pub fn parse(
186189 features : & Features ,
187190 attrs : & [ ast:: Attribute ] ,
188191 edition : Edition ,
192+ macro_node_id : NodeId ,
189193) -> Vec < TokenTree > {
190194 // Will contain the final collection of `self::TokenTree`
191195 let mut result = Vec :: new ( ) ;
@@ -204,6 +208,7 @@ pub fn parse(
204208 features,
205209 attrs,
206210 edition,
211+ macro_node_id,
207212 ) ;
208213 match tree {
209214 TokenTree :: MetaVar ( start_sp, ident) if expect_matchers => {
@@ -265,6 +270,7 @@ fn parse_tree<I>(
265270 features : & Features ,
266271 attrs : & [ ast:: Attribute ] ,
267272 edition : Edition ,
273+ macro_node_id : NodeId ,
268274) -> TokenTree
269275where
270276 I : Iterator < Item = tokenstream:: TokenTree > ,
@@ -290,10 +296,19 @@ where
290296 features,
291297 attrs,
292298 edition,
299+ macro_node_id,
293300 ) ;
294301 // Get the Kleene operator and optional separator
295302 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+ ) ;
297312 // Count the number of captured "names" (i.e. named metavars)
298313 let name_captures = macro_parser:: count_names ( & sequence) ;
299314 TokenTree :: Sequence (
@@ -350,6 +365,7 @@ where
350365 features,
351366 attrs,
352367 edition,
368+ macro_node_id,
353369 ) ,
354370 } ) ,
355371 ) ,
@@ -413,12 +429,20 @@ fn parse_sep_and_kleene_op<I>(
413429 features : & Features ,
414430 attrs : & [ ast:: Attribute ] ,
415431 edition : Edition ,
432+ macro_node_id : NodeId ,
416433) -> ( Option < token:: Token > , KleeneOp )
417434where
418435 I : Iterator < Item = tokenstream:: TokenTree > ,
419436{
420437 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+ ) ,
422446 Edition :: Edition2018 => parse_sep_and_kleene_op_2018 ( input, span, sess, features, attrs) ,
423447 _ => unimplemented ! ( ) ,
424448 }
@@ -431,6 +455,7 @@ fn parse_sep_and_kleene_op_2015<I>(
431455 sess : & ParseSess ,
432456 _features : & Features ,
433457 _attrs : & [ ast:: Attribute ] ,
458+ macro_node_id : NodeId ,
434459) -> ( Option < token:: Token > , KleeneOp )
435460where
436461 I : Iterator < Item = tokenstream:: TokenTree > ,
@@ -474,8 +499,10 @@ where
474499 // #2 is a Kleene op, which is the the only valid option
475500 Ok ( Ok ( ( op, _) ) ) => {
476501 // Warn that `?` as a separator will be deprecated
477- sess. span_diagnostic . span_warn (
502+ sess. buffer_lint (
503+ BufferedEarlyLintId :: QuestionMarkMacroSep ,
478504 op1_span,
505+ macro_node_id,
479506 "using `?` as a separator is deprecated and will be \
480507 a hard error in an upcoming edition",
481508 ) ;
0 commit comments