Skip to content

Commit 1ccd4cd

Browse files
authored
Rollup merge of rust-lang#59858 - mark-i-m:dup-matcher-bindings-3, r=Centril
Make duplicate matcher bindings a hard error r? @Centril Closes rust-lang#57742
2 parents 6218a44 + e149dc0 commit 1ccd4cd

File tree

7 files changed

+44
-61
lines changed

7 files changed

+44
-61
lines changed

src/librustc/lint/builtin.rs

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

355-
declare_lint! {
356-
pub DUPLICATE_MATCHER_BINDING_NAME,
357-
Deny,
358-
"duplicate macro matcher binding name"
359-
}
360-
361355
/// Some lints that are buffered from `libsyntax`. See `syntax::early_buffered_lints`.
362356
pub mod parser {
363357
declare_lint! {
@@ -462,7 +456,6 @@ declare_lint_pass! {
462456
DEPRECATED_IN_FUTURE,
463457
AMBIGUOUS_ASSOCIATED_ITEMS,
464458
NESTED_IMPL_TRAIT,
465-
DUPLICATE_MATCHER_BINDING_NAME,
466459
MUTABLE_BORROW_RESERVATION_CONFLICT,
467460
]
468461
}

src/librustc/lint/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_data_structures::sync::{self, Lrc};
2626
use crate::hir::def_id::{CrateNum, LOCAL_CRATE};
2727
use crate::hir::intravisit;
2828
use crate::hir;
29-
use crate::lint::builtin::{BuiltinLintDiagnostics, DUPLICATE_MATCHER_BINDING_NAME};
29+
use crate::lint::builtin::BuiltinLintDiagnostics;
3030
use crate::lint::builtin::parser::{QUESTION_MARK_MACRO_SEP, ILL_FORMED_ATTRIBUTE_INPUT};
3131
use crate::session::{Session, DiagnosticMessageId};
3232
use crate::ty::TyCtxt;
@@ -82,7 +82,6 @@ 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,
8685
}
8786
}
8887

src/librustc_lint/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
428428
reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
429429
edition: None,
430430
},
431-
FutureIncompatibleInfo {
432-
id: LintId::of(DUPLICATE_MATCHER_BINDING_NAME),
433-
reference: "issue #57593 <https://github.com/rust-lang/rust/issues/57593>",
434-
edition: None,
435-
},
436431
FutureIncompatibleInfo {
437432
id: LintId::of(NESTED_IMPL_TRAIT),
438433
reference: "issue #59014 <https://github.com/rust-lang/rust/issues/59014>",
@@ -494,6 +489,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
494489
"no longer a warning, #[no_mangle] statics always exported");
495490
store.register_removed("bad_repr",
496491
"replaced with a generic attribute input check");
492+
store.register_removed("duplicate_matcher_binding_name",
493+
"converted into hard error, see https://github.com/rust-lang/rust/issues/57742");
497494
}
498495

499496
pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) {

src/libsyntax/early_buffered_lints.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ 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,
1715
}
1816

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

src/libsyntax/ext/tt/macro_rules.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -497,22 +497,14 @@ fn check_lhs_duplicate_matcher_bindings(
497497
node_id: ast::NodeId,
498498
) -> bool {
499499
use self::quoted::TokenTree;
500-
use crate::early_buffered_lints::BufferedEarlyLintId;
501500
for tt in tts {
502501
match *tt {
503502
TokenTree::MetaVarDecl(span, name, _kind) => {
504503
if let Some(&prev_span) = metavar_names.get(&name) {
505-
// FIXME(mark-i-m): in a few cycles, make this a hard error.
506-
// sess.span_diagnostic
507-
// .struct_span_err(span, "duplicate matcher binding")
508-
// .span_note(prev_span, "previous declaration was here")
509-
// .emit();
510-
sess.buffer_lint(
511-
BufferedEarlyLintId::DuplicateMacroMatcherBindingName,
512-
crate::source_map::MultiSpan::from(vec![prev_span, span]),
513-
node_id,
514-
"duplicate matcher binding"
515-
);
504+
sess.span_diagnostic
505+
.struct_span_err(span, "duplicate matcher binding")
506+
.span_note(prev_span, "previous declaration was here")
507+
.emit();
516508
return false;
517509
} else {
518510
metavar_names.insert(name, span);
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
// Test that duplicate matcher binding names are caught at declaration time, rather than at macro
22
// invocation time.
3-
//
4-
// FIXME(mark-i-m): Update this when it becomes a hard error.
5-
6-
// compile-pass
73

84
#![allow(unused_macros)]
9-
#![warn(duplicate_matcher_binding_name)]
105

116
macro_rules! foo1 {
12-
($a:ident, $a:ident) => {}; //~WARNING duplicate matcher binding
13-
($a:ident, $a:path) => {}; //~WARNING duplicate matcher binding
7+
($a:ident, $a:ident) => {}; //~ERROR duplicate matcher binding
8+
($a:ident, $a:path) => {}; //~ERROR duplicate matcher binding
149
}
1510

1611
macro_rules! foo2 {
@@ -19,8 +14,8 @@ macro_rules! foo2 {
1914
}
2015

2116
macro_rules! foo3 {
22-
($a:ident, $($a:ident),*) => {}; //~WARNING duplicate matcher binding
23-
($($a:ident)+ # $($($a:path),+);*) => {}; //~WARNING duplicate matcher binding
17+
($a:ident, $($a:ident),*) => {}; //~ERROR duplicate matcher binding
18+
($($a:ident)+ # $($($a:path),+);*) => {}; //~ERROR duplicate matcher binding
2419
}
2520

2621
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,50 @@
1-
warning: duplicate matcher binding
2-
--> $DIR/macro-multiple-matcher-bindings.rs:12:6
1+
error: duplicate matcher binding
2+
--> $DIR/macro-multiple-matcher-bindings.rs:7:16
33
|
44
LL | ($a:ident, $a:ident) => {};
5-
| ^^^^^^^^ ^^^^^^^^
5+
| ^^^^^^^^
66
|
7-
note: lint level defined here
8-
--> $DIR/macro-multiple-matcher-bindings.rs:9:9
7+
note: previous declaration was here
8+
--> $DIR/macro-multiple-matcher-bindings.rs:7:6
99
|
10-
LL | #![warn(duplicate_matcher_binding_name)]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
13-
= note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
10+
LL | ($a:ident, $a:ident) => {};
11+
| ^^^^^^^^
1412

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

24-
warning: duplicate matcher binding
25-
--> $DIR/macro-multiple-matcher-bindings.rs:22:6
25+
error: duplicate matcher binding
26+
--> $DIR/macro-multiple-matcher-bindings.rs:17:18
2627
|
2728
LL | ($a:ident, $($a:ident),*) => {};
28-
| ^^^^^^^^ ^^^^^^^^
29+
| ^^^^^^^^
30+
|
31+
note: previous declaration was here
32+
--> $DIR/macro-multiple-matcher-bindings.rs:17:6
2933
|
30-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31-
= note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
34+
LL | ($a:ident, $($a:ident),*) => {};
35+
| ^^^^^^^^
3236

33-
warning: duplicate matcher binding
34-
--> $DIR/macro-multiple-matcher-bindings.rs:23:8
37+
error: duplicate matcher binding
38+
--> $DIR/macro-multiple-matcher-bindings.rs:18:25
3539
|
3640
LL | ($($a:ident)+ # $($($a:path),+);*) => {};
37-
| ^^^^^^^^ ^^^^^^^
41+
| ^^^^^^^
42+
|
43+
note: previous declaration was here
44+
--> $DIR/macro-multiple-matcher-bindings.rs:18:8
3845
|
39-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
40-
= note: for more information, see issue #57593 <https://github.com/rust-lang/rust/issues/57593>
46+
LL | ($($a:ident)+ # $($($a:path),+);*) => {};
47+
| ^^^^^^^^
48+
49+
error: aborting due to 4 previous errors
4150

0 commit comments

Comments
 (0)