提交 2461b310 编写于 作者: F Felix S. Klock II

incoporate suggestion from huonw to move code into lint.rs

上级 88d34ff2
......@@ -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
};
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册