Skip to content

range_plus_one help suggestion should not remove braces #3103

Open
@alexheretic

Description

@alexheretic

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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    L-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions