@@ -328,8 +328,8 @@ impl<'a> DeclValidator<'a> {
328
328
}
329
329
330
330
fn validate_func ( & mut self , func : FunctionId ) {
331
- let data = self . db . function_data ( func ) ;
332
- if matches ! ( func . lookup ( self . db . upcast ( ) ) . container, ItemContainerId :: ExternBlockId ( _) ) {
331
+ let container = func . lookup ( self . db . upcast ( ) ) . container ;
332
+ if matches ! ( container, ItemContainerId :: ExternBlockId ( _) ) {
333
333
cov_mark:: hit!( extern_func_incorrect_case_ignored) ;
334
334
return ;
335
335
}
@@ -339,23 +339,48 @@ impl<'a> DeclValidator<'a> {
339
339
return ;
340
340
}
341
341
342
- // Check the function name.
343
- let function_name = data. name . display ( self . db . upcast ( ) ) . to_string ( ) ;
344
- let fn_name_replacement = to_lower_snake_case ( & function_name) . map ( |new_name| Replacement {
345
- current_name : data. name . clone ( ) ,
346
- suggested_text : new_name,
347
- expected_case : CaseType :: LowerSnakeCase ,
348
- } ) ;
342
+ // Check whether function is an associated item of a trait implementation
343
+ let is_trait_impl_assoc_fn = self . is_trait_impl_container ( container) ;
349
344
350
- let body = self . db . body ( func. into ( ) ) ;
345
+ // Check the function name.
346
+ if !is_trait_impl_assoc_fn {
347
+ let data = self . db . function_data ( func) ;
348
+ let function_name = data. name . display ( self . db . upcast ( ) ) . to_string ( ) ;
349
+ let fn_name_replacement =
350
+ to_lower_snake_case ( & function_name) . map ( |new_name| Replacement {
351
+ current_name : data. name . clone ( ) ,
352
+ suggested_text : new_name,
353
+ expected_case : CaseType :: LowerSnakeCase ,
354
+ } ) ;
355
+ // If there is at least one element to spawn a warning on,
356
+ // go to the source map and generate a warning.
357
+ if let Some ( fn_name_replacement) = fn_name_replacement {
358
+ self . create_incorrect_case_diagnostic_for_func ( func, fn_name_replacement) ;
359
+ }
360
+ } else {
361
+ cov_mark:: hit!( trait_impl_assoc_func_name_incorrect_case_ignored) ;
362
+ }
351
363
352
364
// Check the patterns inside the function body.
353
- // This includes function parameters.
365
+ // This includes function parameters if it's not an associated function
366
+ // of a trait implementation.
367
+ let body = self . db . body ( func. into ( ) ) ;
354
368
let pats_replacements = body
355
369
. pats
356
370
. iter ( )
357
371
. filter_map ( |( pat_id, pat) | match pat {
358
- Pat :: Bind { id, .. } => Some ( ( pat_id, & body. bindings [ * id] . name ) ) ,
372
+ Pat :: Bind { id, .. } => {
373
+ // Filter out parameters if it's an associated function
374
+ // of a trait implementation.
375
+ if is_trait_impl_assoc_fn
376
+ && body. params . iter ( ) . any ( |param_id| * param_id == pat_id)
377
+ {
378
+ cov_mark:: hit!( trait_impl_assoc_func_param_incorrect_case_ignored) ;
379
+ None
380
+ } else {
381
+ Some ( ( pat_id, & body. bindings [ * id] . name ) )
382
+ }
383
+ }
359
384
_ => None ,
360
385
} )
361
386
. filter_map ( |( id, bind_name) | {
@@ -371,12 +396,6 @@ impl<'a> DeclValidator<'a> {
371
396
) )
372
397
} )
373
398
. collect ( ) ;
374
-
375
- // If there is at least one element to spawn a warning on, go to the source map and generate a warning.
376
- if let Some ( fn_name_replacement) = fn_name_replacement {
377
- self . create_incorrect_case_diagnostic_for_func ( func, fn_name_replacement) ;
378
- }
379
-
380
399
self . create_incorrect_case_diagnostic_for_variables ( func, pats_replacements) ;
381
400
}
382
401
@@ -732,6 +751,12 @@ impl<'a> DeclValidator<'a> {
732
751
}
733
752
734
753
fn validate_const ( & mut self , const_id : ConstId ) {
754
+ let container = const_id. lookup ( self . db . upcast ( ) ) . container ;
755
+ if self . is_trait_impl_container ( container) {
756
+ cov_mark:: hit!( trait_impl_assoc_const_incorrect_case_ignored) ;
757
+ return ;
758
+ }
759
+
735
760
let data = self . db . const_data ( const_id) ;
736
761
737
762
if self . allowed ( const_id. into ( ) , allow:: NON_UPPER_CASE_GLOBAL , false ) {
@@ -819,4 +844,13 @@ impl<'a> DeclValidator<'a> {
819
844
820
845
self . sink . push ( diagnostic) ;
821
846
}
847
+
848
+ fn is_trait_impl_container ( & self , container_id : ItemContainerId ) -> bool {
849
+ if let ItemContainerId :: ImplId ( impl_id) = container_id {
850
+ if self . db . impl_trait ( impl_id) . is_some ( ) {
851
+ return true ;
852
+ }
853
+ }
854
+ false
855
+ }
822
856
}
0 commit comments