Skip to content

Commit 19b8c65

Browse files
authored
Rollup merge of #80857 - camelid:vec-truncate-comment, r=scottmcm
Add comment to `Vec::truncate` explaining `>` vs `>=` Hopefully this will prevent people from continuing to ask about this over and over again :) See [this Zulip discussion][1] for more. [1]: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Vec.3A.3Atruncate.20implementation r? ``@scottmcm``
2 parents 3e735c6 + befd153 commit 19b8c65

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/alloc/src/vec/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,9 @@ impl<T, A: Allocator> Vec<T, A> {
990990
// such that no value will be dropped twice in case `drop_in_place`
991991
// were to panic once (if it panics twice, the program aborts).
992992
unsafe {
993+
// Note: It's intentional that this is `>` and not `>=`.
994+
// Changing it to `>=` has negative performance
995+
// implications in some cases. See #78884 for more.
993996
if len > self.len {
994997
return;
995998
}

0 commit comments

Comments
 (0)