Skip to content

range_plus_one doesn't handle macros correctly #9431

Closed
@ghost

Description

Summary

When a macro contains this item, Clippy suggests removing the macro call with the correction.

Reproducer

I tried this code:

#![warn(clippy::range_plus_one)]

macro_rules! m {
    () => {
        for i in 0..4 + 1 {
            println!("{}", i);
        }
    }
}

fn main() {
    m!();
}

I expected to see this happen:
A warning on the code inside the macro.

Instead, this happened:

warning: an inclusive range would be more readable
  --> src/main.rs:12:5
   |
12 |     m!();
   |     ^^^^ help: use: `0..=4`

playground

Version

Clippy 0.1.65 (2022-09-04 289279d)

Additional Labels

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions