Skip to content

Commit

Permalink
use ManuallyDrop instead of mem-forget-in-disguise
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 30, 2020
1 parent 27a0f9c commit 5ff331a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bytes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::iter::FromIterator;
use core::ops::{Deref, RangeBounds};
use core::{cmp, fmt, hash, mem, ptr, slice, usize};
use core::mem::ManuallyDrop;

use alloc::{borrow::Borrow, boxed::Box, string::String, vec::Vec};

Expand Down Expand Up @@ -804,10 +805,9 @@ impl From<Vec<u8>> for Bytes {
return Bytes::new();
}

let slice = vec.into_boxed_slice();
let slice = ManuallyDrop::new(vec.into_boxed_slice());
let len = slice.len();
let ptr = slice.as_ptr();
drop(Box::into_raw(slice));

if ptr as usize & 0x1 == 0 {
let data = ptr as usize | KIND_VEC;
Expand Down

0 comments on commit 5ff331a

Please sign in to comment.