Skip to content

Add a UB-check to Vec::set_len #143813

@scottmcm

Description

@scottmcm

Today, set_len has a debug_assert! on the length being legal:

#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn set_len(&mut self, new_len: usize) {
debug_assert!(new_len <= self.capacity());
self.len = new_len;
}

It would be nice, assuming the compilation time hit is tolerable, to upgrade that to a UB-check in order to better catch people making over-long vectors.

Metadata

Metadata

Assignees

Labels

A-collectionsArea: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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