chore(rustfmt): use nightly (#2325)

Stable rustfmt lacks a lot of features resulting in worse formatted
code, thus use nightly formatter.
This commit is contained in:
Kirill Chibisov 2024-04-26 19:11:44 +04:00 committed by GitHub
parent 7006c7ceca
commit 7b0c7b6cb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
154 changed files with 3439 additions and 5891 deletions

View file

@ -19,10 +19,7 @@ pub struct Abortable<F: Future> {
impl<F: Future> Abortable<F> {
pub fn new(handle: AbortHandle, future: F) -> Self {
Self {
future,
shared: handle.0,
}
Self { future, shared: handle.0 }
}
}
@ -59,10 +56,7 @@ pub struct AbortHandle(Arc<Shared>);
impl AbortHandle {
pub fn new() -> Self {
Self(Arc::new(Shared {
waker: AtomicWaker::new(),
aborted: AtomicBool::new(false),
}))
Self(Arc::new(Shared { waker: AtomicWaker::new(), aborted: AtomicBool::new(false) }))
}
pub fn abort(&self) {

View file

@ -9,19 +9,11 @@ use super::AtomicWaker;
pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
let (sender, receiver) = mpsc::channel();
let shared = Arc::new(Shared {
closed: AtomicBool::new(false),
waker: AtomicWaker::new(),
});
let shared = Arc::new(Shared { closed: AtomicBool::new(false), waker: AtomicWaker::new() });
let sender = Sender(Arc::new(SenderInner {
sender: Mutex::new(sender),
shared: Arc::clone(&shared),
}));
let receiver = Receiver {
receiver: Rc::new(receiver),
shared,
};
let sender =
Sender(Arc::new(SenderInner { sender: Mutex::new(sender), shared: Arc::clone(&shared) }));
let receiver = Receiver { receiver: Rc::new(receiver), shared };
(sender, receiver)
}
@ -85,10 +77,10 @@ impl<T> Receiver<T> {
} else {
Poll::Pending
}
}
},
Err(TryRecvError::Disconnected) => Poll::Ready(Err(RecvError)),
}
}
},
Err(TryRecvError::Disconnected) => Poll::Ready(Err(RecvError)),
})
.await
@ -105,10 +97,7 @@ impl<T> Receiver<T> {
impl<T> Clone for Receiver<T> {
fn clone(&self) -> Self {
Self {
receiver: Rc::clone(&self.receiver),
shared: Arc::clone(&self.shared),
}
Self { receiver: Rc::clone(&self.receiver), shared: Arc::clone(&self.shared) }
}
}

View file

@ -19,10 +19,7 @@ pub enum PopError {
impl<T> ConcurrentQueue<T> {
pub fn unbounded() -> Self {
Self {
queue: RefCell::new(Vec::new()),
closed: Cell::new(false),
}
Self { queue: RefCell::new(Vec::new()), closed: Cell::new(false) }
}
pub fn push(&self, value: T) -> Result<(), PushError<T>> {

View file

@ -1,9 +1,7 @@
use super::super::main_thread::MainThreadMarker;
use super::{channel, Receiver, Sender, Wrapper};
use std::{
cell::Ref,
sync::{Arc, Condvar, Mutex},
};
use std::cell::Ref;
use std::sync::{Arc, Condvar, Mutex};
pub struct Dispatcher<T: 'static>(Wrapper<T, Sender<Closure<T>>, Closure<T>>);
@ -18,24 +16,25 @@ impl<T> Dispatcher<T> {
main_thread,
value,
|value, Closure(closure)| {
// SAFETY: The given `Closure` here isn't really `'static`, so we shouldn't do anything
// funny with it here. See `Self::queue()`.
// SAFETY: The given `Closure` here isn't really `'static`, so we shouldn't do
// anything funny with it here. See `Self::queue()`.
closure(value.borrow().as_ref().unwrap())
},
{
let receiver = receiver.clone();
move |value| async move {
while let Ok(Closure(closure)) = receiver.next().await {
// SAFETY: The given `Closure` here isn't really `'static`, so we shouldn't do anything
// funny with it here. See `Self::queue()`.
// SAFETY: The given `Closure` here isn't really `'static`, so we shouldn't
// do anything funny with it here. See
// `Self::queue()`.
closure(value.borrow().as_ref().unwrap())
}
}
},
sender,
|sender, closure| {
// SAFETY: The given `Closure` here isn't really `'static`, so we shouldn't do anything
// funny with it here. See `Self::queue()`.
// SAFETY: The given `Closure` here isn't really `'static`, so we shouldn't do
// anything funny with it here. See `Self::queue()`.
sender.send(closure).unwrap()
},
)
@ -91,19 +90,12 @@ pub struct DispatchRunner<T: 'static> {
impl<T> DispatchRunner<T> {
pub fn run(&self) {
while let Some(Closure(closure)) = self
.receiver
.try_recv()
.expect("should only be closed when `Dispatcher` is dropped")
while let Some(Closure(closure)) =
self.receiver.try_recv().expect("should only be closed when `Dispatcher` is dropped")
{
// SAFETY: The given `Closure` here isn't really `'static`, so we shouldn't do anything
// funny with it here. See `Self::queue()`.
closure(
&self
.wrapper
.value()
.expect("don't call this outside the main thread"),
)
closure(&self.wrapper.value().expect("don't call this outside the main thread"))
}
}
}

View file

@ -1,10 +1,7 @@
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::sync::OnceLock;
use std::task::Context;
use std::task::Poll;
use std::task::Waker;
use std::sync::{Arc, OnceLock};
use std::task::{Context, Poll, Waker};
use super::{ConcurrentQueue, PushError};
@ -13,10 +10,7 @@ pub struct Notifier<T: Clone>(Arc<Inner<T>>);
impl<T: Clone> Notifier<T> {
pub fn new() -> Self {
Self(Arc::new(Inner {
queue: ConcurrentQueue::unbounded(),
value: OnceLock::new(),
}))
Self(Arc::new(Inner { queue: ConcurrentQueue::unbounded(), value: OnceLock::new() }))
}
pub fn notify(self, value: T) {
@ -52,11 +46,11 @@ impl<T: Clone> Future for Notified<T> {
self.0 = Some(this);
return Poll::Pending;
}
}
},
Err(PushError::Closed(_)) => (),
Err(PushError::Full(_)) => {
unreachable!("found full queue despite using unbounded queue")
}
},
}
}

View file

@ -92,8 +92,7 @@ impl<T> WakerSpawner<T> {
"this should only be called from the main thread"
);
self.0
.with_sender_data(|inner| inner.0.counter.swap(0, Ordering::Relaxed))
self.0.with_sender_data(|inner| inner.0.counter.swap(0, Ordering::Relaxed))
}
}

View file

@ -17,10 +17,9 @@ struct Value<V> {
// SAFETY:
// This value must not be accessed if not on the main thread.
//
// - We wrap this in an `Arc` to allow it to be safely cloned without
// accessing the value.
// - The `RefCell` lets us mutably access in the main thread but is safe to
// drop in any thread because it has no `Drop` behavior.
// - We wrap this in an `Arc` to allow it to be safely cloned without accessing the value.
// - The `RefCell` lets us mutably access in the main thread but is safe to drop in any thread
// because it has no `Drop` behavior.
// - The `Option` lets us safely drop `T` only in the main thread.
value: Arc<RefCell<Option<V>>>,
// Prevent's `Send` or `Sync` to be automatically implemented.
@ -53,10 +52,7 @@ impl<V, S: Clone + Send, E> Wrapper<V, S, E> {
});
Some(Self {
value: Value {
value,
local: PhantomData,
},
value: Value { value, local: PhantomData },
handler,
sender_data,
sender_handler,
@ -84,10 +80,7 @@ impl<V, S: Clone + Send, E> Wrapper<V, S, E> {
impl<V, S: Clone + Send, E> Clone for Wrapper<V, S, E> {
fn clone(&self) -> Self {
Self {
value: Value {
value: self.value.value.clone(),
local: PhantomData,
},
value: Value { value: self.value.value.clone(), local: PhantomData },
handler: self.handler,
sender_data: self.sender_data.clone(),
sender_handler: self.sender_handler,