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

+2-2
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

+10-10
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

+5-5
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

+2-2
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

+3-3
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

+1-1
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

+3-3
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

+2-2
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

+5-5
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

+2-2
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
}

futures-macro/src/join.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct Join {
1313

1414
impl Parse for Join {
1515
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
16-
let mut join = Join::default();
16+
let mut join = Self::default();
1717

1818
while !input.is_empty() {
1919
join.fut_exprs.push(input.parse::<Expr>()?);

futures-macro/src/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ enum CaseKind {
2727

2828
impl Parse for Select {
2929
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
30-
let mut select = Select {
30+
let mut select = Self {
3131
complete: None,
3232
default: None,
3333
normal_fut_exprs: vec![],

futures-task/src/future_obj.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ unsafe fn remove_drop_lifetime<'a, T>(ptr: unsafe fn (*mut (dyn Future<Output =
4242
impl<'a, T> LocalFutureObj<'a, T> {
4343
/// Create a `LocalFutureObj` from a custom trait object representation.
4444
#[inline]
45-
pub fn new<F: UnsafeFutureObj<'a, T> + 'a>(f: F) -> LocalFutureObj<'a, T> {
46-
LocalFutureObj {
45+
pub fn new<F: UnsafeFutureObj<'a, T> + 'a>(f: F) -> Self {
46+
Self {
4747
future: unsafe { remove_future_lifetime(f.into_raw()) },
4848
drop_fn: unsafe { remove_drop_lifetime(F::drop) },
4949
_marker: PhantomData,
@@ -72,7 +72,7 @@ impl<T> fmt::Debug for LocalFutureObj<'_, T> {
7272

7373
impl<'a, T> From<FutureObj<'a, T>> for LocalFutureObj<'a, T> {
7474
#[inline]
75-
fn from(f: FutureObj<'a, T>) -> LocalFutureObj<'a, T> {
75+
fn from(f: FutureObj<'a, T>) -> Self {
7676
f.0
7777
}
7878
}
@@ -113,8 +113,8 @@ unsafe impl<T> Send for FutureObj<'_, T> {}
113113
impl<'a, T> FutureObj<'a, T> {
114114
/// Create a `FutureObj` from a custom trait object representation.
115115
#[inline]
116-
pub fn new<F: UnsafeFutureObj<'a, T> + Send>(f: F) -> FutureObj<'a, T> {
117-
FutureObj(LocalFutureObj::new(f))
116+
pub fn new<F: UnsafeFutureObj<'a, T> + Send>(f: F) -> Self {
117+
Self(LocalFutureObj::new(f))
118118
}
119119
}
120120

@@ -296,49 +296,49 @@ mod if_alloc {
296296

297297
impl<'a, F: Future<Output = ()> + Send + 'a> From<Box<F>> for FutureObj<'a, ()> {
298298
fn from(boxed: Box<F>) -> Self {
299-
FutureObj::new(boxed)
299+
Self::new(boxed)
300300
}
301301
}
302302

303303
impl<'a> From<Box<dyn Future<Output = ()> + Send + 'a>> for FutureObj<'a, ()> {
304304
fn from(boxed: Box<dyn Future<Output = ()> + Send + 'a>) -> Self {
305-
FutureObj::new(boxed)
305+
Self::new(boxed)
306306
}
307307
}
308308

309309
impl<'a, F: Future<Output = ()> + Send + 'a> From<Pin<Box<F>>> for FutureObj<'a, ()> {
310310
fn from(boxed: Pin<Box<F>>) -> Self {
311-
FutureObj::new(boxed)
311+
Self::new(boxed)
312312
}
313313
}
314314

315315
impl<'a> From<Pin<Box<dyn Future<Output = ()> + Send + 'a>>> for FutureObj<'a, ()> {
316316
fn from(boxed: Pin<Box<dyn Future<Output = ()> + Send + 'a>>) -> Self {
317-
FutureObj::new(boxed)
317+
Self::new(boxed)
318318
}
319319
}
320320

321321
impl<'a, F: Future<Output = ()> + 'a> From<Box<F>> for LocalFutureObj<'a, ()> {
322322
fn from(boxed: Box<F>) -> Self {
323-
LocalFutureObj::new(boxed)
323+
Self::new(boxed)
324324
}
325325
}
326326

327327
impl<'a> From<Box<dyn Future<Output = ()> + 'a>> for LocalFutureObj<'a, ()> {
328328
fn from(boxed: Box<dyn Future<Output = ()> + 'a>) -> Self {
329-
LocalFutureObj::new(boxed)
329+
Self::new(boxed)
330330
}
331331
}
332332

333333
impl<'a, F: Future<Output = ()> + 'a> From<Pin<Box<F>>> for LocalFutureObj<'a, ()> {
334334
fn from(boxed: Pin<Box<F>>) -> Self {
335-
LocalFutureObj::new(boxed)
335+
Self::new(boxed)
336336
}
337337
}
338338

339339
impl<'a> From<Pin<Box<dyn Future<Output = ()> + 'a>>> for LocalFutureObj<'a, ()> {
340340
fn from(boxed: Pin<Box<dyn Future<Output = ()> + 'a>>) -> Self {
341-
LocalFutureObj::new(boxed)
341+
Self::new(boxed)
342342
}
343343
}
344344
}

futures-task/src/waker_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'a> WakerRef<'a> {
2222
// copy the underlying (raw) waker without calling a clone,
2323
// as we won't call Waker::drop either.
2424
let waker = ManuallyDrop::new(unsafe { core::ptr::read(waker) });
25-
WakerRef {
25+
Self {
2626
waker,
2727
_marker: PhantomData,
2828
}
@@ -35,7 +35,7 @@ impl<'a> WakerRef<'a> {
3535
/// by the caller), and the [`Waker`] doesn't need to or must not be
3636
/// destroyed.
3737
pub fn new_unowned(waker: ManuallyDrop<Waker>) -> Self {
38-
WakerRef {
38+
Self {
3939
waker,
4040
_marker: PhantomData,
4141
}

futures-test/src/assert_unmoved.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::thread::panicking;
2424
pub struct AssertUnmoved<T> {
2525
#[pin]
2626
inner: T,
27-
this_ptr: *const AssertUnmoved<T>,
27+
this_ptr: *const Self,
2828
}
2929

3030
// Safety: having a raw pointer in a struct makes it `!Send`, however the

futures-test/src/io/limited.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub struct Limited<Io> {
2121
}
2222

2323
impl<Io> Limited<Io> {
24-
pub(crate) fn new(io: Io, limit: usize) -> Limited<Io> {
25-
Limited { io, limit }
24+
pub(crate) fn new(io: Io, limit: usize) -> Self {
25+
Self { io, limit }
2626
}
2727

2828
/// Acquires a reference to the underlying I/O object that this adaptor is

0 commit comments

Comments
 (0)