mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Trigger wrong_self_convention
only if it has implicit self
This commit is contained in:
parent
aa15a5442a
commit
cd241b33cb
3 changed files with 56 additions and 10 deletions
|
@ -1838,16 +1838,18 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wrong_self_convention::check(
|
if sig.decl.implicit_self.has_implicit_self() {
|
||||||
cx,
|
wrong_self_convention::check(
|
||||||
&name,
|
cx,
|
||||||
item.vis.node.is_pub(),
|
&name,
|
||||||
self_ty,
|
item.vis.node.is_pub(),
|
||||||
first_arg_ty,
|
self_ty,
|
||||||
first_arg.pat.span,
|
first_arg_ty,
|
||||||
implements_trait,
|
first_arg.pat.span,
|
||||||
false
|
implements_trait,
|
||||||
);
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1903,7 +1905,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let TraitItemKind::Fn(ref sig, _) = item.kind;
|
if let TraitItemKind::Fn(ref sig, _) = item.kind;
|
||||||
|
if sig.decl.implicit_self.has_implicit_self();
|
||||||
if let Some(first_arg_ty) = sig.decl.inputs.iter().next();
|
if let Some(first_arg_ty) = sig.decl.inputs.iter().next();
|
||||||
|
|
||||||
then {
|
then {
|
||||||
let first_arg_span = first_arg_ty.span;
|
let first_arg_span = first_arg_ty.span;
|
||||||
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
|
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
|
||||||
|
|
|
@ -42,3 +42,26 @@ mod issue7032 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod issue7179 {
|
||||||
|
pub struct S(i32);
|
||||||
|
|
||||||
|
impl S {
|
||||||
|
// don't trigger (`s` is not `self`)
|
||||||
|
pub fn from_be(s: Self) -> Self {
|
||||||
|
S(i32::from_be(s.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
// lint
|
||||||
|
pub fn from_be_self(self) -> Self {
|
||||||
|
S(i32::from_be(self.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait T {
|
||||||
|
// don't trigger (`s` is not `self`)
|
||||||
|
fn from_be(s: Self) -> Self;
|
||||||
|
// lint
|
||||||
|
fn from_be_self(self) -> Self;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
19
tests/ui/wrong_self_convention2.stderr
Normal file
19
tests/ui/wrong_self_convention2.stderr
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
error: methods called `from_*` usually take no `self`
|
||||||
|
--> $DIR/wrong_self_convention2.rs:56:29
|
||||||
|
|
|
||||||
|
LL | pub fn from_be_self(self) -> Self {
|
||||||
|
| ^^^^
|
||||||
|
|
|
||||||
|
= note: `-D clippy::wrong-self-convention` implied by `-D warnings`
|
||||||
|
= help: consider choosing a less ambiguous name
|
||||||
|
|
||||||
|
error: methods called `from_*` usually take no `self`
|
||||||
|
--> $DIR/wrong_self_convention2.rs:65:25
|
||||||
|
|
|
||||||
|
LL | fn from_be_self(self) -> Self;
|
||||||
|
| ^^^^
|
||||||
|
|
|
||||||
|
= help: consider choosing a less ambiguous name
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
Loading…
Reference in a new issue