]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_data_structures/sync.rs
Auto merge of #69833 - Centril:rollup-mh74yue, r=Centril
[rust.git] / src / librustc_data_structures / sync.rs
index 6a19f52897e5de97d976aaae88e5b954060b81f5..9051b1751b119426d2a6101dfe6ee867492834b1 100644 (file)
 //! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
 //! depending on the value of cfg!(parallel_compiler).
 
+use crate::owning_ref::{Erased, OwningRef};
 use std::collections::HashMap;
-use std::hash::{Hash, BuildHasher};
+use std::hash::{BuildHasher, Hash};
 use std::marker::PhantomData;
 use std::ops::{Deref, DerefMut};
-use crate::owning_ref::{Erased, OwningRef};
 
-pub use std::sync::atomic::Ordering::SeqCst;
 pub use std::sync::atomic::Ordering;
+pub use std::sync::atomic::Ordering::SeqCst;
 
 cfg_if! {
     if #[cfg(not(parallel_compiler))] {
@@ -203,11 +203,7 @@ pub fn par_iter<T: IntoIterator>(t: T) -> T::IntoIter {
             t.into_iter()
         }
 
-        pub fn par_for_each_in<T: IntoIterator>(
-            t: T,
-            for_each:
-                impl Fn(<<T as IntoIterator>::IntoIter as Iterator>::Item) + Sync + Send
-        ) {
+        pub fn par_for_each_in<T: IntoIterator>(t: T, for_each: impl Fn(T::Item) + Sync + Send) {
             // We catch panics here ensuring that all the loop iterations execute.
             // This makes behavior consistent with the parallel compiler.
             let mut panic = None;
@@ -397,9 +393,7 @@ pub fn par_iter<T: IntoParallelIterator>(t: T) -> T::Iter {
 
         pub fn par_for_each_in<T: IntoParallelIterator>(
             t: T,
-            for_each: impl Fn(
-                <<T as IntoParallelIterator>::Iter as ParallelIterator>::Item
-            ) + Sync + Send
+            for_each: impl Fn(T::Item) + Sync + Send,
         ) {
             t.into_par_iter().for_each(for_each)
         }
@@ -476,7 +470,10 @@ pub fn try_set(&self, value: T) -> Option<T> {
     /// otherwise if the inner value was already set it asserts that `value` is equal to the inner
     /// value and then returns `value` back to the caller
     #[inline]
-    pub fn try_set_same(&self, value: T) -> Option<T> where T: Eq {
+    pub fn try_set_same(&self, value: T) -> Option<T>
+    where
+        T: Eq,
+    {
         let mut lock = self.0.lock();
         if let Some(ref inner) = *lock {
             assert!(*inner == value);
@@ -518,11 +515,7 @@ pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> &T {
     /// If the value is already initialized, the closure is not called and `None` is returned.
     #[inline]
     pub fn init_nonlocking<F: FnOnce() -> T>(&self, f: F) -> Option<T> {
-        if self.0.lock().is_some() {
-            None
-        } else {
-            self.try_set(f())
-        }
+        if self.0.lock().is_some() { None } else { self.try_set(f()) }
     }
 
     /// Tries to initialize the inner value by calling the closure without ensuring that no-one
@@ -535,12 +528,11 @@ pub fn init_nonlocking<F: FnOnce() -> T>(&self, f: F) -> Option<T> {
     /// If our closure set the value, `None` is returned.
     /// If the value is already initialized, the closure is not called and `None` is returned.
     #[inline]
-    pub fn init_nonlocking_same<F: FnOnce() -> T>(&self, f: F) -> Option<T> where T: Eq {
-        if self.0.lock().is_some() {
-            None
-        } else {
-            self.try_set_same(f())
-        }
+    pub fn init_nonlocking_same<F: FnOnce() -> T>(&self, f: F) -> Option<T>
+    where
+        T: Eq,
+    {
+        if self.0.lock().is_some() { None } else { self.try_set_same(f()) }
     }
 
     /// Tries to get a reference to the inner value, returns `None` if it is not yet initialized