@@ -53,17 +53,17 @@ declare_lint! {
53
53
pub struct NonCamelCaseTypes ;
54
54
55
55
impl NonCamelCaseTypes {
56
- fn check_case ( & self , cx : & LateContext , sort : & str , ident : ast:: Ident , span : Span ) {
57
- fn is_camel_case ( ident : ast:: Ident ) -> bool {
58
- let ident = ident . name . as_str ( ) ;
59
- if ident . is_empty ( ) {
56
+ fn check_case ( & self , cx : & LateContext , sort : & str , name : ast:: Name , span : Span ) {
57
+ fn is_camel_case ( name : ast:: Name ) -> bool {
58
+ let name = name. as_str ( ) ;
59
+ if name . is_empty ( ) {
60
60
return true ;
61
61
}
62
- let ident = ident . trim_matches ( '_' ) ;
62
+ let name = name . trim_matches ( '_' ) ;
63
63
64
64
// start with a non-lowercase letter rather than non-uppercase
65
65
// ones (some scripts don't have a concept of upper/lowercase)
66
- !ident . is_empty ( ) && !ident . char_at ( 0 ) . is_lowercase ( ) && !ident . contains ( '_' )
66
+ !name . is_empty ( ) && !name . char_at ( 0 ) . is_lowercase ( ) && !name . contains ( '_' )
67
67
}
68
68
69
69
fn to_camel_case ( s : & str ) -> String {
@@ -76,9 +76,9 @@ impl NonCamelCaseTypes {
76
76
) ) . collect :: < Vec < _ > > ( ) . concat ( )
77
77
}
78
78
79
- let s = ident . name . as_str ( ) ;
79
+ let s = name. as_str ( ) ;
80
80
81
- if !is_camel_case ( ident ) {
81
+ if !is_camel_case ( name ) {
82
82
let c = to_camel_case ( & s) ;
83
83
let m = if c. is_empty ( ) {
84
84
format ! ( "{} `{}` should have a camel case name such as `CamelCase`" , sort, s)
@@ -110,16 +110,16 @@ impl LateLintPass for NonCamelCaseTypes {
110
110
111
111
match it. node {
112
112
hir:: ItemTy ( ..) | hir:: ItemStruct ( ..) => {
113
- self . check_case ( cx, "type" , it. ident , it. span )
113
+ self . check_case ( cx, "type" , it. name , it. span )
114
114
}
115
115
hir:: ItemTrait ( ..) => {
116
- self . check_case ( cx, "trait" , it. ident , it. span )
116
+ self . check_case ( cx, "trait" , it. name , it. span )
117
117
}
118
118
hir:: ItemEnum ( ref enum_definition, _) => {
119
119
if has_extern_repr {
120
120
return ;
121
121
}
122
- self . check_case ( cx, "type" , it. ident , it. span ) ;
122
+ self . check_case ( cx, "type" , it. name , it. span ) ;
123
123
for variant in & enum_definition. variants {
124
124
self . check_case ( cx, "variant" , variant. node . name , variant. span ) ;
125
125
}
@@ -130,7 +130,7 @@ impl LateLintPass for NonCamelCaseTypes {
130
130
131
131
fn check_generics ( & mut self , cx : & LateContext , it : & hir:: Generics ) {
132
132
for gen in it. ty_params . iter ( ) {
133
- self . check_case ( cx, "type parameter" , gen. ident , gen. span ) ;
133
+ self . check_case ( cx, "type parameter" , gen. name , gen. span ) ;
134
134
}
135
135
}
136
136
}
@@ -237,31 +237,31 @@ impl LateLintPass for NonSnakeCase {
237
237
fk : FnKind , _: & hir:: FnDecl ,
238
238
_: & hir:: Block , span : Span , id : ast:: NodeId ) {
239
239
match fk {
240
- FnKind :: Method ( ident , _, _) => match method_context ( cx, id, span) {
240
+ FnKind :: Method ( name , _, _) => match method_context ( cx, id, span) {
241
241
MethodLateContext :: PlainImpl => {
242
- self . check_snake_case ( cx, "method" , & ident . name . as_str ( ) , Some ( span) )
242
+ self . check_snake_case ( cx, "method" , & name. as_str ( ) , Some ( span) )
243
243
} ,
244
244
MethodLateContext :: TraitDefaultImpl => {
245
- self . check_snake_case ( cx, "trait method" , & ident . name . as_str ( ) , Some ( span) )
245
+ self . check_snake_case ( cx, "trait method" , & name. as_str ( ) , Some ( span) )
246
246
} ,
247
247
_ => ( ) ,
248
248
} ,
249
- FnKind :: ItemFn ( ident , _, _, _, _, _) => {
250
- self . check_snake_case ( cx, "function" , & ident . name . as_str ( ) , Some ( span) )
249
+ FnKind :: ItemFn ( name , _, _, _, _, _) => {
250
+ self . check_snake_case ( cx, "function" , & name. as_str ( ) , Some ( span) )
251
251
} ,
252
252
_ => ( ) ,
253
253
}
254
254
}
255
255
256
256
fn check_item ( & mut self , cx : & LateContext , it : & hir:: Item ) {
257
257
if let hir:: ItemMod ( _) = it. node {
258
- self . check_snake_case ( cx, "module" , & it. ident . name . as_str ( ) , Some ( it. span ) ) ;
258
+ self . check_snake_case ( cx, "module" , & it. name . as_str ( ) , Some ( it. span ) ) ;
259
259
}
260
260
}
261
261
262
262
fn check_trait_item ( & mut self , cx : & LateContext , trait_item : & hir:: TraitItem ) {
263
263
if let hir:: MethodTraitItem ( _, None ) = trait_item. node {
264
- self . check_snake_case ( cx, "trait method" , & trait_item. ident . name . as_str ( ) ,
264
+ self . check_snake_case ( cx, "trait method" , & trait_item. name . as_str ( ) ,
265
265
Some ( trait_item. span ) ) ;
266
266
}
267
267
}
@@ -281,10 +281,10 @@ impl LateLintPass for NonSnakeCase {
281
281
}
282
282
283
283
fn check_struct_def ( & mut self , cx : & LateContext , s : & hir:: StructDef ,
284
- _: ast:: Ident , _: & hir:: Generics , _: ast:: NodeId ) {
284
+ _: ast:: Name , _: & hir:: Generics , _: ast:: NodeId ) {
285
285
for sf in & s. fields {
286
- if let hir:: StructField_ { kind : hir:: NamedField ( ident , _) , .. } = sf. node {
287
- self . check_snake_case ( cx, "structure field" , & ident . name . as_str ( ) ,
286
+ if let hir:: StructField_ { kind : hir:: NamedField ( name , _) , .. } = sf. node {
287
+ self . check_snake_case ( cx, "structure field" , & name. as_str ( ) ,
288
288
Some ( sf. span ) ) ;
289
289
}
290
290
}
@@ -301,8 +301,8 @@ declare_lint! {
301
301
pub struct NonUpperCaseGlobals ;
302
302
303
303
impl NonUpperCaseGlobals {
304
- fn check_upper_case ( cx : & LateContext , sort : & str , ident : ast:: Ident , span : Span ) {
305
- let s = ident . name . as_str ( ) ;
304
+ fn check_upper_case ( cx : & LateContext , sort : & str , name : ast:: Name , span : Span ) {
305
+ let s = name. as_str ( ) ;
306
306
307
307
if s. chars ( ) . any ( |c| c. is_lowercase ( ) ) {
308
308
let uc = NonSnakeCase :: to_snake_case ( & s) . to_uppercase ( ) ;
@@ -330,10 +330,10 @@ impl LateLintPass for NonUpperCaseGlobals {
330
330
match it. node {
331
331
// only check static constants
332
332
hir:: ItemStatic ( _, hir:: MutImmutable , _) => {
333
- NonUpperCaseGlobals :: check_upper_case ( cx, "static constant" , it. ident , it. span ) ;
333
+ NonUpperCaseGlobals :: check_upper_case ( cx, "static constant" , it. name , it. span ) ;
334
334
}
335
335
hir:: ItemConst ( ..) => {
336
- NonUpperCaseGlobals :: check_upper_case ( cx, "constant" , it. ident , it. span ) ;
336
+ NonUpperCaseGlobals :: check_upper_case ( cx, "constant" , it. name , it. span ) ;
337
337
}
338
338
_ => { }
339
339
}
@@ -343,7 +343,7 @@ impl LateLintPass for NonUpperCaseGlobals {
343
343
match ti. node {
344
344
hir:: ConstTraitItem ( ..) => {
345
345
NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" ,
346
- ti. ident , ti. span ) ;
346
+ ti. name , ti. span ) ;
347
347
}
348
348
_ => { }
349
349
}
@@ -353,7 +353,7 @@ impl LateLintPass for NonUpperCaseGlobals {
353
353
match ii. node {
354
354
hir:: ConstImplItem ( ..) => {
355
355
NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" ,
356
- ii. ident , ii. span ) ;
356
+ ii. name , ii. span ) ;
357
357
}
358
358
_ => { }
359
359
}
@@ -364,7 +364,7 @@ impl LateLintPass for NonUpperCaseGlobals {
364
364
match ( & p. node , cx. tcx . def_map . borrow ( ) . get ( & p. id ) . map ( |d| d. full_def ( ) ) ) {
365
365
( & hir:: PatIdent ( _, ref path1, _) , Some ( def:: DefConst ( ..) ) ) => {
366
366
NonUpperCaseGlobals :: check_upper_case ( cx, "constant in pattern" ,
367
- path1. node , p. span ) ;
367
+ path1. node . name , p. span ) ;
368
368
}
369
369
_ => { }
370
370
}
0 commit comments