Skip to content

Commit 1fa794a

Browse files
authored
Use Self keyword instead of concrete type name (#2251)
1 parent 90b4a8e commit 1fa794a

File tree

109 files changed

+268
-268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+268
-268
lines changed

futures-channel/src/lock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ unsafe impl<T: Send> Sync for Lock<T> {}
3636

3737
impl<T> Lock<T> {
3838
/// Creates a new lock around the given value.
39-
pub(crate) fn new(t: T) -> Lock<T> {
40-
Lock {
39+
pub(crate) fn new(t: T) -> Self {
40+
Self {
4141
locked: AtomicBool::new(false),
4242
data: UnsafeCell::new(t),
4343
}

futures-channel/src/mpsc/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ struct SenderTask {
334334

335335
impl SenderTask {
336336
fn new() -> Self {
337-
SenderTask {
337+
Self {
338338
task: None,
339339
is_parked: false,
340340
}
@@ -665,7 +665,7 @@ impl<T> BoundedSenderInner<T> {
665665
/// Returns whether the sender send to this receiver.
666666
fn is_connected_to(&self, receiver: &Arc<BoundedInner<T>>) -> bool {
667667
Arc::ptr_eq(&self.inner, &receiver)
668-
}
668+
}
669669

670670
/// Returns pointer to the Arc containing sender
671671
///
@@ -896,19 +896,19 @@ impl<T> UnboundedSender<T> {
896896
}
897897

898898
impl<T> Clone for Sender<T> {
899-
fn clone(&self) -> Sender<T> {
900-
Sender(self.0.clone())
899+
fn clone(&self) -> Self {
900+
Self(self.0.clone())
901901
}
902902
}
903903

904904
impl<T> Clone for UnboundedSender<T> {
905-
fn clone(&self) -> UnboundedSender<T> {
906-
UnboundedSender(self.0.clone())
905+
fn clone(&self) -> Self {
906+
Self(self.0.clone())
907907
}
908908
}
909909

910910
impl<T> Clone for UnboundedSenderInner<T> {
911-
fn clone(&self) -> UnboundedSenderInner<T> {
911+
fn clone(&self) -> Self {
912912
// Since this atomic op isn't actually guarding any memory and we don't
913913
// care about any orderings besides the ordering on the single atomic
914914
// variable, a relaxed ordering is acceptable.
@@ -928,7 +928,7 @@ impl<T> Clone for UnboundedSenderInner<T> {
928928
// The ABA problem doesn't matter here. We only care that the
929929
// number of senders never exceeds the maximum.
930930
if actual == curr {
931-
return UnboundedSenderInner {
931+
return Self {
932932
inner: self.inner.clone(),
933933
};
934934
}
@@ -939,7 +939,7 @@ impl<T> Clone for UnboundedSenderInner<T> {
939939
}
940940

941941
impl<T> Clone for BoundedSenderInner<T> {
942-
fn clone(&self) -> BoundedSenderInner<T> {
942+
fn clone(&self) -> Self {
943943
// Since this atomic op isn't actually guarding any memory and we don't
944944
// care about any orderings besides the ordering on the single atomic
945945
// variable, a relaxed ordering is acceptable.
@@ -959,7 +959,7 @@ impl<T> Clone for BoundedSenderInner<T> {
959959
// The ABA problem doesn't matter here. We only care that the
960960
// number of senders never exceeds the maximum.
961961
if actual == curr {
962-
return BoundedSenderInner {
962+
return Self {
963963
inner: self.inner.clone(),
964964
sender_task: Arc::new(Mutex::new(SenderTask::new())),
965965
maybe_parked: false,

futures-channel/src/mpsc/queue.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(super) enum PopResult<T> {
6363

6464
#[derive(Debug)]
6565
struct Node<T> {
66-
next: AtomicPtr<Node<T>>,
66+
next: AtomicPtr<Self>,
6767
value: Option<T>,
6868
}
6969

@@ -80,8 +80,8 @@ unsafe impl<T: Send> Send for Queue<T> { }
8080
unsafe impl<T: Send> Sync for Queue<T> { }
8181

8282
impl<T> Node<T> {
83-
unsafe fn new(v: Option<T>) -> *mut Node<T> {
84-
Box::into_raw(Box::new(Node {
83+
unsafe fn new(v: Option<T>) -> *mut Self {
84+
Box::into_raw(Box::new(Self {
8585
next: AtomicPtr::new(ptr::null_mut()),
8686
value: v,
8787
}))
@@ -91,9 +91,9 @@ impl<T> Node<T> {
9191
impl<T> Queue<T> {
9292
/// Creates a new queue that is safe to share among multiple producers and
9393
/// one consumer.
94-
pub(super) fn new() -> Queue<T> {
94+
pub(super) fn new() -> Self {
9595
let stub = unsafe { Node::new(None) };
96-
Queue {
96+
Self {
9797
head: AtomicPtr::new(stub),
9898
tail: UnsafeCell::new(stub),
9999
}

futures-channel/src/mpsc/sink_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ impl<T> Sink<T> for UnboundedSender<T> {
4949
self: Pin<&mut Self>,
5050
cx: &mut Context<'_>,
5151
) -> Poll<Result<(), Self::Error>> {
52-
UnboundedSender::poll_ready(&*self, cx)
52+
Self::poll_ready(&*self, cx)
5353
}
5454

5555
fn start_send(
5656
mut self: Pin<&mut Self>,
5757
msg: T,
5858
) -> Result<(), Self::Error> {
59-
UnboundedSender::start_send(&mut *self, msg)
59+
Self::start_send(&mut *self, msg)
6060
}
6161

6262
fn poll_flush(

futures-channel/src/oneshot.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
116116
}
117117

118118
impl<T> Inner<T> {
119-
fn new() -> Inner<T> {
120-
Inner {
119+
fn new() -> Self {
120+
Self {
121121
complete: AtomicBool::new(false),
122122
data: Lock::new(None),
123123
rx_task: Lock::new(None),
@@ -366,7 +366,7 @@ impl<T> Sender<T> {
366366
/// [`Receiver`](Receiver) half has hung up.
367367
///
368368
/// This is a utility wrapping [`poll_canceled`](Sender::poll_canceled)
369-
/// to expose a [`Future`](core::future::Future).
369+
/// to expose a [`Future`](core::future::Future).
370370
pub fn cancellation(&mut self) -> Cancellation<'_, T> {
371371
Cancellation { inner: self }
372372
}

futures-core/src/future.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<F, T, E> TryFuture for F
7979
type Error = E;
8080

8181
#[inline]
82-
fn try_poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<F::Output> {
82+
fn try_poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
8383
self.poll(cx)
8484
}
8585
}

futures-core/src/task/__internal/atomic_waker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use core::task::Waker;
5353
///
5454
/// impl Flag {
5555
/// pub fn new() -> Self {
56-
/// Flag(Arc::new(Inner {
56+
/// Self(Arc::new(Inner {
5757
/// waker: AtomicWaker::new(),
5858
/// set: AtomicBool::new(false),
5959
/// }))
@@ -202,7 +202,7 @@ impl AtomicWaker {
202202
trait AssertSync: Sync {}
203203
impl AssertSync for Waker {}
204204

205-
AtomicWaker {
205+
Self {
206206
state: AtomicUsize::new(WAITING),
207207
waker: UnsafeCell::new(None),
208208
}
@@ -398,7 +398,7 @@ impl AtomicWaker {
398398

399399
impl Default for AtomicWaker {
400400
fn default() -> Self {
401-
AtomicWaker::new()
401+
Self::new()
402402
}
403403
}
404404

futures-executor/src/local_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ fn poll_executor<T, F: FnMut(&mut Context<'_>) -> T>(mut f: F) -> T {
118118

119119
impl LocalPool {
120120
/// Create a new, empty pool of tasks.
121-
pub fn new() -> LocalPool {
122-
LocalPool {
121+
pub fn new() -> Self {
122+
Self {
123123
pool: FuturesUnordered::new(),
124124
incoming: Default::default(),
125125
}

futures-executor/src/thread_pool.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl ThreadPool {
8080
/// See documentation for the methods in
8181
/// [`ThreadPoolBuilder`](ThreadPoolBuilder) for details on the default
8282
/// configuration.
83-
pub fn new() -> Result<ThreadPool, io::Error> {
83+
pub fn new() -> Result<Self, io::Error> {
8484
ThreadPoolBuilder::new().create()
8585
}
8686

@@ -168,9 +168,9 @@ impl PoolState {
168168
}
169169

170170
impl Clone for ThreadPool {
171-
fn clone(&self) -> ThreadPool {
171+
fn clone(&self) -> Self {
172172
self.state.cnt.fetch_add(1, Ordering::Relaxed);
173-
ThreadPool { state: self.state.clone() }
173+
Self { state: self.state.clone() }
174174
}
175175
}
176176

@@ -313,7 +313,7 @@ impl Task {
313313
/// Actually run the task (invoking `poll` on the future) on the current
314314
/// thread.
315315
fn run(self) {
316-
let Task { mut future, wake_handle, mut exec } = self;
316+
let Self { mut future, wake_handle, mut exec } = self;
317317
let waker = waker_ref(&wake_handle);
318318
let mut cx = Context::from_waker(&waker);
319319

@@ -328,7 +328,7 @@ impl Task {
328328
Poll::Pending => {}
329329
Poll::Ready(()) => return wake_handle.mutex.complete(),
330330
}
331-
let task = Task {
331+
let task = Self {
332332
future,
333333
wake_handle: wake_handle.clone(),
334334
exec,

futures-executor/src/unpark_mutex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ const REPOLL: usize = 2; // --> POLLING
4343
const COMPLETE: usize = 3; // No transitions out
4444

4545
impl<D> UnparkMutex<D> {
46-
pub(crate) fn new() -> UnparkMutex<D> {
47-
UnparkMutex {
46+
pub(crate) fn new() -> Self {
47+
Self {
4848
status: AtomicUsize::new(WAITING),
4949
inner: UnsafeCell::new(None),
5050
}

0 commit comments

Comments
 (0)