Skip to content

Use field init shorthand where possible #134443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ where
let actual_to = if from_end {
if from.checked_add(to).is_none_or(|to| to > len) {
// This can only be reached in ConstProp and non-rustc-MIR.
throw_ub!(BoundsCheckFailed { len: len, index: from.saturating_add(to) });
throw_ub!(BoundsCheckFailed { len, index: from.saturating_add(to) });
}
len.checked_sub(to).unwrap()
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/impl_trait_overcaptures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn check_fn(tcx: TyCtxt<'_>, parent_def_id: LocalDefId) {
// Lazily compute these two, since they're likely a bit expensive.
variances: LazyCell::new(|| {
let mut functional_variances = FunctionalVariances {
tcx: tcx,
tcx,
variances: FxHashMap::default(),
ambient_variance: ty::Covariant,
generics: tcx.generics_of(parent_def_id),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ impl<'a> Parser<'a> {
ident: prev_field,
})
} else {
self.dcx().create_err(AtInStructPattern { span: span })
self.dcx().create_err(AtInStructPattern { span })
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/elaborate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<I: Interner> Elaboratable<I> for ClauseWithSupertraitSpan<I> {
_parent_trait_pred: crate::Binder<I, crate::TraitPredicate<I>>,
_index: usize,
) -> Self {
ClauseWithSupertraitSpan { pred: clause.as_predicate(), supertrait_span: supertrait_span }
ClauseWithSupertraitSpan { pred: clause.as_predicate(), supertrait_span }
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/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 library/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 library/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 library/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 library/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 library/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 library/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
1 change: 1 addition & 0 deletions rustfmt.toml
Copy link
Member

@jieyouxu jieyouxu Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes rustfmt.toml

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use_small_heuristics = "Max"
merge_derives = false
group_imports = "StdExternalCrate"
imports_granularity = "Module"
use_field_init_shorthand = true

# Files to ignore. Each entry uses gitignore syntax, but `!` prefixes aren't allowed.
ignore = [
Expand Down
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/read2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ mod imp {
impl<'a> Pipe<'a> {
unsafe fn new<P: IntoRawHandle>(p: P, dst: &'a mut Vec<u8>) -> Pipe<'a> {
Pipe {
dst: dst,
dst,
pipe: NamedPipe::from_raw_handle(p.into_raw_handle()),
overlapped: Overlapped::zero(),
done: false,
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/generic-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn id<T>(x: T) -> T {

impl<T> Struct<T> {
fn new(x: T) -> Struct<T> {
Struct { x: x, f: id }
Struct { x, f: id }
}

fn get<T2>(self, x: T2) -> (T, T2) {
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/issues/issue-15953.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct Foo {
#[no_mangle]
// CHECK: memcpy
fn interior(x: Vec<i32>) -> Vec<i32> {
let Foo { x } = Foo { x: x };
let Foo { x } = Foo { x };
x
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/extern-fn-struct-passing-abi/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extern "C" {

fn main() {
let s = Rect { a: 553, b: 554, c: 555, d: 556 };
let t = BiggerRect { s: s, a: 27834, b: 7657 };
let t = BiggerRect { s, a: 27834, b: 7657 };
let u = FloatRect { a: 3489, b: 3490, c: 8. };
let v = Huge { a: 5647, b: 5648, c: 5649, d: 5650, e: 5651 };
let w = Huge64 { a: 1234, b: 1335, c: 1436, d: 1537, e: 1638 };
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/symbols-include-type-name/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct Def {

impl Def {
pub fn new(id: i32) -> Def {
Def { id: id }
Def { id }
}
}

Expand Down
Loading