Skip to content

Use field init shorthand where possible#134443

Merged
bors merged 1 commit into
rust-lang:masterfrom
joshtriplett:use-field-init-shorthand
Dec 18, 2024
Merged

Use field init shorthand where possible#134443
bors merged 1 commit into
rust-lang:masterfrom
joshtriplett:use-field-init-shorthand

Conversation

@joshtriplett

@joshtriplett joshtriplett commented Dec 17, 2024

Copy link
Copy Markdown
Member

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.

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.
@rustbot

rustbot commented Dec 17, 2024

Copy link
Copy Markdown
Collaborator

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc O-hermit Operating System: Hermit O-SGX Target: SGX S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 17, 2024
@joshtriplett

Copy link
Copy Markdown
Member Author

r? nnethercote

@rustbot rustbot assigned nnethercote and unassigned tgross35 Dec 17, 2024
@joshtriplett joshtriplett removed A-testsuite Area: The testsuite used to check the correctness of rustc O-SGX Target: SGX O-hermit Operating System: Hermit A-compiletest Area: The compiletest test runner A-run-make Area: port run-make Makefiles to rmake.rs labels Dec 17, 2024

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

r=me unless you wanted a review from nnethercote specifically

@lqd

lqd commented Dec 17, 2024

Copy link
Copy Markdown
Member

This rustfmt setting seems uncontroversial.

If you don't need a review from nick specifically, r=me when CI is green.

@joshtriplett

Copy link
Copy Markdown
Member Author

@tgross35 @lqd No specific reviewer needed, was just picking based on expected familiarity with the area. Thanks! Will r= when CI is green.

@joshtriplett joshtriplett removed the request for review from nnethercote December 17, 2024 22:49
@nnethercote

Copy link
Copy Markdown
Contributor

👍

@tgross35

Copy link
Copy Markdown
Contributor

@bors r=lqd,tgross35,nnethercote

@bors

bors commented Dec 18, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit a105cd6 has been approved by lqd,tgross35,nnethercote

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 18, 2024
@tgross35 tgross35 added the CI-spurious-fail-msvc CI spurious failure: target env msvc label Dec 18, 2024
@jieyouxu

This comment was marked as off-topic.

@RalfJung

Copy link
Copy Markdown
Member

@bors rollup=never

can cause unrelated PRs in the rollup to break

Comment thread rustfmt.toml

@jieyouxu jieyouxu Dec 18, 2024

Copy link
Copy Markdown
Member

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

@ChrisDenton

Copy link
Copy Markdown
Member

Should use_field_init_shorthand be set by default for style_edition = "2024"?

@jieyouxu jieyouxu added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 18, 2024
@klensy

klensy commented Dec 18, 2024

Copy link
Copy Markdown
Contributor

Should use_field_init_shorthand be set by default for style_edition = "2024"?

I'm stuck, step-reviewer, help me: #129636

@klensy

klensy commented Dec 18, 2024

Copy link
Copy Markdown
Contributor

Can also apply this diff to make clippy check the same thing. Can be added to this pr or i can send it separately.

diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs
index 0884d86cc6d..4644f31c003 100644
--- a/src/bootstrap/src/core/build_steps/clippy.rs
+++ b/src/bootstrap/src/core/build_steps/clippy.rs
@@ -378,20 +378,24 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
             config: self.config.merge(&LintConfig {
                 allow: vec![],
                 warn: vec![],
-                deny: vec!["warnings".into()],
+                deny: vec!["clippy::redundant_field_names".into(), "warnings".into()],
                 forbid: vec![],
             }),
         });
         let library_clippy_cfg = LintConfig {
             allow: vec!["clippy::all".into()],
             warn: vec![],
-            deny: vec!["clippy::correctness".into()],
+            deny: vec!["clippy::redundant_field_names".into(), "clippy::correctness".into()],
             forbid: vec![],
         };
         let compiler_clippy_cfg = LintConfig {
             allow: vec!["clippy::all".into()],
             warn: vec![],
-            deny: vec!["clippy::correctness".into(), "clippy::clone_on_ref_ptr".into()],
+            deny: vec![
+                "clippy::redundant_field_names".into(),
+                "clippy::correctness".into(),
+                "clippy::clone_on_ref_ptr".into(),
+            ],
             forbid: vec![],
         };
  

@joshtriplett

joshtriplett commented Dec 18, 2024

Copy link
Copy Markdown
Member Author

@klensy Please send the clippy change as a separate PR. Happy to review it.

@bors

bors commented Dec 18, 2024

Copy link
Copy Markdown
Collaborator

⌛ Testing commit a105cd6 with merge 4ba4ac6...

@bors

bors commented Dec 18, 2024

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: lqd,tgross35,nnethercote
Pushing 4ba4ac6 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 18, 2024
@bors bors merged commit 4ba4ac6 into rust-lang:master Dec 18, 2024
@rustbot rustbot added this to the 1.85.0 milestone Dec 18, 2024
@joshtriplett joshtriplett deleted the use-field-init-shorthand branch December 18, 2024 23:18
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (4ba4ac6): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -7.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-7.0% [-7.0%, -7.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -7.0% [-7.0%, -7.0%] 1

Cycles

Results (primary 2.9%, secondary -2.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.9% [2.9%, 2.9%] 1
Regressions ❌
(secondary)
2.0% [2.0%, 2.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.1% [-4.3%, -2.1%] 14
All ❌✅ (primary) 2.9% [2.9%, 2.9%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 769.824s -> 771.62s (0.23%)
Artifact size: 330.35 MiB -> 330.35 MiB (-0.00%)

@fmease fmease added T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. and removed A-rustfmt labels Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-meta Area: Issues & PRs about the rust-lang/rust repository itself CI-spurious-fail-msvc CI spurious failure: target env msvc merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.