Snap for 6877830 from a120c7727cbd37fbae8c169fec15acc52d35bb2a to sdk-release

Change-Id: I2cfb8762ff2f9f55a7844f510a95d6918e895904
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 262cf9e..afdaae2 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "311c33480fbd8b56b0d3db081a0e328b199e2b9c"
+    "sha1": "d6b9907273d20bd3d1aa26f74d358b483469d122"
   }
 }
diff --git a/.gitignore b/.gitignore
index 6936990..ff0d847 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
 /target
-**/*.rs.bk
+/.vscode
 Cargo.lock
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 02fe9ee..de5e795 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
 # Changelog
 
+## 1.4.1
+
+- upgrade `parking_lot` to `0.11.0`
+- make `sync::OnceCell<T>` pass https://doc.rust-lang.org/nomicon/dropck.html#an-escape-hatch[dropck] with `parking_lot` feature enabled.
+  This fixes a (minor) semver-incompatible changed introduced in `1.4.0`
+
 ## 1.4.0
 
 - upgrade `parking_lot` to `0.10` (note that this bumps MSRV with `parking_lot` feature enabled to `1.36.0`).
diff --git a/Cargo.toml b/Cargo.toml
index e2c2279..b505be3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
 [package]
 edition = "2018"
 name = "once_cell"
-version = "1.4.0"
+version = "1.4.1"
 authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
 exclude = ["*.png", "*.svg", "/Cargo.lock.min", "/.travis.yml", "/run-miri-tests.sh", "rustfmt.toml"]
 description = "Single assignment cells and lazy values."
@@ -52,7 +52,7 @@
 name = "test_synchronization"
 required-features = ["std"]
 [dependencies.parking_lot]
-version = "0.10.0"
+version = "0.11"
 optional = true
 default_features = false
 [dev-dependencies.crossbeam-utils]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index f11573e..7768b12 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "once_cell"
-version = "1.4.0"
+version = "1.4.1"
 authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
 license = "MIT OR Apache-2.0"
 edition = "2018"
@@ -19,7 +19,7 @@
 # Uses parking_lot to implement once_cell::sync::OnceCell.
 # This makes not speed difference, but makes each OnceCell<T>
 # for up to two bytes smaller, depending on the size of the T.
-parking_lot = { version = "0.10.0", optional = true, default_features = false }
+parking_lot = { version = "0.11", optional = true, default_features = false }
 
 [dev-dependencies]
 lazy_static = "1.0.0"
diff --git a/METADATA b/METADATA
index bf87c4a..01cc916 100644
--- a/METADATA
+++ b/METADATA
@@ -6,14 +6,14 @@
     value: "https://crates.io/crates/once_cell"
   }
   url {
-    type: GIT
-    value: "https://github.com/matklad/once_cell"
+    type: ARCHIVE
+    value: "https://static.crates.io/crates/once_cell/once_cell-1.4.1.crate"
   }
-  version: "1.4.0"
+  version: "1.4.1"
   license_type: NOTICE
   last_upgrade_date {
     year: 2020
-    month: 5
-    day: 18
+    month: 8
+    day: 17
   }
 }
diff --git a/src/imp_pl.rs b/src/imp_pl.rs
index 5885e77..ed426b1 100644
--- a/src/imp_pl.rs
+++ b/src/imp_pl.rs
@@ -1,17 +1,16 @@
 use std::{
     cell::UnsafeCell,
-    mem::{self, MaybeUninit},
+    hint,
     panic::{RefUnwindSafe, UnwindSafe},
-    ptr,
     sync::atomic::{AtomicBool, Ordering},
 };
 
-use parking_lot::{lock_api::RawMutex as _RawMutex, RawMutex};
+use parking_lot::Mutex;
 
 pub(crate) struct OnceCell<T> {
-    mutex: Mutex,
+    mutex: Mutex<()>,
     is_initialized: AtomicBool,
-    value: UnsafeCell<MaybeUninit<T>>,
+    value: UnsafeCell<Option<T>>,
 }
 
 // Why do we need `T: Send`?
@@ -28,9 +27,9 @@
 impl<T> OnceCell<T> {
     pub(crate) const fn new() -> OnceCell<T> {
         OnceCell {
-            mutex: Mutex::new(),
+            mutex: parking_lot::const_mutex(()),
             is_initialized: AtomicBool::new(false),
-            value: UnsafeCell::new(MaybeUninit::uninit()),
+            value: UnsafeCell::new(None),
         }
     }
 
@@ -60,7 +59,9 @@
             let value = f()?;
             // Safe b/c we have a unique access and no panic may happen
             // until the cell is marked as initialized.
-            unsafe { self.as_mut_ptr().write(value) };
+            let slot: &mut Option<T> = unsafe { &mut *self.value.get() };
+            debug_assert!(slot.is_none());
+            *slot = Some(value);
             self.is_initialized.store(true, Ordering::Release);
         }
         Ok(())
@@ -75,84 +76,29 @@
     /// the contents are acquired by (synchronized to) this thread.
     pub(crate) unsafe fn get_unchecked(&self) -> &T {
         debug_assert!(self.is_initialized());
-        &*self.as_ptr()
+        let slot: &Option<T> = &*self.value.get();
+        match slot {
+            Some(value) => value,
+            // This unsafe does improve performance, see `examples/bench`.
+            None => {
+                debug_assert!(false);
+                hint::unreachable_unchecked()
+            }
+        }
     }
 
     /// Gets the mutable reference to the underlying value.
     /// Returns `None` if the cell is empty.
     pub(crate) fn get_mut(&mut self) -> Option<&mut T> {
-        if self.is_initialized() {
-            // Safe b/c we have a unique access and value is initialized.
-            Some(unsafe { &mut *self.as_mut_ptr() })
-        } else {
-            None
-        }
+        // Safe b/c we have an exclusive access
+        let slot: &mut Option<T> = unsafe { &mut *self.value.get() };
+        slot.as_mut()
     }
 
     /// Consumes this `OnceCell`, returning the wrapped value.
     /// Returns `None` if the cell was empty.
     pub(crate) fn into_inner(self) -> Option<T> {
-        if !self.is_initialized() {
-            return None;
-        }
-
-        // Safe b/c we have a unique access and value is initialized.
-        let value: T = unsafe { ptr::read(self.as_ptr()) };
-
-        // It's OK to `mem::forget` without dropping, because both `self.mutex`
-        // and `self.is_initialized` are not heap-allocated.
-        mem::forget(self);
-
-        Some(value)
-    }
-
-    fn as_ptr(&self) -> *const T {
-        unsafe {
-            let slot: &MaybeUninit<T> = &*self.value.get();
-            slot.as_ptr()
-        }
-    }
-
-    fn as_mut_ptr(&self) -> *mut T {
-        unsafe {
-            let slot: &mut MaybeUninit<T> = &mut *self.value.get();
-            slot.as_mut_ptr()
-        }
-    }
-}
-
-impl<T> Drop for OnceCell<T> {
-    fn drop(&mut self) {
-        if self.is_initialized() {
-            // Safe b/c we have a unique access and value is initialized.
-            unsafe { ptr::drop_in_place(self.as_mut_ptr()) };
-        }
-    }
-}
-
-/// Wrapper around parking_lot's `RawMutex` which has `const fn` new.
-struct Mutex {
-    inner: RawMutex,
-}
-
-impl Mutex {
-    const fn new() -> Mutex {
-        Mutex { inner: RawMutex::INIT }
-    }
-
-    fn lock(&self) -> MutexGuard<'_> {
-        self.inner.lock();
-        MutexGuard { inner: &self.inner }
-    }
-}
-
-struct MutexGuard<'a> {
-    inner: &'a RawMutex,
-}
-
-impl Drop for MutexGuard<'_> {
-    fn drop(&mut self) {
-        self.inner.unlock();
+        self.value.into_inner()
     }
 }
 
diff --git a/src/lib.rs b/src/lib.rs
index 90a3c6b..fd36471 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,7 +3,7 @@
 
 `once_cell` provides two new cell-like types, [`unsync::OnceCell`] and [`sync::OnceCell`]. A `OnceCell`
 might store arbitrary non-`Copy` types, can be assigned to at most once and provides direct access
-to the stored contents. In a nutshell, the API looks *roughly* like this:
+to the stored contents. The core API looks *roughly* like this (and there's much more inside, read on!):
 
 ```rust,ignore
 impl<T> OnceCell<T> {
@@ -20,7 +20,7 @@
 The `sync` flavor is thread-safe (that is, implements the [`Sync`] trait), while the `unsync` one is not.
 
 [`unsync::OnceCell`]: unsync/struct.OnceCell.html
-[`sync::OnceCell`]: sync/struct.ONceCell.html
+[`sync::OnceCell`]: sync/struct.OnceCell.html
 [`RefCell`]: https://doc.rust-lang.org/std/cell/struct.RefCell.html
 [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
 [`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
diff --git a/tests/test.rs b/tests/test.rs
index c1351a7..18c86fe 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -186,6 +186,16 @@
         });
         eprintln!("use after free: {:?}", dangling_ref.get().unwrap());
     }
+
+    #[test]
+    // https://github.com/rust-lang/rust/issues/34761#issuecomment-256320669
+    fn arrrrrrrrrrrrrrrrrrrrrr() {
+        let cell = OnceCell::new();
+        {
+            let s = String::new();
+            cell.set(&s).unwrap();
+        }
+    }
 }
 
 #[cfg(feature = "std")]
@@ -572,4 +582,14 @@
         .unwrap();
         assert_eq!(cell.get(), Some(&"hello".to_string()));
     }
+
+    #[test]
+    // https://github.com/rust-lang/rust/issues/34761#issuecomment-256320669
+    fn arrrrrrrrrrrrrrrrrrrrrr() {
+        let cell = OnceCell::new();
+        {
+            let s = String::new();
+            cell.set(&s).unwrap();
+        }
+    }
 }