rust-lang / rust-lang/rust-clippy
Implicit return with brackets only
Open
Nobody has claimed this yet.
C-enhancement
L-restriction
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Improve implicit return lint. It wood be more classic-like style to omit the return keyword on visually inlined closures. Like Java and JS do with lambdas.
Categories (optional)
- style
What is the advantage of the recommended code over the original code
- Seems more classic-like as Java's and JS' lambdas.
Drawbacks
None.
Example
fn foo_1(bar: Bar) -> Baz {
return bar.map(|b| return b.baz.clone()); // needless closure return
}
fn foo_2(bar: Bar) -> Baz {
return bar.map(|b| {
b.baz.clone() // missing return, since we use curly brackets
});
}
Could be written as:
fn foo_1(bar: Bar) -> Baz {
return bar.map(|b| b.baz.clone());
}
fn foo_2(bar: Bar) -> Baz {
return bar.map(|b| {
return b.baz.clone();
});
}
Contributor guide
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
Use the Rust examples in the issue as the behavioral entry point, then locate the existing implicit-return lint and its tests. Check how closures with parentheses differ from closures with curly brackets, and consider the work complete when the examples receive the intended lint behavior with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100