@@ -83,6 +83,7 @@ pub enum lint {
83
83
unrecognized_lint,
84
84
non_camel_case_types,
85
85
non_uppercase_statics,
86
+ non_uppercase_pattern_statics,
86
87
type_limits,
87
88
unused_unsafe,
88
89
@@ -209,6 +210,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
209
210
default : allow
210
211
} ) ,
211
212
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
+
212
220
( "managed_heap_memory" ,
213
221
LintSpec {
214
222
lint : managed_heap_memory,
@@ -1110,6 +1118,22 @@ fn check_item_non_uppercase_statics(cx: &Context, it: &ast::item) {
1110
1118
}
1111
1119
}
1112
1120
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
+
1113
1137
struct UnusedUnsafeLintVisitor { stopping_on_items : bool }
1114
1138
1115
1139
impl SubitemStoppableVisitor for UnusedUnsafeLintVisitor {
@@ -1516,6 +1540,11 @@ struct LintCheckVisitor;
1516
1540
1517
1541
impl Visitor < @mut Context > for LintCheckVisitor {
1518
1542
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
+
1519
1548
fn visit_item ( & mut self , it : @ast:: item , cx : @mut Context ) {
1520
1549
1521
1550
do cx. with_lint_attrs ( it. attrs ) {
0 commit comments