about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorMark Mansi <markm@cs.wisc.edu>2019-01-17 21:19:56 -0600
committerMark Mansi <markm@cs.wisc.edu>2019-02-07 12:17:27 -0600
commit802b256283fe7dd0f0e72499ba77d18f2838e817 (patch)
tree49b71583eaf41d89e97fc4b9b90dd91c8d6d9754 /src/libsyntax/ext
parent3e790a7c304b3bcb182c4fcb745ea288d3dc56f2 (diff)
Make it an incompatibility lint for now
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index 61a5b2cb0d2..33ea675f9d1 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -360,8 +360,12 @@ pub fn compile(
     // don't abort iteration early, so that errors for multiple lhses can be reported
     for lhs in &lhses {
         valid &= check_lhs_no_empty_seq(sess, &[lhs.clone()]);
-        valid &=
-            check_lhs_duplicate_matcher_bindings(sess, &[lhs.clone()], &mut FxHashMap::default());
+        valid &= check_lhs_duplicate_matcher_bindings(
+            sess,
+            &[lhs.clone()],
+            &mut FxHashMap::default(),
+            def.id
+        );
     }
 
     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(
     sess: &ParseSess,
     tts: &[quoted::TokenTree],
-    metavar_names: &mut FxHashMap<Ident, Span>
+    metavar_names: &mut FxHashMap<Ident, Span>,
+    node_id: ast::NodeId,
 ) -> bool {
     use self::quoted::TokenTree;
+    use crate::early_buffered_lints::BufferedEarlyLintId;
     for tt in tts {
         match *tt {
             TokenTree::MetaVarDecl(span, name, _kind) => {
                 if let Some(&prev_span) = metavar_names.get(&name) {
-                    sess.span_diagnostic
-                        .struct_span_err(span, "duplicate matcher binding")
-                        .span_note(prev_span, "previous declaration was here")
-                        .emit();
+                    // FIXME(mark-i-m): in a few cycles, make this a hard error.
+                    // sess.span_diagnostic
+                    //     .struct_span_err(span, "duplicate matcher binding")
+                    //     .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;
                 } else {
                     metavar_names.insert(name, span);
                 }
             }
             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;
                 }
             },
             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;
                 }
             }