This commit is contained in:
tamaron 2022-04-23 22:45:26 +09:00
parent cef882cc9d
commit 51db157fb4
5 changed files with 25 additions and 28 deletions

View File

@ -296,15 +296,15 @@
/// Checks for methods with certain name prefixes and which
/// doesn't match how self is taken. The actual rules are:
///
/// |Prefix |Postfix |`self` taken | `self` type |
/// |-------|------------|-----------------------|--------------|
/// |`as_` | none |`&self` or `&mut self` | any |
/// |`from_`| none | none | any |
/// |`into_`| none |`self` | any |
/// |`is_` | none |`&self` or none | any |
/// |`to_` | `_mut` |`&mut self` | any |
/// |`to_` | not `_mut` |`self` | `Copy` |
/// |`to_` | not `_mut` |`&self` | not `Copy` |
/// |Prefix |Postfix |`self` taken | `self` type |
/// |-------|------------|-------------------------------|--------------|
/// |`as_` | none |`&self` or `&mut self` | any |
/// |`from_`| none | none | any |
/// |`into_`| none |`self` | any |
/// |`is_` | none |`&mut self` or `&self` or none | any |
/// |`to_` | `_mut` |`&mut self` | any |
/// |`to_` | not `_mut` |`self` | `Copy` |
/// |`to_` | not `_mut` |`&self` | not `Copy` |
///
/// Note: Clippy doesn't trigger methods with `to_` prefix in:
/// - Traits definition.

View File

@ -14,7 +14,7 @@
(&[Convention::StartsWith("as_")], &[SelfKind::Ref, SelfKind::RefMut]),
(&[Convention::StartsWith("from_")], &[SelfKind::No]),
(&[Convention::StartsWith("into_")], &[SelfKind::Value]),
(&[Convention::StartsWith("is_")], &[SelfKind::Ref, SelfKind::No]),
(&[Convention::StartsWith("is_")], &[SelfKind::RefMut, SelfKind::Ref, SelfKind::No]),
(&[Convention::Eq("to_mut")], &[SelfKind::RefMut]),
(&[Convention::StartsWith("to_"), Convention::EndsWith("_mut")], &[SelfKind::RefMut]),

View File

@ -193,11 +193,6 @@ pub mod issue8142 {
struct S;
impl S {
// Should lint: is_ methods should only take &self, or no self at all.
fn is_still_buggy(&mut self) -> bool {
false
}
// Should not lint: "no self at all" is allowed.
fn is_forty_two(x: u32) -> bool {
x == 42

View File

@ -31,7 +31,7 @@ LL | fn into_i32(&self) {}
|
= help: consider choosing a less ambiguous name
error: methods called `is_*` usually take `self` by reference or no `self`
error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self`
--> $DIR/wrong_self_convention.rs:38:15
|
LL | fn is_i32(self) {}
@ -71,7 +71,7 @@ LL | pub fn into_i64(&self) {}
|
= help: consider choosing a less ambiguous name
error: methods called `is_*` usually take `self` by reference or no `self`
error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self`
--> $DIR/wrong_self_convention.rs:46:19
|
LL | pub fn is_i64(self) {}
@ -111,7 +111,7 @@ LL | fn into_i32_ref(&self) {}
|
= help: consider choosing a less ambiguous name
error: methods called `is_*` usually take `self` by reference or no `self`
error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self`
--> $DIR/wrong_self_convention.rs:98:19
|
LL | fn is_i32(self) {}
@ -143,7 +143,7 @@ LL | fn into_i32_ref(&self);
|
= help: consider choosing a less ambiguous name
error: methods called `is_*` usually take `self` by reference or no `self`
error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self`
--> $DIR/wrong_self_convention.rs:122:19
|
LL | fn is_i32(self);
@ -191,13 +191,5 @@ LL | fn to_u64(self) -> u64 {
|
= help: consider choosing a less ambiguous name
error: methods called `is_*` usually take `self` by reference or no `self`
--> $DIR/wrong_self_convention.rs:197:27
|
LL | fn is_still_buggy(&mut self) -> bool {
| ^^^^^^^^^
|
= help: consider choosing a less ambiguous name
error: aborting due to 25 previous errors
error: aborting due to 24 previous errors

View File

@ -104,3 +104,13 @@ pub fn to_mut(self: Pin<&mut Self>) {}
pub fn to_other_thingy(self: Pin<&Self>) {}
}
}
mod issue_8480_8513 {
struct Cat(String);
impl Cat {
fn is_animal(&mut self) -> bool {
todo!();
}
}
}