Skip to content

Possible Vec::truncate improvement #76089

Open
@leonardo-m

Description

@leonardo-m

The docs of Vec::truncate say:

"If len is greater than the vector's current length, this has no effect."

And indeed if you look at the source code:
https://doc.rust-lang.org/nightly/src/alloc/vec.rs.html#740-742

There's:

if len > self.len {
    return;
}

But isn't it better to use len >= self.len instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions