Skip to content

Regarding range_plus_one #8317

Open
Open
@leonardo-m

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

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions