Skip to content

Commit 2408e71

Browse files
Make drop_with_len unsafe
1 parent b95e1d2 commit 2408e71

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ use core::{
99

1010
/// Workaround forbidden specialization of Drop
1111
pub trait VecDrop {
12-
fn drop_with_len(&mut self, len: usize);
12+
unsafe fn drop_with_len(&mut self, len: usize);
1313
}
1414

1515
impl<T> VecDrop for [MaybeUninit<T>] {
16-
fn drop_with_len(&mut self, _len: usize) {
16+
unsafe fn drop_with_len(&mut self, _len: usize) {
1717
// Case of a view, drop does nothing
1818
}
1919
}
2020

2121
impl<T, const N: usize> VecDrop for [MaybeUninit<T>; N] {
22-
fn drop_with_len(&mut self, len: usize) {
22+
unsafe fn drop_with_len(&mut self, len: usize) {
2323
// NOTE(unsafe) avoid bound checks in the slicing operation
2424
// &mut buffer[..self.len]
2525
let mut_slice = unsafe { slice::from_raw_parts_mut(self.as_mut_ptr() as *mut T, len) };
@@ -1540,7 +1540,7 @@ impl<T, const N: usize, const M: usize> From<[T; M]> for Vec<T, N> {
15401540

15411541
impl<T: ?Sized + VecDrop> Drop for VecInner<T> {
15421542
fn drop(&mut self) {
1543-
self.buffer.drop_with_len(self.len)
1543+
unsafe { self.buffer.drop_with_len(self.len) }
15441544
}
15451545
}
15461546

0 commit comments

Comments
 (0)