@@ -18,8 +18,8 @@ use hir_def::{
1818 data:: adt:: VariantData ,
1919 hir:: { Pat , PatId } ,
2020 src:: HasSource ,
21- AdtId , AttrDefId , ConstId , DefWithBodyId , EnumId , FunctionId , ItemContainerId , Lookup ,
22- ModuleDefId , StaticId , StructId ,
21+ AdtId , AttrDefId , ConstId , DefWithBodyId , EnumId , EnumVariantId , FunctionId , ItemContainerId ,
22+ Lookup , ModuleDefId , StaticId , StructId ,
2323} ;
2424use hir_expand:: {
2525 name:: { AsName , Name } ,
@@ -189,8 +189,7 @@ impl<'a> DeclValidator<'a> {
189189 AttrDefId :: TypeAliasId ( _) => None ,
190190 AttrDefId :: GenericParamId ( _) => None ,
191191 }
192- . map ( |mid| self . allowed ( mid, allow_name, true ) )
193- . unwrap_or ( false )
192+ . is_some_and ( |mid| self . allowed ( mid, allow_name, true ) )
194193 }
195194
196195 fn validate_func ( & mut self , func : FunctionId ) {
@@ -482,6 +481,11 @@ impl<'a> DeclValidator<'a> {
482481 fn validate_enum ( & mut self , enum_id : EnumId ) {
483482 let data = self . db . enum_data ( enum_id) ;
484483
484+ for ( local_id, _) in data. variants . iter ( ) {
485+ let variant_id = EnumVariantId { parent : enum_id, local_id } ;
486+ self . validate_body_inner_items ( variant_id. into ( ) ) ;
487+ }
488+
485489 // Check whether non-camel case names are allowed for this enum.
486490 if self . allowed ( enum_id. into ( ) , allow:: NON_CAMEL_CASE_TYPES , false ) {
487491 return ;
@@ -498,13 +502,11 @@ impl<'a> DeclValidator<'a> {
498502 // Check the field names.
499503 let enum_fields_replacements = data
500504 . variants
501- . iter ( )
502- . filter_map ( |( _ , variant) | {
505+ . values ( )
506+ . filter_map ( |variant| {
503507 Some ( Replacement {
504508 current_name : variant. name . clone ( ) ,
505- suggested_text : to_camel_case (
506- & variant. name . display ( self . db . upcast ( ) ) . to_string ( ) ,
507- ) ?,
509+ suggested_text : to_camel_case ( & variant. name . to_smol_str ( ) ) ?,
508510 expected_case : CaseType :: UpperCamelCase ,
509511 } )
510512 } )
@@ -608,6 +610,8 @@ impl<'a> DeclValidator<'a> {
608610 fn validate_const ( & mut self , const_id : ConstId ) {
609611 let data = self . db . const_data ( const_id) ;
610612
613+ self . validate_body_inner_items ( const_id. into ( ) ) ;
614+
611615 if self . allowed ( const_id. into ( ) , allow:: NON_UPPER_CASE_GLOBAL , false ) {
612616 return ;
613617 }
@@ -617,7 +621,7 @@ impl<'a> DeclValidator<'a> {
617621 None => return ,
618622 } ;
619623
620- let const_name = name. display ( self . db . upcast ( ) ) . to_string ( ) ;
624+ let const_name = name. to_smol_str ( ) ;
621625 let replacement = if let Some ( new_name) = to_upper_snake_case ( & const_name) {
622626 Replacement {
623627 current_name : name. clone ( ) ,
@@ -656,13 +660,15 @@ impl<'a> DeclValidator<'a> {
656660 return ;
657661 }
658662
663+ self . validate_body_inner_items ( static_id. into ( ) ) ;
664+
659665 if self . allowed ( static_id. into ( ) , allow:: NON_UPPER_CASE_GLOBAL , false ) {
660666 return ;
661667 }
662668
663669 let name = & data. name ;
664670
665- let static_name = name. display ( self . db . upcast ( ) ) . to_string ( ) ;
671+ let static_name = name. to_smol_str ( ) ;
666672 let replacement = if let Some ( new_name) = to_upper_snake_case ( & static_name) {
667673 Replacement {
668674 current_name : name. clone ( ) ,
@@ -694,6 +700,7 @@ impl<'a> DeclValidator<'a> {
694700 self . sink . push ( diagnostic) ;
695701 }
696702
703+ // FIXME: We don't currently validate names within `DefWithBodyId::InTypeConstId`.
697704 /// Recursively validates inner scope items, such as static variables and constants.
698705 fn validate_body_inner_items ( & mut self , body_id : DefWithBodyId ) {
699706 let body = self . db . body ( body_id) ;
0 commit comments