@@ -18,8 +18,8 @@ use hir_def::{
18
18
data:: adt:: VariantData ,
19
19
hir:: { Pat , PatId } ,
20
20
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 ,
23
23
} ;
24
24
use hir_expand:: {
25
25
name:: { AsName , Name } ,
@@ -189,8 +189,7 @@ impl<'a> DeclValidator<'a> {
189
189
AttrDefId :: TypeAliasId ( _) => None ,
190
190
AttrDefId :: GenericParamId ( _) => None ,
191
191
}
192
- . map ( |mid| self . allowed ( mid, allow_name, true ) )
193
- . unwrap_or ( false )
192
+ . is_some_and ( |mid| self . allowed ( mid, allow_name, true ) )
194
193
}
195
194
196
195
fn validate_func ( & mut self , func : FunctionId ) {
@@ -482,6 +481,11 @@ impl<'a> DeclValidator<'a> {
482
481
fn validate_enum ( & mut self , enum_id : EnumId ) {
483
482
let data = self . db . enum_data ( enum_id) ;
484
483
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
+
485
489
// Check whether non-camel case names are allowed for this enum.
486
490
if self . allowed ( enum_id. into ( ) , allow:: NON_CAMEL_CASE_TYPES , false ) {
487
491
return ;
@@ -498,13 +502,11 @@ impl<'a> DeclValidator<'a> {
498
502
// Check the field names.
499
503
let enum_fields_replacements = data
500
504
. variants
501
- . iter ( )
502
- . filter_map ( |( _ , variant) | {
505
+ . values ( )
506
+ . filter_map ( |variant| {
503
507
Some ( Replacement {
504
508
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 ( ) ) ?,
508
510
expected_case : CaseType :: UpperCamelCase ,
509
511
} )
510
512
} )
@@ -608,6 +610,8 @@ impl<'a> DeclValidator<'a> {
608
610
fn validate_const ( & mut self , const_id : ConstId ) {
609
611
let data = self . db . const_data ( const_id) ;
610
612
613
+ self . validate_body_inner_items ( const_id. into ( ) ) ;
614
+
611
615
if self . allowed ( const_id. into ( ) , allow:: NON_UPPER_CASE_GLOBAL , false ) {
612
616
return ;
613
617
}
@@ -617,7 +621,7 @@ impl<'a> DeclValidator<'a> {
617
621
None => return ,
618
622
} ;
619
623
620
- let const_name = name. display ( self . db . upcast ( ) ) . to_string ( ) ;
624
+ let const_name = name. to_smol_str ( ) ;
621
625
let replacement = if let Some ( new_name) = to_upper_snake_case ( & const_name) {
622
626
Replacement {
623
627
current_name : name. clone ( ) ,
@@ -656,13 +660,15 @@ impl<'a> DeclValidator<'a> {
656
660
return ;
657
661
}
658
662
663
+ self . validate_body_inner_items ( static_id. into ( ) ) ;
664
+
659
665
if self . allowed ( static_id. into ( ) , allow:: NON_UPPER_CASE_GLOBAL , false ) {
660
666
return ;
661
667
}
662
668
663
669
let name = & data. name ;
664
670
665
- let static_name = name. display ( self . db . upcast ( ) ) . to_string ( ) ;
671
+ let static_name = name. to_smol_str ( ) ;
666
672
let replacement = if let Some ( new_name) = to_upper_snake_case ( & static_name) {
667
673
Replacement {
668
674
current_name : name. clone ( ) ,
@@ -694,6 +700,7 @@ impl<'a> DeclValidator<'a> {
694
700
self . sink . push ( diagnostic) ;
695
701
}
696
702
703
+ // FIXME: We don't currently validate names within `DefWithBodyId::InTypeConstId`.
697
704
/// Recursively validates inner scope items, such as static variables and constants.
698
705
fn validate_body_inner_items ( & mut self , body_id : DefWithBodyId ) {
699
706
let body = self . db . body ( body_id) ;
0 commit comments