new lint: method_without_self_relation - #15913
Conversation
23a34a6 to
fb5ddaf
Compare
|
Lintcheck changes for 17410f9
This comment will be updated if you push new changes |
|
It looks like this triggers for methods in trait impls - that seems like a FP? E.g. there's a lintcheck warning on https://docs.rs/ahash/0.8.11/src/ahash/specialize.rs.html#95-100 |
|
any updates? |
|
Hey @y21 👋 Just wanted to clarify - the trait impl false positive you flagged was fixed in commit 38587b0 ("do not trigger for trait impls"). The lint now explicitly skips trait implementations: // Don't lint trait implementations - these methods are defined by the trait
if implements_trait {
return;
}The lintcheck was re-run after this fix and shows 354 warnings on real-world crates, none of which are from trait impls anymore. Just rebased onto latest master. Let me know if there's anything else needed for review! |
- Merge identical match arms for Ref and RawPtr types - Remove unused cx parameter from contains_self function - Remove unnecessary .iter() call in loop over method inputs
38587b0 to
17410f9
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready |
|
☔ The latest upstream changes (possibly #15979) made this pull request unmergeable. Please resolve the merge conflicts. |
Adds a new restriction lint that detects methods in
implblocks that have no relationship toSelf, neither through parameters, return types, nor receiver. These are better expressed as standalone functions.Motivation
Methods that don't reference
Selfanywhere in their signature are not truly "methods" but rather associated functions that happen to be namespaced under a type. Moving them to standalone functions can improve code modularity and discoverability.Implementation Details
restriction- intentionally conservative since there are valid reasons to keep functions in impl blocks (helpers, private implementation details, namespace organization)Selfreferences in: receiver and return typesExamples
Triggers lint:
Does not trigger:
changelog: [
method_without_self_relation]: new restriction lint to detect methods with no relationship toSelf