diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 4856bb6c7fc09e866338e978e02ea7d46da3eb69..c891e57ff39aaf3da4ed3f0134e2cd8a0d14b5ea 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 6f022aa31bd7170896715470c31af0a9b8276d34..b3d595c6efb7224904476ba31ead02cd38c1cf23 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 @@ fn lint_stability() -> @mut OuterLint { 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) {