@@ -1674,32 +1674,14 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1674
1674
}
1675
1675
}
1676
1676
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
+ ) ;
1703
1685
}
1704
1686
}
1705
1687
@@ -1748,26 +1730,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1748
1730
let self_ty = TraitRef :: identity( cx. tcx, item. hir_id. owner. to_def_id( ) ) . self_ty( ) ;
1749
1731
1750
1732
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) ;
1771
1734
}
1772
1735
}
1773
1736
@@ -1792,6 +1755,39 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1792
1755
extract_msrv_attr ! ( LateContext ) ;
1793
1756
}
1794
1757
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
+
1795
1791
/// Checks for the `OR_FUN_CALL` lint.
1796
1792
#[ allow( clippy:: too_many_lines) ]
1797
1793
fn lint_or_fun_call < ' tcx > (
0 commit comments