@@ -1674,32 +1674,14 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
16741674 }
16751675 }
16761676
1677- if let Some ( ( ref conv, self_kinds) ) = & CONVENTIONS
1678- . iter( )
1679- . find( |( ref conv, _) | conv. check( & name) )
1680- {
1681- if !self_kinds. iter( ) . any( |k| k. matches( cx, self_ty, first_arg_ty) ) {
1682- let lint = if item. vis. node. is_pub( ) {
1683- WRONG_PUB_SELF_CONVENTION
1684- } else {
1685- WRONG_SELF_CONVENTION
1686- } ;
1687-
1688- span_lint(
1689- cx,
1690- lint,
1691- first_arg. pat. span,
1692- & format!( "methods called `{}` usually take {}; consider choosing a less ambiguous name" ,
1693- conv,
1694- & self_kinds
1695- . iter( )
1696- . map( |k| k. description( ) )
1697- . collect:: <Vec <_>>( )
1698- . join( " or " )
1699- ) ,
1700- ) ;
1701- }
1702- }
1677+ lint_wrong_self_convention(
1678+ cx,
1679+ & name,
1680+ item. vis. node. is_pub( ) ,
1681+ self_ty,
1682+ first_arg_ty,
1683+ first_arg. pat. span
1684+ ) ;
17031685 }
17041686 }
17051687
@@ -1748,26 +1730,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
17481730 let self_ty = TraitRef :: identity( cx. tcx, item. hir_id. owner. to_def_id( ) ) . self_ty( ) ;
17491731
17501732 then {
1751- if let Some ( ( ref conv, self_kinds) ) = & CONVENTIONS
1752- . iter( )
1753- . find( |( ref conv, _) | conv. check( & item. ident. name. as_str( ) ) )
1754- {
1755- if !self_kinds. iter( ) . any( |k| k. matches( cx, self_ty, first_arg_ty) ) {
1756- span_lint(
1757- cx,
1758- WRONG_PUB_SELF_CONVENTION ,
1759- first_arg_span,
1760- & format!( "methods called `{}` usually take {}; consider choosing a less ambiguous name" ,
1761- conv,
1762- & self_kinds
1763- . iter( )
1764- . map( |k| k. description( ) )
1765- . collect:: <Vec <_>>( )
1766- . join( " or " )
1767- ) ,
1768- ) ;
1769- }
1770- }
1733+ lint_wrong_self_convention( cx, & item. ident. name. as_str( ) , false , self_ty, first_arg_ty, first_arg_span) ;
17711734 }
17721735 }
17731736
@@ -1792,6 +1755,39 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
17921755 extract_msrv_attr ! ( LateContext ) ;
17931756}
17941757
1758+ fn lint_wrong_self_convention < ' tcx > (
1759+ cx : & LateContext < ' tcx > ,
1760+ item_name : & str ,
1761+ is_pub : bool ,
1762+ self_ty : & ' tcx TyS < ' tcx > ,
1763+ first_arg_ty : & ' tcx TyS < ' tcx > ,
1764+ first_arg_span : Span ,
1765+ ) {
1766+ let lint = if is_pub {
1767+ WRONG_PUB_SELF_CONVENTION
1768+ } else {
1769+ WRONG_SELF_CONVENTION
1770+ } ;
1771+ if let Some ( ( ref conv, self_kinds) ) = & CONVENTIONS . iter ( ) . find ( |( ref conv, _) | conv. check ( item_name) ) {
1772+ if !self_kinds. iter ( ) . any ( |k| k. matches ( cx, self_ty, first_arg_ty) ) {
1773+ span_lint (
1774+ cx,
1775+ lint,
1776+ first_arg_span,
1777+ & format ! (
1778+ "methods called `{}` usually take {}; consider choosing a less ambiguous name" ,
1779+ conv,
1780+ & self_kinds
1781+ . iter( )
1782+ . map( |k| k. description( ) )
1783+ . collect:: <Vec <_>>( )
1784+ . join( " or " )
1785+ ) ,
1786+ ) ;
1787+ }
1788+ }
1789+ }
1790+
17951791/// Checks for the `OR_FUN_CALL` lint.
17961792#[ allow( clippy:: too_many_lines) ]
17971793fn lint_or_fun_call < ' tcx > (
0 commit comments