File tree Expand file tree Collapse file tree 3 files changed +56
-10
lines changed
Expand file tree Collapse file tree 3 files changed +56
-10
lines changed Original file line number Diff line number Diff line change @@ -1838,16 +1838,18 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
18381838 }
18391839 }
18401840
1841- wrong_self_convention:: check(
1842- cx,
1843- & name,
1844- item. vis. node. is_pub( ) ,
1845- self_ty,
1846- first_arg_ty,
1847- first_arg. pat. span,
1848- implements_trait,
1849- false
1850- ) ;
1841+ if sig. decl. implicit_self. has_implicit_self( ) {
1842+ wrong_self_convention:: check(
1843+ cx,
1844+ & name,
1845+ item. vis. node. is_pub( ) ,
1846+ self_ty,
1847+ first_arg_ty,
1848+ first_arg. pat. span,
1849+ implements_trait,
1850+ false
1851+ ) ;
1852+ }
18511853 }
18521854 }
18531855
@@ -1903,7 +1905,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
19031905
19041906 if_chain ! {
19051907 if let TraitItemKind :: Fn ( ref sig, _) = item. kind;
1908+ if sig. decl. implicit_self. has_implicit_self( ) ;
19061909 if let Some ( first_arg_ty) = sig. decl. inputs. iter( ) . next( ) ;
1910+
19071911 then {
19081912 let first_arg_span = first_arg_ty. span;
19091913 let first_arg_ty = hir_ty_to_ty( cx. tcx, first_arg_ty) ;
Original file line number Diff line number Diff line change @@ -42,3 +42,26 @@ mod issue7032 {
4242 }
4343 }
4444}
45+
46+ mod issue7179 {
47+ pub struct S ( i32 ) ;
48+
49+ impl S {
50+ // don't trigger (`s` is not `self`)
51+ pub fn from_be ( s : Self ) -> Self {
52+ S ( i32:: from_be ( s. 0 ) )
53+ }
54+
55+ // lint
56+ pub fn from_be_self ( self ) -> Self {
57+ S ( i32:: from_be ( self . 0 ) )
58+ }
59+ }
60+
61+ trait T {
62+ // don't trigger (`s` is not `self`)
63+ fn from_be ( s : Self ) -> Self ;
64+ // lint
65+ fn from_be_self ( self ) -> Self ;
66+ }
67+ }
Original file line number Diff line number Diff line change 1+ error: methods called `from_*` usually take no `self`
2+ --> $DIR/wrong_self_convention2.rs:56:29
3+ |
4+ LL | pub fn from_be_self(self) -> Self {
5+ | ^^^^
6+ |
7+ = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
8+ = help: consider choosing a less ambiguous name
9+
10+ error: methods called `from_*` usually take no `self`
11+ --> $DIR/wrong_self_convention2.rs:65:25
12+ |
13+ LL | fn from_be_self(self) -> Self;
14+ | ^^^^
15+ |
16+ = help: consider choosing a less ambiguous name
17+
18+ error: aborting due to 2 previous errors
19+
You can’t perform that action at this time.
0 commit comments