Rustc should throw a helpful warning on useless "self" argument in methods.
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
When we have a code which does not need the self object we may simply say that it can be removed.
struct A(u64);
impl A {
fn m1(&self) { // warning: unused self can be removed
println!("Hello world");
}
fn m2(&mut self) { // warning: unused self can be removed
println!("Hello again");
}
}
Though, this warning should have a possibility to be ommited. And, for example, there are some special cases, one of which @eddyb has pointed me to: if we have a trait which requires method to accept self as a parameter, we don't need to emit such warning:
struct A(u64);
trait Printable {
fn m1(&self);
}
impl Printable for A {
fn m1(&self) { // no warning is here
println!("Printed!");
}
}
The reason of that is making easier to refactor this code in the future (especially if it is very long and we must read the whole method body just to understand that it does not depend on object at all) and to allow code users to call this method without an object.
If this idea gets approved, I would like to implement it by myself. But I have no idea how to work with it so I would like to get some advices where to look at, in learning purposes. I love rust and I want to help to make it better as much as I can.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the RFC repository's contribution guidance and the Rust examples in this issue. Clarify the proposed warning, how it can be omitted, and the trait-implementation exception before identifying the compiler work and tests needed to demonstrate the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100