@@ -356,21 +356,21 @@ declare_lint! {
356356pub struct NonUpperCaseGlobals ;
357357
358358impl NonUpperCaseGlobals {
359- fn check_upper_case ( cx : & LateContext , sort : & str , name : ast :: Name , span : Span ) {
360- if name. as_str ( ) . chars ( ) . any ( |c| c . is_lowercase ( ) ) {
361- let uc = NonSnakeCase :: to_snake_case ( & name . as_str ( ) ) . to_uppercase ( ) ;
362- if name != & * uc {
363- cx . span_lint ( NON_UPPER_CASE_GLOBALS ,
364- span ,
365- & format ! ( "{} `{}` should have an upper case name such as `{}`" ,
366- sort ,
367- name ,
368- uc ) ) ;
369- } else {
370- cx . span_lint ( NON_UPPER_CASE_GLOBALS ,
371- span ,
372- & format ! ( "{} `{}` should have an upper case name" , sort , name ) ) ;
373- }
359+ fn check_upper_case ( cx : & LateContext , sort : & str , ident : & Ident ) {
360+ let name = & ident . name . as_str ( ) ;
361+
362+ if name. chars ( ) . any ( |c| c . is_lowercase ( ) ) {
363+ let uc = NonSnakeCase :: to_snake_case ( & name ) . to_uppercase ( ) ;
364+
365+ let msg = format ! ( "{} `{}` should have an upper case name" , sort , name ) ;
366+ cx . struct_span_lint ( NON_UPPER_CASE_GLOBALS , ident . span , & msg )
367+ . span_suggestion_with_applicability (
368+ ident . span ,
369+ "convert the identifier to upper case" ,
370+ uc ,
371+ Applicability :: MaybeIncorrect ,
372+ )
373+ . emit ( ) ;
374374 }
375375 }
376376}
@@ -384,38 +384,25 @@ impl LintPass for NonUpperCaseGlobals {
384384impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for NonUpperCaseGlobals {
385385 fn check_item ( & mut self , cx : & LateContext , it : & hir:: Item ) {
386386 match it. node {
387- hir:: ItemKind :: Static ( ..) => {
388- if attr:: find_by_name ( & it. attrs , "no_mangle" ) . is_some ( ) {
389- return ;
390- }
391- NonUpperCaseGlobals :: check_upper_case ( cx, "static variable" , it. ident . name ,
392- it. span ) ;
387+ hir:: ItemKind :: Static ( ..) if !attr:: contains_name ( & it. attrs , "no_mangle" ) => {
388+ NonUpperCaseGlobals :: check_upper_case ( cx, "static variable" , & it. ident ) ;
393389 }
394390 hir:: ItemKind :: Const ( ..) => {
395- NonUpperCaseGlobals :: check_upper_case ( cx, "constant" , it. ident . name ,
396- it. span ) ;
391+ NonUpperCaseGlobals :: check_upper_case ( cx, "constant" , & it. ident ) ;
397392 }
398393 _ => { }
399394 }
400395 }
401396
402397 fn check_trait_item ( & mut self , cx : & LateContext , ti : & hir:: TraitItem ) {
403- match ti. node {
404- hir:: TraitItemKind :: Const ( ..) => {
405- NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" ,
406- ti. ident . name , ti. span ) ;
407- }
408- _ => { }
398+ if let hir:: TraitItemKind :: Const ( ..) = ti. node {
399+ NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" , & ti. ident ) ;
409400 }
410401 }
411402
412403 fn check_impl_item ( & mut self , cx : & LateContext , ii : & hir:: ImplItem ) {
413- match ii. node {
414- hir:: ImplItemKind :: Const ( ..) => {
415- NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" ,
416- ii. ident . name , ii. span ) ;
417- }
418- _ => { }
404+ if let hir:: ImplItemKind :: Const ( ..) = ii. node {
405+ NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" , & ii. ident ) ;
419406 }
420407 }
421408
@@ -424,10 +411,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
424411 if let PatKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = p. node {
425412 if let Def :: Const ( ..) = path. def {
426413 if path. segments . len ( ) == 1 {
427- NonUpperCaseGlobals :: check_upper_case ( cx,
428- "constant in pattern" ,
429- path. segments [ 0 ] . ident . name ,
430- path. span ) ;
414+ NonUpperCaseGlobals :: check_upper_case (
415+ cx,
416+ "constant in pattern" ,
417+ & path. segments [ 0 ] . ident
418+ ) ;
431419 }
432420 }
433421 }
0 commit comments