rust-lang / rust-lang/rust-clippy
Regarding range_plus_one
Open
Nobody has claimed this yet.
C-bug
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
This code:
#![warn(clippy::pedantic)]
fn foo(i: u32) {
for i in 0 .. i + 1 {
println!("{}", i);
}
}
Gives:
warning: an inclusive range would be more readable
--> src/main.rs:4:14
|
4 | for i in 0 .. i + 1 {
| ^^^^^^^^^^ help: use: `0..=i`
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::pedantic)]
| ^^^^^^^^^^^^^^^^
= note: `#[warn(clippy::range_plus_one)]` implied by `#[warn(clippy::pedantic)]`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one
But ..= isn't performant, especially in inner loops. So for me this seems a bad warning.
Lint Name
No response
Reproducer
I tried this code:
<code>
I saw this happen:
<output>
I expected to see this happen:
Version
No response
Additional Labels
No response
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
Start by reproducing the range_plus_one warning with the Rust example in the issue, then inspect the lint's implementation and existing tests. Compare the generated range forms in the reported loop context and determine whether the lint should change; done means a maintainer-facing conclusion supported by benchmark or test evidence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100