@@ -127,14 +127,20 @@ impl NonCamelCaseTypes {
127
127
if !is_camel_case ( name) {
128
128
cx. struct_span_lint ( NON_CAMEL_CASE_TYPES , ident. span , |lint| {
129
129
let msg = format ! ( "{} `{}` should have an upper camel case name" , sort, name) ;
130
- lint. build ( & msg)
131
- . span_suggestion (
130
+ let mut err = lint. build ( & msg) ;
131
+ let cc = to_camel_case ( name) ;
132
+ // We cannot provide meaningful suggestions
133
+ // if the characters are in the category of "Lowercase Letter".
134
+ if name. to_string ( ) != cc {
135
+ err. span_suggestion (
132
136
ident. span ,
133
137
"convert the identifier to upper camel case" ,
134
138
to_camel_case ( name) ,
135
139
Applicability :: MaybeIncorrect ,
136
- )
137
- . emit ( )
140
+ ) ;
141
+ }
142
+
143
+ err. emit ( ) ;
138
144
} )
139
145
}
140
146
}
@@ -263,17 +269,21 @@ impl NonSnakeCase {
263
269
let sc = NonSnakeCase :: to_snake_case ( name) ;
264
270
let msg = format ! ( "{} `{}` should have a snake case name" , sort, name) ;
265
271
let mut err = lint. build ( & msg) ;
266
- // We have a valid span in almost all cases, but we don't have one when linting a crate
267
- // name provided via the command line.
268
- if !ident. span . is_dummy ( ) {
269
- err. span_suggestion (
270
- ident. span ,
271
- "convert the identifier to snake case" ,
272
- sc,
273
- Applicability :: MaybeIncorrect ,
274
- ) ;
275
- } else {
276
- err. help ( & format ! ( "convert the identifier to snake case: `{}`" , sc) ) ;
272
+ // We cannot provide meaningful suggestions
273
+ // if the characters are in the category of "Uppercase Letter".
274
+ if name. to_string ( ) != sc {
275
+ // We have a valid span in almost all cases, but we don't have one when linting a crate
276
+ // name provided via the command line.
277
+ if !ident. span . is_dummy ( ) {
278
+ err. span_suggestion (
279
+ ident. span ,
280
+ "convert the identifier to snake case" ,
281
+ sc,
282
+ Applicability :: MaybeIncorrect ,
283
+ ) ;
284
+ } else {
285
+ err. help ( & format ! ( "convert the identifier to snake case: `{}`" , sc) ) ;
286
+ }
277
287
}
278
288
279
289
err. emit ( ) ;
@@ -441,14 +451,20 @@ impl NonUpperCaseGlobals {
441
451
if name. chars ( ) . any ( |c| c. is_lowercase ( ) ) {
442
452
cx. struct_span_lint ( NON_UPPER_CASE_GLOBALS , ident. span , |lint| {
443
453
let uc = NonSnakeCase :: to_snake_case ( & name) . to_uppercase ( ) ;
444
- lint. build ( & format ! ( "{} `{}` should have an upper case name" , sort, name) )
445
- . span_suggestion (
454
+ let mut err =
455
+ lint. build ( & format ! ( "{} `{}` should have an upper case name" , sort, name) ) ;
456
+ // We cannot provide meaningful suggestions
457
+ // if the characters are in the category of "Lowercase Letter".
458
+ if name. to_string ( ) != uc {
459
+ err. span_suggestion (
446
460
ident. span ,
447
461
"convert the identifier to upper case" ,
448
462
uc,
449
463
Applicability :: MaybeIncorrect ,
450
- )
451
- . emit ( ) ;
464
+ ) ;
465
+ }
466
+
467
+ err. emit ( ) ;
452
468
} )
453
469
}
454
470
}
0 commit comments