Skip to content

Improve suggestions for needless_range_loop #1864

Closed
@vbrandl

Description

@vbrandl

Hey there. First of all: Great work to all the devs. Clippy is a real handy tool when developing in Rust.

Now about my proposal: the needless_range_loop gives pretty good suggestions even for non default ranges. But if a range loop like the following is linted, one could suggest to use a mutable iterator using iter_mut():

for i in 1..arr.len()-1 {
    arr[i] = <some_value>;
}

Clippy would suggest something like for <item> in arr.iter().take(arr.len()-1).skip(1) { but in this case iter_mut() must be used to assign new values to <item>. I don't know if there is an easy way to detect cases like this one but I think it would be a great improvement.

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 appliedL-suggestionLint: Improving, adding or fixing lint suggestionsT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions