about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/middle/check_match.rs19
-rw-r--r--src/librustc/middle/lint.rs21
2 files changed, 21 insertions, 19 deletions
diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs
index 4856bb6c7fc..c891e57ff39 100644
--- a/src/librustc/middle/check_match.rs
+++ b/src/librustc/middle/check_match.rs
@@ -11,7 +11,6 @@
 
 use middle::const_eval::{compare_const_vals, lookup_const_by_id};
 use middle::const_eval::{eval_const_expr, const_val, const_bool, const_float};
-use middle::lint::non_uppercase_pattern_statics;
 use middle::pat_util::*;
 use middle::ty::*;
 use middle::ty;
@@ -135,29 +134,11 @@ pub fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
                 }
             };
 
-            // Lint for constants that look like binding identifiers (#7526)
-            let pat_matches_non_uppercase_static: &fn(@Pat) = |p| {
-                let msg = "static constant in pattern should be all caps";
-                match (&p.node, cx.tcx.def_map.find(&p.id)) {
-                    (&PatIdent(_, ref path, _), Some(&DefStatic(_, false))) => {
-                        // last identifier alone is right choice for this lint.
-                        let ident = path.segments.last().identifier;
-                        let s = cx.tcx.sess.str_of(ident);
-                        if s.iter().any(|c| c.is_lowercase()) {
-                            cx.tcx.sess.add_lint(non_uppercase_pattern_statics,
-                                                 p.id, path.span, msg.to_owned());
-                        }
-                    }
-                    _ => {}
-                }
-            };
-
             do walk_pat(*pat) |p| {
                 if pat_matches_nan(p) {
                     cx.tcx.sess.span_warn(p.span, "unmatchable NaN in pattern, \
                                                    use the is_nan method in a guard instead");
                 }
-                pat_matches_non_uppercase_static(p);
                 true
             };
 
diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs
index 6f022aa31bd..b3d595c6efb 100644
--- a/src/librustc/middle/lint.rs
+++ b/src/librustc/middle/lint.rs
@@ -1118,6 +1118,22 @@ fn check_item_non_uppercase_statics(cx: &Context, it: &ast::item) {
     }
 }
 
+fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
+    // Lint for constants that look like binding identifiers (#7526)
+    match (&p.node, cx.tcx.def_map.find(&p.id)) {
+        (&ast::PatIdent(_, ref path, _), Some(&ast::DefStatic(_, false))) => {
+            // last identifier alone is right choice for this lint.
+            let ident = path.segments.last().identifier;
+            let s = cx.tcx.sess.str_of(ident);
+            if s.iter().any(|c| c.is_lowercase()) {
+                cx.span_lint(non_uppercase_pattern_statics, path.span,
+                             "static constant in pattern should be all caps");
+            }
+        }
+        _ => {}
+    }
+}
+
 struct UnusedUnsafeLintVisitor { stopping_on_items: bool }
 
 impl SubitemStoppableVisitor for UnusedUnsafeLintVisitor {
@@ -1524,6 +1540,11 @@ struct LintCheckVisitor;
 
 impl Visitor<@mut Context> for LintCheckVisitor {
 
+    fn visit_pat(&mut self, p:@ast::Pat, cx: @mut Context) {
+        check_pat_non_uppercase_statics(cx, p);
+        visit::walk_pat(self, p, cx);
+    }
+
     fn visit_item(&mut self, it:@ast::item, cx: @mut Context) {
 
                 do cx.with_lint_attrs(it.attrs) {