Make it an incompatibility lint for now

This commit is contained in:
Mark Mansi 2019-01-17 21:19:56 -06:00
parent 3e790a7c30
commit 802b256283
7 changed files with 72 additions and 56 deletions

View File

@ -352,6 +352,12 @@ declare_lint! {
"outlives requirements can be inferred" "outlives requirements can be inferred"
} }
declare_lint! {
pub DUPLICATE_MATCHER_BINDING_NAME,
Warn,
"duplicate macro matcher binding name"
}
/// Some lints that are buffered from `libsyntax`. See `syntax::early_buffered_lints`. /// Some lints that are buffered from `libsyntax`. See `syntax::early_buffered_lints`.
pub mod parser { pub mod parser {
declare_lint! { declare_lint! {

View File

@ -27,7 +27,7 @@ use crate::errors::{DiagnosticBuilder, DiagnosticId};
use crate::hir::def_id::{CrateNum, LOCAL_CRATE}; use crate::hir::def_id::{CrateNum, LOCAL_CRATE};
use crate::hir::intravisit; use crate::hir::intravisit;
use crate::hir; use crate::hir;
use crate::lint::builtin::BuiltinLintDiagnostics; use crate::lint::builtin::{BuiltinLintDiagnostics, DUPLICATE_MATCHER_BINDING_NAME};
use crate::lint::builtin::parser::{QUESTION_MARK_MACRO_SEP, ILL_FORMED_ATTRIBUTE_INPUT}; use crate::lint::builtin::parser::{QUESTION_MARK_MACRO_SEP, ILL_FORMED_ATTRIBUTE_INPUT};
use crate::session::{Session, DiagnosticMessageId}; use crate::session::{Session, DiagnosticMessageId};
use std::{hash, ptr}; use std::{hash, ptr};
@ -82,6 +82,7 @@ impl Lint {
match lint_id { match lint_id {
BufferedEarlyLintId::QuestionMarkMacroSep => QUESTION_MARK_MACRO_SEP, BufferedEarlyLintId::QuestionMarkMacroSep => QUESTION_MARK_MACRO_SEP,
BufferedEarlyLintId::IllFormedAttributeInput => ILL_FORMED_ATTRIBUTE_INPUT, BufferedEarlyLintId::IllFormedAttributeInput => ILL_FORMED_ATTRIBUTE_INPUT,
BufferedEarlyLintId::DuplicateMacroMatcherBindingName => DUPLICATE_MATCHER_BINDING_NAME,
} }
} }

View File

@ -354,6 +354,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>", reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
edition: None, edition: None,
}, },
FutureIncompatibleInfo {
id: LintId::of(DUPLICATE_MATCHER_BINDING_NAME),
reference: "issue #57593 <https://github.com/rust-lang/rust/issues/57593>",
edition: None,
},
]); ]);
// Register renamed and removed lints. // Register renamed and removed lints.

View File

@ -12,6 +12,8 @@ pub enum BufferedEarlyLintId {
/// Usage of `?` as a macro separator is deprecated. /// Usage of `?` as a macro separator is deprecated.
QuestionMarkMacroSep, QuestionMarkMacroSep,
IllFormedAttributeInput, IllFormedAttributeInput,
/// Usage of a duplicate macro matcher binding name.
DuplicateMacroMatcherBindingName,
} }
/// Stores buffered lint info which can later be passed to `librustc`. /// Stores buffered lint info which can later be passed to `librustc`.

View File

@ -360,8 +360,12 @@ pub fn compile(
// don't abort iteration early, so that errors for multiple lhses can be reported // don't abort iteration early, so that errors for multiple lhses can be reported
for lhs in &lhses { for lhs in &lhses {
valid &= check_lhs_no_empty_seq(sess, &[lhs.clone()]); valid &= check_lhs_no_empty_seq(sess, &[lhs.clone()]);
valid &= valid &= check_lhs_duplicate_matcher_bindings(
check_lhs_duplicate_matcher_bindings(sess, &[lhs.clone()], &mut FxHashMap::default()); sess,
&[lhs.clone()],
&mut FxHashMap::default(),
def.id
);
} }
let expander: Box<_> = Box::new(MacroRulesMacroExpander { let expander: Box<_> = Box::new(MacroRulesMacroExpander {
@ -467,29 +471,38 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[quoted::TokenTree]) -> bool {
fn check_lhs_duplicate_matcher_bindings( fn check_lhs_duplicate_matcher_bindings(
sess: &ParseSess, sess: &ParseSess,
tts: &[quoted::TokenTree], tts: &[quoted::TokenTree],
metavar_names: &mut FxHashMap<Ident, Span> metavar_names: &mut FxHashMap<Ident, Span>,
node_id: ast::NodeId,
) -> bool { ) -> bool {
use self::quoted::TokenTree; use self::quoted::TokenTree;
use crate::early_buffered_lints::BufferedEarlyLintId;
for tt in tts { for tt in tts {
match *tt { match *tt {
TokenTree::MetaVarDecl(span, name, _kind) => { TokenTree::MetaVarDecl(span, name, _kind) => {
if let Some(&prev_span) = metavar_names.get(&name) { if let Some(&prev_span) = metavar_names.get(&name) {
sess.span_diagnostic // FIXME(mark-i-m): in a few cycles, make this a hard error.
.struct_span_err(span, "duplicate matcher binding") // sess.span_diagnostic
.span_note(prev_span, "previous declaration was here") // .struct_span_err(span, "duplicate matcher binding")
.emit(); // .span_note(prev_span, "previous declaration was here")
// .emit();
sess.buffer_lint(
BufferedEarlyLintId::DuplicateMacroMatcherBindingName,
crate::source_map::MultiSpan::from(vec![prev_span, span]),
node_id,
"duplicate matcher binding"
);
return false; return false;
} else { } else {
metavar_names.insert(name, span); metavar_names.insert(name, span);
} }
} }
TokenTree::Delimited(_, ref del) => { TokenTree::Delimited(_, ref del) => {
if !check_lhs_duplicate_matcher_bindings(sess, &del.tts, metavar_names) { if !check_lhs_duplicate_matcher_bindings(sess, &del.tts, metavar_names, node_id) {
return false; return false;
} }
}, },
TokenTree::Sequence(_, ref seq) => { TokenTree::Sequence(_, ref seq) => {
if !check_lhs_duplicate_matcher_bindings(sess, &seq.tts, metavar_names) { if !check_lhs_duplicate_matcher_bindings(sess, &seq.tts, metavar_names, node_id) {
return false; return false;
} }
} }

View File

@ -1,9 +1,11 @@
// Test that duplicate matcher binding names are caught at declaration time, rather than at macro // Test that duplicate matcher binding names are caught at declaration time, rather than at macro
// invocation time. // invocation time.
#![allow(unused_macros)]
macro_rules! foo1 { macro_rules! foo1 {
($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding ($a:ident, $a:ident) => {}; //~WARN duplicate matcher binding
($a:ident, $a:path) => {}; //~ERROR duplicate matcher binding ($a:ident, $a:path) => {}; //~WARN duplicate matcher binding
} }
macro_rules! foo2 { macro_rules! foo2 {
@ -12,8 +14,8 @@ macro_rules! foo2 {
} }
macro_rules! foo3 { macro_rules! foo3 {
($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding ($a:ident, $($a:ident),*) => {}; //~WARN duplicate matcher binding
($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding ($($a:ident)+ # $($($a:path),+);*) => {}; //~WARN duplicate matcher binding
} }
fn main() {} fn main() {}

View File

@ -1,50 +1,37 @@
error: duplicate matcher binding warning: duplicate matcher binding
--> $DIR/macro-multiple-matcher-bindings.rs:5:16 --> src/test/ui/macros/macro-multiple-matcher-bindings.rs:7:6
| |
LL | ($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding 7 | ($a:ident, $a:ident) => {}; //~WARN duplicate matcher binding
| ^^^^^^^^ | ^^^^^^^^ ^^^^^^^^
| |
note: previous declaration was here = note: #[warn(duplicate_matcher_binding_name)] on by default
--> $DIR/macro-multiple-matcher-bindings.rs:5:6 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
| = note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
LL | ($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding
| ^^^^^^^^
error: duplicate matcher binding warning: duplicate matcher binding
--> $DIR/macro-multiple-matcher-bindings.rs:6:16 --> src/test/ui/macros/macro-multiple-matcher-bindings.rs:8:6
| |
LL | ($a:ident, $a:path) => {}; //~ERROR duplicate matcher binding 8 | ($a:ident, $a:path) => {}; //~WARN duplicate matcher binding
| ^^^^^^^ | ^^^^^^^^ ^^^^^^^
| |
note: previous declaration was here = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
--> $DIR/macro-multiple-matcher-bindings.rs:6:6 = note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
|
LL | ($a:ident, $a:path) => {}; //~ERROR duplicate matcher binding
| ^^^^^^^^
error: duplicate matcher binding warning: duplicate matcher binding
--> $DIR/macro-multiple-matcher-bindings.rs:15:18 --> src/test/ui/macros/macro-multiple-matcher-bindings.rs:17:6
| |
LL | ($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding LL | ($a:ident, $($a:ident),*) => {}; //~WARN duplicate matcher binding
| ^^^^^^^^ | ^^^^^^^^ ^^^^^^^^
| |
note: previous declaration was here = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
--> $DIR/macro-multiple-matcher-bindings.rs:15:6 = note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
|
LL | ($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding
| ^^^^^^^^
error: duplicate matcher binding warning: duplicate matcher binding
--> $DIR/macro-multiple-matcher-bindings.rs:16:25 --> src/test/ui/macros/macro-multiple-matcher-bindings.rs:18:8
| |
LL | ($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding LL | ($($a:ident)+ # $($($a:path),+);*) => {}; //~WARN duplicate matcher binding
| ^^^^^^^ | ^^^^^^^^ ^^^^^^^
| |
note: previous declaration was here = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
--> $DIR/macro-multiple-matcher-bindings.rs:16:8 = note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
|
LL | ($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding
| ^^^^^^^^
error: aborting due to 4 previous errors