@@ -80,6 +80,7 @@ pub enum Lint {
80
80
NonCamelCaseTypes ,
81
81
NonUppercaseStatics ,
82
82
NonUppercasePatternStatics ,
83
+ UppercaseVariables ,
83
84
UnnecessaryParens ,
84
85
TypeLimits ,
85
86
TypeOverflow ,
@@ -208,7 +209,14 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
208
209
default : warn
209
210
} ) ,
210
211
211
- ( "unnecessary_parens" ,
212
+ ( "uppercase_variables" ,
213
+ LintSpec {
214
+ lint : UppercaseVariables ,
215
+ desc : "variable names should start with a lowercase character" ,
216
+ default : warn
217
+ } ) ,
218
+
219
+ ( "unnecessary_parens" ,
212
220
LintSpec {
213
221
lint : UnnecessaryParens ,
214
222
desc : "`if`, `match`, `while` and `return` do not need parentheses" ,
@@ -1169,6 +1177,30 @@ fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
1169
1177
}
1170
1178
}
1171
1179
1180
+ fn check_pat_uppercase_variable ( cx : & Context , p : & ast:: Pat ) {
1181
+ let def_map = cx. tcx . def_map . borrow ( ) ;
1182
+ match & p. node {
1183
+ & ast:: PatIdent ( _, ref path, _) => {
1184
+ match def_map. get ( ) . find ( & p. id ) {
1185
+ Some ( & ast:: DefLocal ( _, _) ) | Some ( & ast:: DefBinding ( _, _) ) |
1186
+ Some ( & ast:: DefArg ( _, _) ) => {
1187
+ // last identifier alone is right choice for this lint.
1188
+ let ident = path. segments . last ( ) . unwrap ( ) . identifier ;
1189
+ let s = token:: get_ident ( ident) ;
1190
+ if s. get ( ) . char_at ( 0 ) . is_uppercase ( ) {
1191
+ cx. span_lint (
1192
+ UppercaseVariables ,
1193
+ path. span ,
1194
+ "variable names should start with a lowercase character" ) ;
1195
+ }
1196
+ }
1197
+ _ => { }
1198
+ }
1199
+ }
1200
+ _ => { }
1201
+ }
1202
+ }
1203
+
1172
1204
fn check_unnecessary_parens_core ( cx : & Context , value : & ast:: Expr , msg : & str ) {
1173
1205
match value. node {
1174
1206
ast:: ExprParen ( _) => {
@@ -1553,6 +1585,7 @@ impl<'a> Visitor<()> for Context<'a> {
1553
1585
1554
1586
fn visit_pat ( & mut self , p : & ast:: Pat , _: ( ) ) {
1555
1587
check_pat_non_uppercase_statics ( self , p) ;
1588
+ check_pat_uppercase_variable ( self , p) ;
1556
1589
check_unused_mut_pat ( self , p) ;
1557
1590
1558
1591
visit:: walk_pat ( self , p, ( ) ) ;
0 commit comments