Skip to content

Commit 2461b31

Browse files
committedOct 1, 2013
incoporate suggestion from huonw to move code into lint.rs
1 parent 88d34ff commit 2461b31

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed
 

‎src/librustc/middle/check_match.rs

-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use middle::const_eval::{compare_const_vals, lookup_const_by_id};
1313
use middle::const_eval::{eval_const_expr, const_val, const_bool, const_float};
14-
use middle::lint::non_uppercase_pattern_statics;
1514
use middle::pat_util::*;
1615
use middle::ty::*;
1716
use middle::ty;
@@ -135,29 +134,11 @@ pub fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
135134
}
136135
};
137136

138-
// Lint for constants that look like binding identifiers (#7526)
139-
let pat_matches_non_uppercase_static: &fn(@Pat) = |p| {
140-
let msg = "static constant in pattern should be all caps";
141-
match (&p.node, cx.tcx.def_map.find(&p.id)) {
142-
(&PatIdent(_, ref path, _), Some(&DefStatic(_, false))) => {
143-
// last identifier alone is right choice for this lint.
144-
let ident = path.segments.last().identifier;
145-
let s = cx.tcx.sess.str_of(ident);
146-
if s.iter().any(|c| c.is_lowercase()) {
147-
cx.tcx.sess.add_lint(non_uppercase_pattern_statics,
148-
p.id, path.span, msg.to_owned());
149-
}
150-
}
151-
_ => {}
152-
}
153-
};
154-
155137
do walk_pat(*pat) |p| {
156138
if pat_matches_nan(p) {
157139
cx.tcx.sess.span_warn(p.span, "unmatchable NaN in pattern, \
158140
use the is_nan method in a guard instead");
159141
}
160-
pat_matches_non_uppercase_static(p);
161142
true
162143
};
163144

‎src/librustc/middle/lint.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,22 @@ fn check_item_non_uppercase_statics(cx: &Context, it: &ast::item) {
11181118
}
11191119
}
11201120

1121+
fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
1122+
// Lint for constants that look like binding identifiers (#7526)
1123+
match (&p.node, cx.tcx.def_map.find(&p.id)) {
1124+
(&ast::PatIdent(_, ref path, _), Some(&ast::DefStatic(_, false))) => {
1125+
// last identifier alone is right choice for this lint.
1126+
let ident = path.segments.last().identifier;
1127+
let s = cx.tcx.sess.str_of(ident);
1128+
if s.iter().any(|c| c.is_lowercase()) {
1129+
cx.span_lint(non_uppercase_pattern_statics, path.span,
1130+
"static constant in pattern should be all caps");
1131+
}
1132+
}
1133+
_ => {}
1134+
}
1135+
}
1136+
11211137
struct UnusedUnsafeLintVisitor { stopping_on_items: bool }
11221138

11231139
impl SubitemStoppableVisitor for UnusedUnsafeLintVisitor {
@@ -1524,6 +1540,11 @@ struct LintCheckVisitor;
15241540

15251541
impl Visitor<@mut Context> for LintCheckVisitor {
15261542

1543+
fn visit_pat(&mut self, p:@ast::Pat, cx: @mut Context) {
1544+
check_pat_non_uppercase_statics(cx, p);
1545+
visit::walk_pat(self, p, cx);
1546+
}
1547+
15271548
fn visit_item(&mut self, it:@ast::item, cx: @mut Context) {
15281549

15291550
do cx.with_lint_attrs(it.attrs) {

9 commit comments

Comments
 (9)

bors commented on Oct 2, 2013

@bors
Contributor

saw approval from alexcrichton
at pnkfelix@2461b31

bors commented on Oct 2, 2013

@bors
Contributor

merging pnkfelix/rust/fsk-issue7526-attempt-to-catch-nonuc-statics-in-match-patterns = 2461b31 into auto

bors commented on Oct 2, 2013

@bors
Contributor

pnkfelix/rust/fsk-issue7526-attempt-to-catch-nonuc-statics-in-match-patterns = 2461b31 merged ok, testing candidate = b7df2e0c

bors commented on Oct 2, 2013

@bors
Contributor

saw approval from alexcrichton
at pnkfelix@2461b31

bors commented on Oct 2, 2013

@bors
Contributor

merging pnkfelix/rust/fsk-issue7526-attempt-to-catch-nonuc-statics-in-match-patterns = 2461b31 into auto

bors commented on Oct 2, 2013

@bors
Contributor

pnkfelix/rust/fsk-issue7526-attempt-to-catch-nonuc-statics-in-match-patterns = 2461b31 merged ok, testing candidate = 97cd495

bors commented on Oct 2, 2013

@bors
Contributor

fast-forwarding master to auto = 97cd495

Please sign in to comment.