Skip to content

Commit 802b256

Browse files
committed
Make it an incompatibility lint for now
1 parent 3e790a7 commit 802b256

File tree

7 files changed

+72
-56
lines changed

7 files changed

+72
-56
lines changed

src/librustc/lint/builtin.rs

+6
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ declare_lint! {
352352
"outlives requirements can be inferred"
353353
}
354354

355+
declare_lint! {
356+
pub DUPLICATE_MATCHER_BINDING_NAME,
357+
Warn,
358+
"duplicate macro matcher binding name"
359+
}
360+
355361
/// Some lints that are buffered from `libsyntax`. See `syntax::early_buffered_lints`.
356362
pub mod parser {
357363
declare_lint! {

src/librustc/lint/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::errors::{DiagnosticBuilder, DiagnosticId};
2727
use crate::hir::def_id::{CrateNum, LOCAL_CRATE};
2828
use crate::hir::intravisit;
2929
use crate::hir;
30-
use crate::lint::builtin::BuiltinLintDiagnostics;
30+
use crate::lint::builtin::{BuiltinLintDiagnostics, DUPLICATE_MATCHER_BINDING_NAME};
3131
use crate::lint::builtin::parser::{QUESTION_MARK_MACRO_SEP, ILL_FORMED_ATTRIBUTE_INPUT};
3232
use crate::session::{Session, DiagnosticMessageId};
3333
use std::{hash, ptr};
@@ -82,6 +82,7 @@ impl Lint {
8282
match lint_id {
8383
BufferedEarlyLintId::QuestionMarkMacroSep => QUESTION_MARK_MACRO_SEP,
8484
BufferedEarlyLintId::IllFormedAttributeInput => ILL_FORMED_ATTRIBUTE_INPUT,
85+
BufferedEarlyLintId::DuplicateMacroMatcherBindingName => DUPLICATE_MATCHER_BINDING_NAME,
8586
}
8687
}
8788

src/librustc_lint/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
354354
reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
355355
edition: None,
356356
},
357+
FutureIncompatibleInfo {
358+
id: LintId::of(DUPLICATE_MATCHER_BINDING_NAME),
359+
reference: "issue #57593 <https://github.com/rust-lang/rust/issues/57593>",
360+
edition: None,
361+
},
357362
]);
358363

359364
// Register renamed and removed lints.

src/libsyntax/early_buffered_lints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub enum BufferedEarlyLintId {
1212
/// Usage of `?` as a macro separator is deprecated.
1313
QuestionMarkMacroSep,
1414
IllFormedAttributeInput,
15+
/// Usage of a duplicate macro matcher binding name.
16+
DuplicateMacroMatcherBindingName,
1517
}
1618

1719
/// Stores buffered lint info which can later be passed to `librustc`.

src/libsyntax/ext/tt/macro_rules.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,12 @@ pub fn compile(
360360
// don't abort iteration early, so that errors for multiple lhses can be reported
361361
for lhs in &lhses {
362362
valid &= check_lhs_no_empty_seq(sess, &[lhs.clone()]);
363-
valid &=
364-
check_lhs_duplicate_matcher_bindings(sess, &[lhs.clone()], &mut FxHashMap::default());
363+
valid &= check_lhs_duplicate_matcher_bindings(
364+
sess,
365+
&[lhs.clone()],
366+
&mut FxHashMap::default(),
367+
def.id
368+
);
365369
}
366370

367371
let expander: Box<_> = Box::new(MacroRulesMacroExpander {
@@ -467,29 +471,38 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[quoted::TokenTree]) -> bool {
467471
fn check_lhs_duplicate_matcher_bindings(
468472
sess: &ParseSess,
469473
tts: &[quoted::TokenTree],
470-
metavar_names: &mut FxHashMap<Ident, Span>
474+
metavar_names: &mut FxHashMap<Ident, Span>,
475+
node_id: ast::NodeId,
471476
) -> bool {
472477
use self::quoted::TokenTree;
478+
use crate::early_buffered_lints::BufferedEarlyLintId;
473479
for tt in tts {
474480
match *tt {
475481
TokenTree::MetaVarDecl(span, name, _kind) => {
476482
if let Some(&prev_span) = metavar_names.get(&name) {
477-
sess.span_diagnostic
478-
.struct_span_err(span, "duplicate matcher binding")
479-
.span_note(prev_span, "previous declaration was here")
480-
.emit();
483+
// FIXME(mark-i-m): in a few cycles, make this a hard error.
484+
// sess.span_diagnostic
485+
// .struct_span_err(span, "duplicate matcher binding")
486+
// .span_note(prev_span, "previous declaration was here")
487+
// .emit();
488+
sess.buffer_lint(
489+
BufferedEarlyLintId::DuplicateMacroMatcherBindingName,
490+
crate::source_map::MultiSpan::from(vec![prev_span, span]),
491+
node_id,
492+
"duplicate matcher binding"
493+
);
481494
return false;
482495
} else {
483496
metavar_names.insert(name, span);
484497
}
485498
}
486499
TokenTree::Delimited(_, ref del) => {
487-
if !check_lhs_duplicate_matcher_bindings(sess, &del.tts, metavar_names) {
500+
if !check_lhs_duplicate_matcher_bindings(sess, &del.tts, metavar_names, node_id) {
488501
return false;
489502
}
490503
},
491504
TokenTree::Sequence(_, ref seq) => {
492-
if !check_lhs_duplicate_matcher_bindings(sess, &seq.tts, metavar_names) {
505+
if !check_lhs_duplicate_matcher_bindings(sess, &seq.tts, metavar_names, node_id) {
493506
return false;
494507
}
495508
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Test that duplicate matcher binding names are caught at declaration time, rather than at macro
22
// invocation time.
33

4+
#![allow(unused_macros)]
5+
46
macro_rules! foo1 {
5-
($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding
6-
($a:ident, $a:path) => {}; //~ERROR duplicate matcher binding
7+
($a:ident, $a:ident) => {}; //~WARN duplicate matcher binding
8+
($a:ident, $a:path) => {}; //~WARN duplicate matcher binding
79
}
810

911
macro_rules! foo2 {
@@ -12,8 +14,8 @@ macro_rules! foo2 {
1214
}
1315

1416
macro_rules! foo3 {
15-
($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding
16-
($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding
17+
($a:ident, $($a:ident),*) => {}; //~WARN duplicate matcher binding
18+
($($a:ident)+ # $($($a:path),+);*) => {}; //~WARN duplicate matcher binding
1719
}
1820

1921
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,37 @@
1-
error: duplicate matcher binding
2-
--> $DIR/macro-multiple-matcher-bindings.rs:5:16
3-
|
4-
LL | ($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding
5-
| ^^^^^^^^
6-
|
7-
note: previous declaration was here
8-
--> $DIR/macro-multiple-matcher-bindings.rs:5:6
9-
|
10-
LL | ($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding
11-
| ^^^^^^^^
1+
warning: duplicate matcher binding
2+
--> src/test/ui/macros/macro-multiple-matcher-bindings.rs:7:6
3+
|
4+
7 | ($a:ident, $a:ident) => {}; //~WARN duplicate matcher binding
5+
| ^^^^^^^^ ^^^^^^^^
6+
|
7+
= note: #[warn(duplicate_matcher_binding_name)] on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
1210

13-
error: duplicate matcher binding
14-
--> $DIR/macro-multiple-matcher-bindings.rs:6:16
15-
|
16-
LL | ($a:ident, $a:path) => {}; //~ERROR duplicate matcher binding
17-
| ^^^^^^^
18-
|
19-
note: previous declaration was here
20-
--> $DIR/macro-multiple-matcher-bindings.rs:6:6
21-
|
22-
LL | ($a:ident, $a:path) => {}; //~ERROR duplicate matcher binding
23-
| ^^^^^^^^
11+
warning: duplicate matcher binding
12+
--> src/test/ui/macros/macro-multiple-matcher-bindings.rs:8:6
13+
|
14+
8 | ($a:ident, $a:path) => {}; //~WARN duplicate matcher binding
15+
| ^^^^^^^^ ^^^^^^^
16+
|
17+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18+
= note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
2419

25-
error: duplicate matcher binding
26-
--> $DIR/macro-multiple-matcher-bindings.rs:15:18
27-
|
28-
LL | ($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding
29-
| ^^^^^^^^
20+
warning: duplicate matcher binding
21+
--> src/test/ui/macros/macro-multiple-matcher-bindings.rs:17:6
3022
|
31-
note: previous declaration was here
32-
--> $DIR/macro-multiple-matcher-bindings.rs:15:6
23+
LL | ($a:ident, $($a:ident),*) => {}; //~WARN duplicate matcher binding
24+
| ^^^^^^^^ ^^^^^^^^
3325
|
34-
LL | ($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding
35-
| ^^^^^^^^
26+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27+
= note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
3628

37-
error: duplicate matcher binding
38-
--> $DIR/macro-multiple-matcher-bindings.rs:16:25
29+
warning: duplicate matcher binding
30+
--> src/test/ui/macros/macro-multiple-matcher-bindings.rs:18:8
3931
|
40-
LL | ($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding
41-
| ^^^^^^^
32+
LL | ($($a:ident)+ # $($($a:path),+);*) => {}; //~WARN duplicate matcher binding
33+
| ^^^^^^^^ ^^^^^^^
4234
|
43-
note: previous declaration was here
44-
--> $DIR/macro-multiple-matcher-bindings.rs:16:8
45-
|
46-
LL | ($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding
47-
| ^^^^^^^^
48-
49-
error: aborting due to 4 previous errors
35+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
36+
= note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
5037

0 commit comments

Comments
 (0)