| use array::Array; | ||
| use std::mem::MaybeUninit as StdMaybeUninit; | ||
| pub struct MaybeUninit<T> { | ||
| inner: StdMaybeUninit<T>, | ||
| } | ||
| impl<T> MaybeUninit<T> { | ||
| /// Create a new MaybeUninit with uninitialized interior | ||
| pub unsafe fn uninitialized() -> Self { | ||
| MaybeUninit { inner: StdMaybeUninit::uninit() } | ||
| } | ||
| /// Create a new MaybeUninit from the value `v`. | ||
| pub fn from(v: T) -> Self { | ||
| MaybeUninit { inner: StdMaybeUninit::new(v) } | ||
| } | ||
| // Raw pointer casts written so that we don't reference or access the | ||
| // uninitialized interior value | ||
| /// Return a raw pointer to the start of the interior array | ||
| pub fn ptr(&self) -> *const T::Item | ||
| where T: Array | ||
| { | ||
| // std MaybeUninit creates a &self.value reference here which is | ||
| // not guaranteed to be sound in our case - we will partially | ||
| // initialize the value, not always wholly. | ||
| self.inner.as_ptr() as *const T::Item | ||
| } | ||
| /// Return a mut raw pointer to the start of the interior array | ||
| pub fn ptr_mut(&mut self) -> *mut T::Item | ||
| where T: Array | ||
| { | ||
| self.inner.as_mut_ptr() as *mut T::Item | ||
| } | ||
| } |
| { | ||
| "git": { | ||
| "sha1": "21661facf8f5d65b4bd6701e48d218eb957314fa" | ||
| "sha1": "97925027920f7a284774f76a48c3126297d2fd13" | ||
| } | ||
| } |
+3
-2
@@ -18,2 +18,3 @@ language: rust | ||
| - FEATURES='array-sizes-33-128 array-sizes-129-255' | ||
| - ARRAYVECTEST_ENSURE_MAYBEUNINIT=1 | ||
| - rust: beta | ||
@@ -27,3 +28,3 @@ - rust: nightly | ||
| - NODROP_FEATURES='use_needs_drop' | ||
| - ARRAYVECTEST_ENSURE_UNION=1 | ||
| - ARRAYVECTEST_ENSURE_MAYBEUNINIT=1 | ||
| - rust: nightly | ||
@@ -33,3 +34,3 @@ env: | ||
| - NODROP_FEATURES='use_union' | ||
| - ARRAYVECTEST_ENSURE_UNION=1 | ||
| - ARRAYVECTEST_ENSURE_MAYBEUNINIT=1 | ||
| branches: | ||
@@ -36,0 +37,0 @@ only: |
+16
-5
@@ -14,2 +14,7 @@ | ||
| fn detect_maybe_uninit() { | ||
| let has_stable_maybe_uninit = probe(&stable_maybe_uninit()); | ||
| if has_stable_maybe_uninit { | ||
| println!("cargo:rustc-cfg=has_stable_maybe_uninit"); | ||
| return; | ||
| } | ||
| let has_unstable_union_with_md = probe(&maybe_uninit_code(true)); | ||
@@ -19,9 +24,15 @@ if has_unstable_union_with_md { | ||
| println!("cargo:rustc-cfg=has_union_feature"); | ||
| return; | ||
| } | ||
| } | ||
| let has_stable_union_with_md = probe(&maybe_uninit_code(false)); | ||
| if has_stable_union_with_md { | ||
| println!("cargo:rustc-cfg=has_manually_drop_in_union"); | ||
| } | ||
| // To guard against changes in this currently unstable feature, use | ||
| // a detection tests instead of a Rustc version and/or date test. | ||
| fn stable_maybe_uninit() -> String { | ||
| let code = " | ||
| #![allow(warnings)] | ||
| use std::mem::MaybeUninit; | ||
| fn main() { } | ||
| "; | ||
| code.to_string() | ||
| } | ||
@@ -28,0 +39,0 @@ |
+2
-2
@@ -6,3 +6,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| # with all versions of Cargo and also rewrite `path` dependencies | ||
| # to registry (e.g. crates.io) dependencies | ||
| # to registry (e.g., crates.io) dependencies | ||
| # | ||
@@ -16,3 +16,3 @@ # If you believe there's an error in this file please file an | ||
| name = "arrayvec" | ||
| version = "0.4.10" | ||
| version = "0.4.11" | ||
| authors = ["bluss"] | ||
@@ -19,0 +19,0 @@ description = "A vector with fixed capacity, backed by an array (it can be stored on the stack too). Implements fixed capacity ArrayVec and ArrayString." |
+7
-0
@@ -25,2 +25,9 @@ | ||
| - 0.4.11 | ||
| - In Rust 1.36 or later, use newly stable MaybeUninit. This extends the | ||
| soundness work introduced in 0.4.9, we are finally able to use this in | ||
| stable. We use feature detection (build script) to enable this at build | ||
| time. | ||
| - 0.4.10 | ||
@@ -27,0 +34,0 @@ |
+5
-2
@@ -53,5 +53,8 @@ //! **arrayvec** provides the types `ArrayVec` and `ArrayString`: | ||
| #[cfg(has_manually_drop_in_union)] | ||
| #[cfg(has_stable_maybe_uninit)] | ||
| #[path="maybe_uninit_stable.rs"] | ||
| mod maybe_uninit; | ||
| #[cfg(not(has_manually_drop_in_union))] | ||
| #[cfg(all(not(has_stable_maybe_uninit), has_manually_drop_in_union))] | ||
| mod maybe_uninit; | ||
| #[cfg(all(not(has_stable_maybe_uninit), not(has_manually_drop_in_union)))] | ||
| #[path="maybe_uninit_nodrop.rs"] | ||
@@ -58,0 +61,0 @@ mod maybe_uninit; |
+3
-5
@@ -513,8 +513,6 @@ extern crate arrayvec; | ||
| #[test] | ||
| fn test_nightly_uses_maybe_uninit() { | ||
| if option_env!("ARRAYVECTEST_ENSURE_UNION").map(|s| !s.is_empty()).unwrap_or(false) { | ||
| assert!(cfg!(has_manually_drop_in_union)); | ||
| type ByteArray = ArrayVec<[u8; 4]>; | ||
| assert!(mem::size_of::<ByteArray>() == 5); | ||
| fn test_newish_stable_uses_maybe_uninit() { | ||
| if option_env!("ARRAYVECTEST_ENSURE_MAYBEUNINIT").map(|s| !s.is_empty()).unwrap_or(false) { | ||
| assert!(cfg!(has_stable_maybe_uninit)); | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet