diff --git a/.gitignore b/.gitignore index 5ec74668..858f0d52 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ target -Cargo.lock /fuzz/hfuzz_target /.vscode diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..0ddd767f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,98 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "malloc_size_of" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d719de8b8f230028cf8192ae4c1b25267cd6b8a99d2747d345a70b8c81aa13" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "smallvec" +version = "2.0.0-alpha.12" +dependencies = [ + "bincode", + "bytes", + "malloc_size_of", + "serde_core", +] + +[[package]] +name = "syn" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" diff --git a/src/lib.rs b/src/lib.rs index e6bc8c73..b90f2ab7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,8 +86,6 @@ use core::mem::align_of; use core::mem::size_of; use core::mem::ManuallyDrop; use core::mem::MaybeUninit; -use core::ptr::addr_of; -use core::ptr::addr_of_mut; use core::ptr::copy; use core::ptr::copy_nonoverlapping; use core::ptr::NonNull; @@ -207,16 +205,16 @@ impl RawSmallVec { #[inline] const fn as_ptr_inline(&self) -> *const T { - // SAFETY: This is safe because we don't read the value. We only get a pointer to the data. - // Dereferencing the pointer is unsafe so unsafe code is required to misuse the return - // value. - (unsafe { addr_of!(self.inline) }) as *const T + // SAFETY: it is safe because we aren't reading the value, just getting a + // reference to it. reading it would be UB potentially, but for that downstream + // unsafe is required + (unsafe {&raw const self.inline}) as *mut T } #[inline] const fn as_mut_ptr_inline(&mut self) -> *mut T { - // SAFETY: See above. - (unsafe { addr_of_mut!(self.inline) }) as *mut T + // SAFETY: same as above + (unsafe {&raw mut self.inline}) as *mut T } /// # Safety diff --git a/src/tests.rs b/src/tests.rs index 2082f962..466b96d4 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -370,7 +370,7 @@ fn test_invalid_grow() { #[should_panic] fn drain_overflow() { let mut v: SmallVec = smallvec![0]; - v.drain(..=std::usize::MAX); + v.drain(..=usize::MAX); } #[test]