@@ -127,14 +127,20 @@ impl NonCamelCaseTypes {
127127 if !is_camel_case ( name) {
128128 cx. struct_span_lint ( NON_CAMEL_CASE_TYPES , ident. span , |lint| {
129129 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 (
132136 ident. span ,
133137 "convert the identifier to upper camel case" ,
134138 to_camel_case ( name) ,
135139 Applicability :: MaybeIncorrect ,
136- )
137- . emit ( )
140+ ) ;
141+ }
142+
143+ err. emit ( ) ;
138144 } )
139145 }
140146 }
@@ -263,17 +269,21 @@ impl NonSnakeCase {
263269 let sc = NonSnakeCase :: to_snake_case ( name) ;
264270 let msg = format ! ( "{} `{}` should have a snake case name" , sort, name) ;
265271 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+ }
277287 }
278288
279289 err. emit ( ) ;
@@ -441,14 +451,20 @@ impl NonUpperCaseGlobals {
441451 if name. chars ( ) . any ( |c| c. is_lowercase ( ) ) {
442452 cx. struct_span_lint ( NON_UPPER_CASE_GLOBALS , ident. span , |lint| {
443453 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 (
446460 ident. span ,
447461 "convert the identifier to upper case" ,
448462 uc,
449463 Applicability :: MaybeIncorrect ,
450- )
451- . emit ( ) ;
464+ ) ;
465+ }
466+
467+ err. emit ( ) ;
452468 } )
453469 }
454470 }
0 commit comments