@@ -4,7 +4,9 @@ use clippy_utils::is_from_proc_macro;
44use rustc_data_structures:: fx:: FxHashSet ;
55use rustc_hir:: def:: { DefKind , Res } ;
66use rustc_hir:: intravisit:: { Visitor , walk_item, walk_trait_item} ;
7- use rustc_hir:: { GenericParamKind , HirId , Item , ItemKind , ItemLocalId , Node , Pat , PatKind , TraitItem , UsePath } ;
7+ use rustc_hir:: {
8+ GenericParamKind , HirId , Impl , ImplItemKind , Item , ItemKind , ItemLocalId , Node , Pat , PatKind , TraitItem , UsePath ,
9+ } ;
810use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
911use rustc_session:: impl_lint_pass;
1012use rustc_span:: Span ;
@@ -84,6 +86,7 @@ impl LateLintPass<'_> for MinIdentChars {
8486 if let PatKind :: Binding ( _, _, ident, ..) = pat. kind
8587 && let str = ident. as_str ( )
8688 && self . is_ident_too_short ( cx, str, ident. span )
89+ && is_not_in_trait_impl ( cx, pat)
8790 {
8891 emit_min_ident_chars ( self , cx, str, ident. span ) ;
8992 }
@@ -201,3 +204,27 @@ fn opt_as_use_node(node: Node<'_>) -> Option<&'_ UsePath<'_>> {
201204 None
202205 }
203206}
207+
208+ /// Check if a pattern is a function param in an impl block for a trait.
209+ fn is_not_in_trait_impl ( cx : & LateContext < ' _ > , pat : & Pat < ' _ > ) -> bool {
210+ let parent_node = cx. tcx . parent_hir_node ( pat. hir_id ) ;
211+ if !matches ! ( parent_node, Node :: Param ( _) ) {
212+ return true ;
213+ }
214+
215+ for ( _, parent_node) in cx. tcx . hir_parent_iter ( pat. hir_id ) {
216+ if let Node :: ImplItem ( impl_item) = parent_node
217+ && matches ! ( impl_item. kind, ImplItemKind :: Fn ( _, _) )
218+ {
219+ let impl_parent_node = cx. tcx . parent_hir_node ( impl_item. hir_id ( ) ) ;
220+ if let Node :: Item ( parent_item) = impl_parent_node
221+ && let ItemKind :: Impl ( Impl { of_trait : Some ( _) , .. } ) = & parent_item. kind
222+ {
223+ return false ;
224+ }
225+ return true ;
226+ }
227+ }
228+
229+ true
230+ }
0 commit comments