-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-bugCategory: This is a bug.Category: This is a bug.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.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.
Description
VecDeque
has an internal method called buffer_as_slice
, which returns an &[T]
containing the entire capacity of the VecDeque
. This is undefined behavior if the VecDeque
is not full, since some elements of the backing RawVec
may be uninitialized. However, this invariant is not documented on buffer_as_slice
and is not respected in practice. For example, VecDeque::iter
calls buffer_as_slice
unconditionally:
rust/src/liballoc/collections/vec_deque.rs
Lines 959 to 962 in 34c5cd9
#[stable(feature = "rust1", since = "1.0.0")] | |
pub fn iter(&self) -> Iter<'_, T> { | |
Iter { tail: self.tail, head: self.head, ring: unsafe { self.buffer_as_slice() } } | |
} |
This one seems so obvious that I'm wondering if I've overlooked something. cc @rust-lang/wg-unsafe-code-guidelines
Found while doing #74172.
ehsanmok and ChayimFriedman2
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-bugCategory: This is a bug.Category: This is a bug.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.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.