Skip to content

Commit b206aed

Browse files
committed
make it a migration lint
1 parent 5d87272 commit b206aed

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

src/librustc_lint/lib.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ extern crate syntax_pos;
4444

4545
use rustc::lint;
4646
use rustc::lint::{LateContext, LateLintPass, LintPass, LintArray};
47-
use rustc::lint::builtin::{BARE_TRAIT_OBJECTS, ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
48-
ELIDED_LIFETIMES_IN_PATHS};
49-
use rustc::lint::builtin::MACRO_USE_EXTERN_CRATE;
47+
use rustc::lint::builtin::{
48+
BARE_TRAIT_OBJECTS,
49+
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
50+
MACRO_USE_EXTERN_CRATE,
51+
ELIDED_LIFETIMES_IN_PATHS,
52+
parser::QUESTION_MARK_MACRO_SEP
53+
};
5054
use rustc::session;
5155
use rustc::util;
5256
use rustc::hir;
@@ -321,6 +325,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
321325
reference: "issue #50504 <https://github.com/rust-lang/rust/issues/50504>",
322326
edition: None,
323327
},
328+
FutureIncompatibleInfo {
329+
id: LintId::of(QUESTION_MARK_MACRO_SEP),
330+
reference: "issue #48075 <https://github.com/rust-lang/rust/issues/48075>",
331+
edition: Some(Edition::Edition2018),
332+
}
324333
]);
325334

326335
// Register renamed and removed lints

src/libsyntax/early_buffered_lints.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
//! Allows the buffering of lints for later.
212
//!
313
//! Since we cannot have a dependency on `librustc`, we implement some types here that are somewhat

src/libsyntax/ext/tt/macro_rules.rs

+2
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item, edition:
247247
features,
248248
&def.attrs,
249249
edition,
250+
def.id,
250251
)
251252
.pop()
252253
.unwrap();
@@ -272,6 +273,7 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item, edition:
272273
features,
273274
&def.attrs,
274275
edition,
276+
def.id,
275277
).pop()
276278
.unwrap();
277279
}

src/libsyntax/ext/tt/quoted.rs

+30-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
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;
1113
use ext::tt::macro_parser;
1214
use feature_gate::{self, emit_feature_err, Features, GateIssue};
1315
use 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
269275
where
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)
417434
where
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)
435460
where
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

Comments
 (0)