Skip to content

Improve suggestions for same_item_push lint #6156

@djc

Description

@djc

The suggestion to use resize() is not optimal because it needs calculation of the difference between current size of the collection and the desired size. The suggestion to use vec![] is not great because it will generally require an extra allocation. Instead, I've landed upon this solution. Maybe it could be suggested:

-        for _ in 0..forward {
-            self.buffer.push(255);
-        }
+        self.buffer.extend(std::iter::repeat(255).take(forward));

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-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