-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Possible Vec::truncate improvement #76089
Copy link
Copy link
Open
Labels
A-collectionsArea: `std::collections`Area: `std::collections`E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call 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.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call 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.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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:
But isn't it better to use
len >= self.leninstead?