authorbors <bors@rust-lang.org> 2024-12-18 19:16:15 UTC
committerbors <bors@rust-lang.org> 2024-12-18 19:16:15 UTC
log4ba4ac612d36e3409e8e1e31e12acc028808f85f
tree4984f3ca5507abb2a5ccd2aad7346390edff999f
parenta52085d9f6a6e596b0cbad4502cddf86bc878028
parenta105cd606628b07e79ab343cc183a176e278c809

Auto merge of #134443 - joshtriplett:use-field-init-shorthand, r=lqd,tgross35,nnethercote

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. EDIT: this PR also updates `rustfmt.toml` to set `use_field_init_shorthand = true`.

17 files changed, 17 insertions(+), 16 deletions(-)

compiler/rustc_const_eval/src/interpret/projection.rs+1-1
......@@ -325,7 +325,7 @@ where
325325 let actual_to = if from_end {
326326 if from.checked_add(to).is_none_or(|to| to > len) {
327327 // This can only be reached in ConstProp and non-rustc-MIR.
328 throw_ub!(BoundsCheckFailed { len: len, index: from.saturating_add(to) });
328 throw_ub!(BoundsCheckFailed { len, index: from.saturating_add(to) });
329329 }
330330 len.checked_sub(to).unwrap()
331331 } else {
compiler/rustc_lint/src/impl_trait_overcaptures.rs+1-1
......@@ -177,7 +177,7 @@ fn check_fn(tcx: TyCtxt<'_>, parent_def_id: LocalDefId) {
177177 // Lazily compute these two, since they're likely a bit expensive.
178178 variances: LazyCell::new(|| {
179179 let mut functional_variances = FunctionalVariances {
180 tcx: tcx,
180 tcx,
181181 variances: FxHashMap::default(),
182182 ambient_variance: ty::Covariant,
183183 generics: tcx.generics_of(parent_def_id),
compiler/rustc_parse/src/parser/pat.rs+1-1
......@@ -1647,7 +1647,7 @@ impl<'a> Parser<'a> {
16471647 ident: prev_field,
16481648 })
16491649 } else {
1650 self.dcx().create_err(AtInStructPattern { span: span })
1650 self.dcx().create_err(AtInStructPattern { span })
16511651 }
16521652 }
16531653
compiler/rustc_type_ir/src/elaborate.rs+1-1
......@@ -72,7 +72,7 @@ impl<I: Interner> Elaboratable<I> for ClauseWithSupertraitSpan<I> {
7272 _parent_trait_pred: crate::Binder<I, crate::TraitPredicate<I>>,
7373 _index: usize,
7474 ) -> Self {
75 ClauseWithSupertraitSpan { pred: clause.as_predicate(), supertrait_span: supertrait_span }
75 ClauseWithSupertraitSpan { pred: clause.as_predicate(), supertrait_span }
7676 }
7777}
7878
library/alloc/src/rc.rs+1-1
......@@ -795,7 +795,7 @@ impl<T, A: Allocator> Rc<T, A> {
795795 let uninit_ptr: NonNull<_> = (unsafe { &mut *uninit_raw_ptr }).into();
796796 let init_ptr: NonNull<RcInner<T>> = uninit_ptr.cast();
797797
798 let weak = Weak { ptr: init_ptr, alloc: alloc };
798 let weak = Weak { ptr: init_ptr, alloc };
799799
800800 // It's important we don't give up ownership of the weak pointer, or
801801 // else the memory might be freed by the time `data_fn` returns. If
library/alloc/src/sync.rs+1-1
......@@ -784,7 +784,7 @@ impl<T, A: Allocator> Arc<T, A> {
784784 let uninit_ptr: NonNull<_> = (unsafe { &mut *uninit_raw_ptr }).into();
785785 let init_ptr: NonNull<ArcInner<T>> = uninit_ptr.cast();
786786
787 let weak = Weak { ptr: init_ptr, alloc: alloc };
787 let weak = Weak { ptr: init_ptr, alloc };
788788
789789 // It's important we don't give up ownership of the weak pointer, or
790790 // else the memory might be freed by the time `data_fn` returns. If
library/core/src/task/wake.rs+1-1
......@@ -322,7 +322,7 @@ impl<'a> ContextBuilder<'a> {
322322 // SAFETY: LocalWaker is just Waker without thread safety
323323 let local_waker = unsafe { transmute(waker) };
324324 Self {
325 waker: waker,
325 waker,
326326 local_waker,
327327 ext: ExtData::None(()),
328328 _marker: PhantomData,
library/std/src/sys/pal/hermit/fs.rs+1-1
......@@ -135,7 +135,7 @@ impl FileAttr {
135135 S_IFREG => DT_REG,
136136 _ => DT_UNKNOWN,
137137 };
138 FileType { mode: mode }
138 FileType { mode }
139139 }
140140}
141141
library/std/src/sys/pal/hermit/thread.rs+1-1
......@@ -43,7 +43,7 @@ impl Thread {
4343 }
4444 Err(io::const_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))
4545 } else {
46 Ok(Thread { tid: tid })
46 Ok(Thread { tid })
4747 };
4848
4949 extern "C" fn thread_start(main: usize) {
library/std/src/sys/pal/hermit/time.rs+1-1
......@@ -22,7 +22,7 @@ impl Timespec {
2222 const fn new(tv_sec: i64, tv_nsec: i32) -> Timespec {
2323 assert!(tv_nsec >= 0 && tv_nsec < NSEC_PER_SEC);
2424 // SAFETY: The assert above checks tv_nsec is within the valid range
25 Timespec { t: timespec { tv_sec: tv_sec, tv_nsec: tv_nsec } }
25 Timespec { t: timespec { tv_sec, tv_nsec } }
2626 }
2727
2828 fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> {
library/std/src/sys/pal/sgx/fd.rs+1-1
......@@ -12,7 +12,7 @@ pub struct FileDesc {
1212
1313impl FileDesc {
1414 pub fn new(fd: Fd) -> FileDesc {
15 FileDesc { fd: fd }
15 FileDesc { fd }
1616 }
1717
1818 pub fn raw(&self) -> Fd {
rustfmt.toml+1
......@@ -4,6 +4,7 @@ use_small_heuristics = "Max"
44merge_derives = false
55group_imports = "StdExternalCrate"
66imports_granularity = "Module"
7use_field_init_shorthand = true
78
89# Files to ignore. Each entry uses gitignore syntax, but `!` prefixes aren't allowed.
910ignore = [
src/tools/compiletest/src/read2.rs+1-1
......@@ -286,7 +286,7 @@ mod imp {
286286 impl<'a> Pipe<'a> {
287287 unsafe fn new<P: IntoRawHandle>(p: P, dst: &'a mut Vec<u8>) -> Pipe<'a> {
288288 Pipe {
289 dst: dst,
289 dst,
290290 pipe: NamedPipe::from_raw_handle(p.into_raw_handle()),
291291 overlapped: Overlapped::zero(),
292292 done: false,
tests/codegen-units/item-collection/generic-impl.rs+1-1
......@@ -14,7 +14,7 @@ fn id<T>(x: T) -> T {
1414
1515impl<T> Struct<T> {
1616 fn new(x: T) -> Struct<T> {
17 Struct { x: x, f: id }
17 Struct { x, f: id }
1818 }
1919
2020 fn get<T2>(self, x: T2) -> (T, T2) {
tests/codegen/issues/issue-15953.rs+1-1
......@@ -9,7 +9,7 @@ struct Foo {
99#[no_mangle]
1010// CHECK: memcpy
1111fn interior(x: Vec<i32>) -> Vec<i32> {
12 let Foo { x } = Foo { x: x };
12 let Foo { x } = Foo { x };
1313 x
1414}
1515
tests/run-make/extern-fn-struct-passing-abi/test.rs+1-1
......@@ -126,7 +126,7 @@ extern "C" {
126126
127127fn main() {
128128 let s = Rect { a: 553, b: 554, c: 555, d: 556 };
129 let t = BiggerRect { s: s, a: 27834, b: 7657 };
129 let t = BiggerRect { s, a: 27834, b: 7657 };
130130 let u = FloatRect { a: 3489, b: 3490, c: 8. };
131131 let v = Huge { a: 5647, b: 5648, c: 5649, d: 5650, e: 5651 };
132132 let w = Huge64 { a: 1234, b: 1335, c: 1436, d: 1537, e: 1638 };
tests/run-make/symbols-include-type-name/lib.rs+1-1
......@@ -4,7 +4,7 @@ pub struct Def {
44
55impl Def {
66 pub fn new(id: i32) -> Def {
7 Def { id: id }
7 Def { id }
88 }
99}
1010