@@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId;
77use rustc_hir:: intravisit:: { FnKind , Visitor } ;
88use rustc_hir:: { AttrArgs , AttrItem , Attribute , GenericParamKind , PatExprKind , PatKind , find_attr} ;
99use rustc_middle:: hir:: nested_filter:: All ;
10- use rustc_middle:: ty;
10+ use rustc_middle:: ty:: AssocContainer ;
1111use rustc_session:: config:: CrateType ;
1212use rustc_session:: { declare_lint, declare_lint_pass} ;
1313use rustc_span:: def_id:: LocalDefId ;
@@ -20,29 +20,6 @@ use crate::lints::{
2020} ;
2121use crate :: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
2222
23- #[ derive( PartialEq ) ]
24- pub ( crate ) enum MethodLateContext {
25- TraitAutoImpl ,
26- TraitImpl ,
27- PlainImpl ,
28- }
29-
30- pub ( crate ) fn method_context ( cx : & LateContext < ' _ > , id : LocalDefId ) -> MethodLateContext {
31- let item = cx. tcx . associated_item ( id) ;
32- match item. container {
33- ty:: AssocContainer :: Trait => MethodLateContext :: TraitAutoImpl ,
34- ty:: AssocContainer :: Impl => match cx. tcx . impl_trait_ref ( item. container_id ( cx. tcx ) ) {
35- Some ( _) => MethodLateContext :: TraitImpl ,
36- None => MethodLateContext :: PlainImpl ,
37- } ,
38- }
39- }
40-
41- fn assoc_item_in_trait_impl ( cx : & LateContext < ' _ > , ii : & hir:: ImplItem < ' _ > ) -> bool {
42- let item = cx. tcx . associated_item ( ii. owner_id ) ;
43- item. trait_item_def_id . is_some ( )
44- }
45-
4623declare_lint ! {
4724 /// The `non_camel_case_types` lint detects types, variants, traits and
4825 /// type parameters that don't have camel case names.
@@ -397,19 +374,19 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
397374 id : LocalDefId ,
398375 ) {
399376 match & fk {
400- FnKind :: Method ( ident, sig, ..) => match method_context ( cx , id) {
401- MethodLateContext :: PlainImpl => {
377+ FnKind :: Method ( ident, sig, ..) => match cx . tcx . associated_item ( id) . container {
378+ AssocContainer :: InherentImpl => {
402379 if sig. header . abi != ExternAbi :: Rust
403380 && find_attr ! ( cx. tcx. get_all_attrs( id) , AttributeKind :: NoMangle ( ..) )
404381 {
405382 return ;
406383 }
407384 self . check_snake_case ( cx, "method" , ident) ;
408385 }
409- MethodLateContext :: TraitAutoImpl => {
386+ AssocContainer :: Trait => {
410387 self . check_snake_case ( cx, "trait method" , ident) ;
411388 }
412- _ => ( ) ,
389+ AssocContainer :: TraitImpl ( _ ) => { }
413390 } ,
414391 FnKind :: ItemFn ( ident, _, header) => {
415392 // Skip foreign-ABI #[no_mangle] functions (Issue #31924)
@@ -610,7 +587,8 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
610587
611588 fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , ii : & hir:: ImplItem < ' _ > ) {
612589 if let hir:: ImplItemKind :: Const ( ..) = ii. kind
613- && !assoc_item_in_trait_impl ( cx, ii)
590+ && let assoc = cx. tcx . associated_item ( ii. owner_id )
591+ && !matches ! ( assoc. container, AssocContainer :: TraitImpl ( _) )
614592 {
615593 NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" , None , & ii. ident ) ;
616594 }
0 commit comments