rust-lang / rust-lang/rust-clippy
range_plus_one help suggestion should not remove braces
Open
Nobody has claimed this yet.
L-suggestion
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
The following code triggers the range_plus_one lint correctly. However the suggestion, if applied explicitly ie by an IDE, removes the braces which causes a compile error.
fn main() {
let from = 5;
let to = 16;
for n in (from..to + 1).rev() {
eprintln!("{}", n);
}
}
--> src/main.rs:17:14
|
17 | for n in (from..to + 1).rev() {
| ^^^^^^^^^^^^^^ help: use: `from..=to`
|
= note: #[warn(range_plus_one)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#range_plus_one
Incorrect suggested code:
fn main() {
let from = 5;
let to = 16;
for n in from..=to.rev() {
eprintln!("{}", n);
}
}
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
Reproduce the range_plus_one lint with the Rust example in the issue and inspect the lint's suggestion-generation entry point. Check why the replacement drops the surrounding range parentheses, then verify that the suggested code preserves them, compiles, and still produces the intended inclusive range.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100