-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrong_self_convention: FN with is_*
taking &mut self
#8142
Comments
This issue was filed because intellij-rust warns for both
|
I agree. It should warn on |
This one looks neat, and I think I can see what the trouble is; I'll try writing a patch for this in the next day or two. (If I haven't written a PR by 5 January, I have probably given up or forgotten this.) |
wrong_self_convention: Match `SelfKind::No` more restrictively The `wrong_self_convention` lint uses a `SelfKind` type to decide whether a method has the right kind of "self" for its name, or whether the kind of "self" it has makes its name confusable for a method in a common trait. One possibility is `SelfKind::No`, which is supposed to mean "No `self`". Previously, SelfKind::No matched everything _except_ Self, including references to Self. This patch changes it to match Self, &Self, &mut Self, Box<Self>, and so on. For example, this kind of method was allowed before: ``` impl S { // Should trigger the lint, because // "methods called `is_*` usually take `self` by reference or no `self`" fn is_foo(&mut self) -> bool { todo!() } } ``` But since SelfKind::No matched "&mut self", no lint was triggered (see #8142). With this patch, the code above now gives a lint as expected. fixes #8142 changelog: [`wrong_self_convention`] rejects `self` references in more cases
Summary
My interpretation of the table at https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention is that a method called
is_*
is allowed to take no self, or&self
, but notself
or&mut self
. In reality, onlyself
produces a warning. Is this intentional?Lint Name
wrong_self_convention
Reproducer
I tried this code:
I expected to see this happen:
Instead, this happened:
No warning
Version
The text was updated successfully, but these errors were encountered: