@@ -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,24 +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-
4123declare_lint ! {
4224 /// The `non_camel_case_types` lint detects types, variants, traits and
4325 /// type parameters that don't have camel case names.
@@ -392,19 +374,19 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
392374 id : LocalDefId ,
393375 ) {
394376 match & fk {
395- FnKind :: Method ( ident, sig, ..) => match method_context ( cx , id) {
396- MethodLateContext :: PlainImpl => {
377+ FnKind :: Method ( ident, sig, ..) => match cx . tcx . associated_item ( id) . container {
378+ AssocContainer :: InherentImpl => {
397379 if sig. header . abi != ExternAbi :: Rust
398380 && find_attr ! ( cx. tcx. get_all_attrs( id) , AttributeKind :: NoMangle ( ..) )
399381 {
400382 return ;
401383 }
402384 self . check_snake_case ( cx, "method" , ident) ;
403385 }
404- MethodLateContext :: TraitAutoImpl => {
386+ AssocContainer :: Trait => {
405387 self . check_snake_case ( cx, "trait method" , ident) ;
406388 }
407- _ => ( ) ,
389+ AssocContainer :: TraitImpl ( _ ) => { }
408390 } ,
409391 FnKind :: ItemFn ( ident, _, header) => {
410392 // Skip foreign-ABI #[no_mangle] functions (Issue #31924)
0 commit comments