@@ -83,6 +83,7 @@ pub enum lint {
8383 unrecognized_lint,
8484 non_camel_case_types,
8585 non_uppercase_statics,
86+ non_uppercase_pattern_statics,
8687 type_limits,
8788 unused_unsafe,
8889
@@ -209,6 +210,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
209210 default : allow
210211 } ) ,
211212
213+ ( "non_uppercase_pattern_statics" ,
214+ LintSpec {
215+ lint : non_uppercase_pattern_statics,
216+ desc : "static constants in match patterns should be all caps" ,
217+ default : warn
218+ } ) ,
219+
212220 ( "managed_heap_memory" ,
213221 LintSpec {
214222 lint : managed_heap_memory,
@@ -1110,6 +1118,22 @@ fn check_item_non_uppercase_statics(cx: &Context, it: &ast::item) {
11101118 }
11111119}
11121120
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+
11131137struct UnusedUnsafeLintVisitor { stopping_on_items : bool }
11141138
11151139impl SubitemStoppableVisitor for UnusedUnsafeLintVisitor {
@@ -1516,6 +1540,11 @@ struct LintCheckVisitor;
15161540
15171541impl Visitor < @mut Context > for LintCheckVisitor {
15181542
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+
15191548 fn visit_item ( & mut self , it : @ast:: item , cx : @mut Context ) {
15201549
15211550 do cx. with_lint_attrs ( it. attrs ) {
0 commit comments