| author | bors <bors@rust-lang.org> 2024-12-18 19:16:15 UTC |
| committer | bors <bors@rust-lang.org> 2024-12-18 19:16:15 UTC |
| log | 4ba4ac612d36e3409e8e1e31e12acc028808f85f |
| tree | 4984f3ca5507abb2a5ccd2aad7346390edff999f |
| parent | a52085d9f6a6e596b0cbad4502cddf86bc878028 |
| parent | a105cd606628b07e79ab343cc183a176e278c809 |
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 |
| 325 | 325 | let actual_to = if from_end { |
| 326 | 326 | if from.checked_add(to).is_none_or(|to| to > len) { |
| 327 | 327 | // 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) }); | |
| 329 | 329 | } |
| 330 | 330 | len.checked_sub(to).unwrap() |
| 331 | 331 | } else { |
compiler/rustc_lint/src/impl_trait_overcaptures.rs+1-1| ... | ... | @@ -177,7 +177,7 @@ fn check_fn(tcx: TyCtxt<'_>, parent_def_id: LocalDefId) { |
| 177 | 177 | // Lazily compute these two, since they're likely a bit expensive. |
| 178 | 178 | variances: LazyCell::new(|| { |
| 179 | 179 | let mut functional_variances = FunctionalVariances { |
| 180 | tcx: tcx, | |
| 180 | tcx, | |
| 181 | 181 | variances: FxHashMap::default(), |
| 182 | 182 | ambient_variance: ty::Covariant, |
| 183 | 183 | generics: tcx.generics_of(parent_def_id), |
compiler/rustc_parse/src/parser/pat.rs+1-1| ... | ... | @@ -1647,7 +1647,7 @@ impl<'a> Parser<'a> { |
| 1647 | 1647 | ident: prev_field, |
| 1648 | 1648 | }) |
| 1649 | 1649 | } else { |
| 1650 | self.dcx().create_err(AtInStructPattern { span: span }) | |
| 1650 | self.dcx().create_err(AtInStructPattern { span }) | |
| 1651 | 1651 | } |
| 1652 | 1652 | } |
| 1653 | 1653 |
compiler/rustc_type_ir/src/elaborate.rs+1-1| ... | ... | @@ -72,7 +72,7 @@ impl<I: Interner> Elaboratable<I> for ClauseWithSupertraitSpan<I> { |
| 72 | 72 | _parent_trait_pred: crate::Binder<I, crate::TraitPredicate<I>>, |
| 73 | 73 | _index: usize, |
| 74 | 74 | ) -> Self { |
| 75 | ClauseWithSupertraitSpan { pred: clause.as_predicate(), supertrait_span: supertrait_span } | |
| 75 | ClauseWithSupertraitSpan { pred: clause.as_predicate(), supertrait_span } | |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 |
library/alloc/src/rc.rs+1-1| ... | ... | @@ -795,7 +795,7 @@ impl<T, A: Allocator> Rc<T, A> { |
| 795 | 795 | let uninit_ptr: NonNull<_> = (unsafe { &mut *uninit_raw_ptr }).into(); |
| 796 | 796 | let init_ptr: NonNull<RcInner<T>> = uninit_ptr.cast(); |
| 797 | 797 | |
| 798 | let weak = Weak { ptr: init_ptr, alloc: alloc }; | |
| 798 | let weak = Weak { ptr: init_ptr, alloc }; | |
| 799 | 799 | |
| 800 | 800 | // It's important we don't give up ownership of the weak pointer, or |
| 801 | 801 | // 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> { |
| 784 | 784 | let uninit_ptr: NonNull<_> = (unsafe { &mut *uninit_raw_ptr }).into(); |
| 785 | 785 | let init_ptr: NonNull<ArcInner<T>> = uninit_ptr.cast(); |
| 786 | 786 | |
| 787 | let weak = Weak { ptr: init_ptr, alloc: alloc }; | |
| 787 | let weak = Weak { ptr: init_ptr, alloc }; | |
| 788 | 788 | |
| 789 | 789 | // It's important we don't give up ownership of the weak pointer, or |
| 790 | 790 | // 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> { |
| 322 | 322 | // SAFETY: LocalWaker is just Waker without thread safety |
| 323 | 323 | let local_waker = unsafe { transmute(waker) }; |
| 324 | 324 | Self { |
| 325 | waker: waker, | |
| 325 | waker, | |
| 326 | 326 | local_waker, |
| 327 | 327 | ext: ExtData::None(()), |
| 328 | 328 | _marker: PhantomData, |
library/std/src/sys/pal/hermit/fs.rs+1-1| ... | ... | @@ -135,7 +135,7 @@ impl FileAttr { |
| 135 | 135 | S_IFREG => DT_REG, |
| 136 | 136 | _ => DT_UNKNOWN, |
| 137 | 137 | }; |
| 138 | FileType { mode: mode } | |
| 138 | FileType { mode } | |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 |
library/std/src/sys/pal/hermit/thread.rs+1-1| ... | ... | @@ -43,7 +43,7 @@ impl Thread { |
| 43 | 43 | } |
| 44 | 44 | Err(io::const_error!(io::ErrorKind::Uncategorized, "Unable to create thread!")) |
| 45 | 45 | } else { |
| 46 | Ok(Thread { tid: tid }) | |
| 46 | Ok(Thread { tid }) | |
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | 49 | extern "C" fn thread_start(main: usize) { |
library/std/src/sys/pal/hermit/time.rs+1-1| ... | ... | @@ -22,7 +22,7 @@ impl Timespec { |
| 22 | 22 | const fn new(tv_sec: i64, tv_nsec: i32) -> Timespec { |
| 23 | 23 | assert!(tv_nsec >= 0 && tv_nsec < NSEC_PER_SEC); |
| 24 | 24 | // 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 } } | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | 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 { |
| 12 | 12 | |
| 13 | 13 | impl FileDesc { |
| 14 | 14 | pub fn new(fd: Fd) -> FileDesc { |
| 15 | FileDesc { fd: fd } | |
| 15 | FileDesc { fd } | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | pub fn raw(&self) -> Fd { |
rustfmt.toml+1| ... | ... | @@ -4,6 +4,7 @@ use_small_heuristics = "Max" |
| 4 | 4 | merge_derives = false |
| 5 | 5 | group_imports = "StdExternalCrate" |
| 6 | 6 | imports_granularity = "Module" |
| 7 | use_field_init_shorthand = true | |
| 7 | 8 | |
| 8 | 9 | # Files to ignore. Each entry uses gitignore syntax, but `!` prefixes aren't allowed. |
| 9 | 10 | ignore = [ |
src/tools/compiletest/src/read2.rs+1-1| ... | ... | @@ -286,7 +286,7 @@ mod imp { |
| 286 | 286 | impl<'a> Pipe<'a> { |
| 287 | 287 | unsafe fn new<P: IntoRawHandle>(p: P, dst: &'a mut Vec<u8>) -> Pipe<'a> { |
| 288 | 288 | Pipe { |
| 289 | dst: dst, | |
| 289 | dst, | |
| 290 | 290 | pipe: NamedPipe::from_raw_handle(p.into_raw_handle()), |
| 291 | 291 | overlapped: Overlapped::zero(), |
| 292 | 292 | done: false, |
tests/codegen-units/item-collection/generic-impl.rs+1-1| ... | ... | @@ -14,7 +14,7 @@ fn id<T>(x: T) -> T { |
| 14 | 14 | |
| 15 | 15 | impl<T> Struct<T> { |
| 16 | 16 | fn new(x: T) -> Struct<T> { |
| 17 | Struct { x: x, f: id } | |
| 17 | Struct { x, f: id } | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | fn get<T2>(self, x: T2) -> (T, T2) { |
tests/codegen/issues/issue-15953.rs+1-1| ... | ... | @@ -9,7 +9,7 @@ struct Foo { |
| 9 | 9 | #[no_mangle] |
| 10 | 10 | // CHECK: memcpy |
| 11 | 11 | fn interior(x: Vec<i32>) -> Vec<i32> { |
| 12 | let Foo { x } = Foo { x: x }; | |
| 12 | let Foo { x } = Foo { x }; | |
| 13 | 13 | x |
| 14 | 14 | } |
| 15 | 15 |
tests/run-make/extern-fn-struct-passing-abi/test.rs+1-1| ... | ... | @@ -126,7 +126,7 @@ extern "C" { |
| 126 | 126 | |
| 127 | 127 | fn main() { |
| 128 | 128 | 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 }; | |
| 130 | 130 | let u = FloatRect { a: 3489, b: 3490, c: 8. }; |
| 131 | 131 | let v = Huge { a: 5647, b: 5648, c: 5649, d: 5650, e: 5651 }; |
| 132 | 132 | 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 { |
| 4 | 4 | |
| 5 | 5 | impl Def { |
| 6 | 6 | pub fn new(id: i32) -> Def { |
| 7 | Def { id: id } | |
| 7 | Def { id } | |
| 8 | 8 | } |
| 9 | 9 | } |
| 10 | 10 |