Skip to content

Improvements to RUF15 #7618

@hoxbro

Description

@hoxbro

I have two (small) suggestions for improving unnecessary-iterable-allocation-for-first-element (RUF015)

  1. Don't add iter to built-in functions that are already iterable
    An example of this could be list(zip([0]))[0], which right now is converted to next(iter(zip([10]))), and my suggestion would make it not add iter so it would be next(zip([10]))

  2. Handle an unpacked list
    This could be something like this [*x][0], which should be handled like list(x)[0] and converts to next(iter(x)). I don't think this is used much in the wild, so it could be overkill to add it.

I have a first already started implementing this here. Though, as this is the first time I have written any Rust, it could likely be improved upon 😅

Metadata

Metadata

Assignees

Labels

ruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions