From 5fbdba080dcda6d267876b6784ac74982afc6426 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Tue, 17 Dec 2024 14:33:10 -0800 Subject: [PATCH] Use field init shorthand where possible Field init shorthand allows writing initializers like `tcx: tcx` as `tcx`. The compiler already uses it extensively. Fix the last few places where it isn't yet used. --- alloc/src/rc.rs | 2 +- alloc/src/sync.rs | 2 +- core/src/task/wake.rs | 2 +- std/src/sys/pal/hermit/fs.rs | 2 +- std/src/sys/pal/hermit/thread.rs | 2 +- std/src/sys/pal/hermit/time.rs | 2 +- std/src/sys/pal/sgx/fd.rs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/alloc/src/rc.rs b/alloc/src/rc.rs index bb27fe3c62dcd..b7ec3af9818a0 100644 --- a/alloc/src/rc.rs +++ b/alloc/src/rc.rs @@ -795,7 +795,7 @@ impl Rc { let uninit_ptr: NonNull<_> = (unsafe { &mut *uninit_raw_ptr }).into(); let init_ptr: NonNull> = uninit_ptr.cast(); - let weak = Weak { ptr: init_ptr, alloc: alloc }; + let weak = Weak { ptr: init_ptr, alloc }; // It's important we don't give up ownership of the weak pointer, or // else the memory might be freed by the time `data_fn` returns. If diff --git a/alloc/src/sync.rs b/alloc/src/sync.rs index 6cf41a3fa4e16..9be0b3e3e8801 100644 --- a/alloc/src/sync.rs +++ b/alloc/src/sync.rs @@ -784,7 +784,7 @@ impl Arc { let uninit_ptr: NonNull<_> = (unsafe { &mut *uninit_raw_ptr }).into(); let init_ptr: NonNull> = uninit_ptr.cast(); - let weak = Weak { ptr: init_ptr, alloc: alloc }; + let weak = Weak { ptr: init_ptr, alloc }; // It's important we don't give up ownership of the weak pointer, or // else the memory might be freed by the time `data_fn` returns. If diff --git a/core/src/task/wake.rs b/core/src/task/wake.rs index bfffcc24a46a2..ba429005fab3d 100644 --- a/core/src/task/wake.rs +++ b/core/src/task/wake.rs @@ -322,7 +322,7 @@ impl<'a> ContextBuilder<'a> { // SAFETY: LocalWaker is just Waker without thread safety let local_waker = unsafe { transmute(waker) }; Self { - waker: waker, + waker, local_waker, ext: ExtData::None(()), _marker: PhantomData, diff --git a/std/src/sys/pal/hermit/fs.rs b/std/src/sys/pal/hermit/fs.rs index 88fc40687195d..783623552bb17 100644 --- a/std/src/sys/pal/hermit/fs.rs +++ b/std/src/sys/pal/hermit/fs.rs @@ -135,7 +135,7 @@ impl FileAttr { S_IFREG => DT_REG, _ => DT_UNKNOWN, }; - FileType { mode: mode } + FileType { mode } } } diff --git a/std/src/sys/pal/hermit/thread.rs b/std/src/sys/pal/hermit/thread.rs index 2a0b8dcb4ed60..4a7afddbec107 100644 --- a/std/src/sys/pal/hermit/thread.rs +++ b/std/src/sys/pal/hermit/thread.rs @@ -43,7 +43,7 @@ impl Thread { } Err(io::const_error!(io::ErrorKind::Uncategorized, "Unable to create thread!")) } else { - Ok(Thread { tid: tid }) + Ok(Thread { tid }) }; extern "C" fn thread_start(main: usize) { diff --git a/std/src/sys/pal/hermit/time.rs b/std/src/sys/pal/hermit/time.rs index e0b6eb76b03af..f76a5f96c8750 100644 --- a/std/src/sys/pal/hermit/time.rs +++ b/std/src/sys/pal/hermit/time.rs @@ -22,7 +22,7 @@ impl Timespec { const fn new(tv_sec: i64, tv_nsec: i32) -> Timespec { assert!(tv_nsec >= 0 && tv_nsec < NSEC_PER_SEC); // SAFETY: The assert above checks tv_nsec is within the valid range - Timespec { t: timespec { tv_sec: tv_sec, tv_nsec: tv_nsec } } + Timespec { t: timespec { tv_sec, tv_nsec } } } fn sub_timespec(&self, other: &Timespec) -> Result { diff --git a/std/src/sys/pal/sgx/fd.rs b/std/src/sys/pal/sgx/fd.rs index c41b527cff798..3bb3189a1d127 100644 --- a/std/src/sys/pal/sgx/fd.rs +++ b/std/src/sys/pal/sgx/fd.rs @@ -12,7 +12,7 @@ pub struct FileDesc { impl FileDesc { pub fn new(fd: Fd) -> FileDesc { - FileDesc { fd: fd } + FileDesc { fd } } pub fn raw(&self) -> Fd {