]> git.lizzy.rs Git - rust.git/commitdiff
add comments explaining our uses of get_ref/get_mut for MaybeUninit
authorRalf Jung <post@ralfj.de>
Tue, 27 Nov 2018 15:12:08 +0000 (16:12 +0100)
committerRalf Jung <post@ralfj.de>
Tue, 27 Nov 2018 15:12:08 +0000 (16:12 +0100)
src/libcore/fmt/float.rs
src/libcore/mem.rs
src/libstd/sys/windows/mutex.rs

index d01cd012031db45cbb99f4d51c008d8eba174fc1..0c1ac90dfd2d7315d281ed276fa758ca3587a929 100644 (file)
@@ -22,6 +22,9 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter, num: &T,
     unsafe {
         let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64
         let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized();
+        // FIXME: Technically, this is calling `get_mut` on an uninitialized
+        // `MaybeUninit` (here and elsewhere in this file).  Revisit this once
+        // we decided whether that is valid or not.
         let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
                                                     *num, sign, precision,
                                                     false, buf.get_mut(), parts.get_mut());
index a5603ff6a62e7e28b0fd50c96749fd4c624bac70..626db7806dfe4e97c6fe971af970caddac46c698 100644 (file)
@@ -1106,6 +1106,9 @@ pub unsafe fn into_inner(self) -> T {
     ///
     /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized
     /// state, otherwise this will immediately cause undefined behavior.
+    // FIXME: We currently rely on the above being incorrect, i.e., we have references
+    // to uninitialized data (e.g. in `libstd/sys/windows/mutex.rs`).  We should make
+    // a final decision about the rules before stabilization.
     #[unstable(feature = "maybe_uninit", issue = "53491")]
     #[inline(always)]
     pub unsafe fn get_ref(&self) -> &T {
@@ -1118,6 +1121,9 @@ pub unsafe fn get_ref(&self) -> &T {
     ///
     /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized
     /// state, otherwise this will immediately cause undefined behavior.
+    // FIXME: We currently rely on the above being incorrect, i.e., we have references
+    // to uninitialized data (e.g. in `libcore/fmt/float.rs`).  We should make
+    // a final decision about the rules before stabilization.
     #[unstable(feature = "maybe_uninit", issue = "53491")]
     #[inline(always)]
     pub unsafe fn get_mut(&mut self) -> &mut T {
index a8eb82a8a6649179ce4bdd42f72ae92a9c2b4f9b..0c228f5097ee33a3fa3a99f2d2216ae70f538c53 100644 (file)
@@ -168,6 +168,9 @@ pub fn uninitialized() -> ReentrantMutex {
     }
 
     pub unsafe fn init(&mut self) {
+        // FIXME: Technically, this is calling `get_ref` on an uninitialized
+        // `MaybeUninit`.  Revisit this once we decided whether that is valid
+        // or not.
         c::InitializeCriticalSection(self.inner.get_ref().get());
     }