False positive iterating over and ignoring 0..n + 1
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
Research direction
Start by locating the range_plus_one lint and its existing tests, then run the supplied Rust reproducer and the analogous map example. Done means the 0..n + 1 forms no longer produce the reported warning while the lint's intended cases remain covered by tests.
Written by the indexing model from the issue text.
Description
Summary
The idiomatic way to do the same thing k times is
for _ in 0..k {
do_thing();
}
Suppose k is the expression n + 1.
for _ in 0..n + 1 {
do_thing();
}
This now triggers the range_plus_one lint, but
for _ in 0..=n {
do_thing();
}
is much less clear about what's going on.
(0..n + 1).map(|_| f()) is similar.
Lint Name
range_plus_one
Reproducer
I tried this code:
fn foo(n: usize) {
for _ in 0..n + 1 {
println!("foo");
}
}
with the pedantic group enabled.
I saw this happen:
warning: an inclusive range would be more readable
I expected to see this happen:
[no warning]
Version
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2
Additional Labels
No response
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
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.
More from rust-lang/rust-clippy
-
C-bug L-suggestion
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rust-lang/rust-clippy#17674 · 5 comments ·
-
C-bug L-suggestion
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-clippy#17673 · 3 comments ·
-
C-bug I-false-positive
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
rust-lang/rust-clippy#17566 ·
-
A-documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rust-lang/rust-clippy#17259 · 3 comments ·
-
A-documentation A-website C-bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-clippy#16981 · 1 reaction ·
All issues in rust-lang/rust-clippy
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100