Skip to content

Commit

Permalink
Use field init shorthand where possible
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshtriplett authored and gitbot committed Feb 22, 2025
1 parent 4291580 commit c5909d0
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ impl<T, A: Allocator> Rc<T, A> {
let uninit_ptr: NonNull<_> = (unsafe { &mut *uninit_raw_ptr }).into();
let init_ptr: NonNull<RcInner<T>> = 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
Expand Down
2 changes: 1 addition & 1 deletion alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ impl<T, A: Allocator> Arc<T, A> {
let uninit_ptr: NonNull<_> = (unsafe { &mut *uninit_raw_ptr }).into();
let init_ptr: NonNull<ArcInner<T>> = 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
Expand Down
2 changes: 1 addition & 1 deletion core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion std/src/sys/pal/hermit/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl FileAttr {
S_IFREG => DT_REG,
_ => DT_UNKNOWN,
};
FileType { mode: mode }
FileType { mode }
}
}

Expand Down
2 changes: 1 addition & 1 deletion std/src/sys/pal/hermit/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion std/src/sys/pal/hermit/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration, Duration> {
Expand Down
2 changes: 1 addition & 1 deletion std/src/sys/pal/sgx/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c5909d0

Please sign in to comment.