Skip to content

FP mut_range_bound: range bound modified inside enclosing loop #6072

Open
@matthiaskrgr

Description

@matthiaskrgr

In this code we first create the mut range bound, and mutate it in another loop which means the loop that actually uses the range is executed several times with different bounds (even if it is true that inside the usage of the range, changing the index has no effect on the inner loop.

fn main() {
    let mut i = 3;
    while i < 1000 { // this invalidates the lint warning
        for x in i..9 { // this will be unaffected by the i+=4 but we modify i AND LOOP AGAIN!
            i += 4; // lint warns about this
        }

        if i > 12 {
            return;
        }
    }
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=30343889f1b8be663adb15c2d8184c2a

The lint should probably only fire if range bound variable and the range bounds usage are in the same scope?

Meta

clippy 0.0.212 (1fd5b9d 2020-09-20)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onI-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