Skip to content

More derive(Debug) cleanups for structs - #165140

Merged
rust-bors[bot] merged 6 commits into
rust-lang:mainfrom
panstromek:derive-debug-cleanups
Nov 2, 2026
Merged

rust-bors[bot] merged 6 commits into
rust-lang:mainfrom
panstromek:derive-debug-cleanups

Conversation

@panstromek

@panstromek panstromek commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

This removes duplication from the debug helpers and unifies tuples with structs.

More details in individual commits.

I think this is makes the code simpler, but it's a bit of a judgement call.

r? nnethercote

They have the same signature now, so we can unify them. The implementation for tuple is selected based on whether the concatenated string contains field names.
@rustbot

rustbot commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Changes to the code generated for builtin derived traits.

cc @nnethercote

stdarch is developed in its own repository. If possible, consider making this change to rust-lang/stdarch instead.

cc @Amanieu, @folkertdev, @sayantn

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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 Oct 29, 2026
@panstromek

Copy link
Copy Markdown
Contributor Author

This could maybe help std size and binary size.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 29, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 29, 2026
More derive(Debug) cleanups for structs
@rust-bors

rust-bors Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 1f87bc3 (1f87bc31991d0e278a00ab88b78a17495a0f5ea3)
Base parent: 96a18bf (96a18bf5ffa2b24f9cf3d1c731a9eb121c1acad9)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (1f87bc3): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@bors rollup=iffy rustc-perf
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

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

Max RSS (memory usage)

Results (primary -0.9%, secondary -0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 1
Improvements ✅
(primary)
-0.9% [-0.9%, -0.9%] 1
Improvements ✅
(secondary)
-2.0% [-2.6%, -1.4%] 2
All ❌✅ (primary) -0.9% [-0.9%, -0.9%] 1

Cycles

Results (primary 0.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.6% [2.3%, 2.8%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.6% [-3.6%, -3.6%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [-3.6%, 2.8%] 6

Binary size

Results (primary -0.4%, secondary 0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 2
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-0.4%, -0.4%] 4

Bootstrap: 487.353s -> 485.918s (-0.29%)
Artifact size: 406.68 MiB -> 406.88 MiB (0.05%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 29, 2026

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

The shorter code is nice. It does make debug printing a little slower, as seen in the fmt-debug-derive runtime test. That's probably ok?

View changes since this review

Comment thread library/core/src/fmt/mod.rs Resolved
@nnethercote

Copy link
Copy Markdown
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 30, 2026
@rustbot

rustbot commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@panstromek

Copy link
Copy Markdown
Contributor Author

It does make debug printing a little slower, as seen in the fmt-debug-derive runtime test. That's probably ok?

I think it's still ok (the concatenation change made it 30% slower), but there's of course a question of how much can we make the debug impls slower to help other metrics. I still assume most of this code in the ecosystem is either dead or used extremely rarely and for a small number of things at once, so I place it on a similar level as a panic path. Not sure that's always the right assumption

Either way, I want try whether we can make it little better, I suspect the split(' ') iterator might not be very optimal for this case. I wanted to unify all the code paths into one place first.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 30, 2026
@nnethercote

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ae82815 has been tentatively approved by nnethercote

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot 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 Oct 30, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Oct 30, 2026
@rust-bors

rust-bors Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

⚠️ A new commit a4331d431ca8238af94bd1adad03063aef41e69f was pushed.

This pull request was unapproved.

@panstromek

panstromek commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Ok, I think I've handled all of those now - split(' ') cases and also checked indexing error handling (that's another one that @folkertdev pointed out). @Jules-Bertholet can you check it out?

Let's check perf as well.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 30, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 30, 2026
More derive(Debug) cleanups for structs
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 2207ca9 (2207ca9689c9c24ff1113563b1aeb97dc5a0b4a4)
Base parent: 92b5b8c (92b5b8c87c61b20adc9001b41baf587634a74734)

@rust-timer

This comment has been minimized.

@panstromek
panstromek force-pushed the derive-debug-cleanups branch from a4331d4 to 8cde1fb Compare October 30, 2026 19:09
@panstromek

Copy link
Copy Markdown
Contributor Author

fixed clippy, should be good now (I don't expect perf run to show problems)

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 30, 2026
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (2207ca9): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@bors rollup=iffy rustc-perf
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

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

Max RSS (memory usage)

Results (secondary 4.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Cycles

Results (secondary -1.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Binary size

Results (primary -0.4%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Bootstrap: 484.843s -> 486.345s (0.31%)
Artifact size: 406.61 MiB -> 406.71 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 30, 2026
@nnethercote

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8cde1fb has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Nov 2, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 2, 2026
…uwer

Rollup of 2 pull requests

Successful merges:

 - #165140 (More derive(Debug) cleanups for structs)
 - #165160 (New solver opts for diesel (part 3))
@rust-bors
rust-bors Bot merged commit 7da2c58 into rust-lang:main Nov 2, 2026
14 checks passed
rust-bors Bot pushed a commit that referenced this pull request Nov 2, 2026
Rollup merge of #165140 - panstromek:derive-debug-cleanups, r=nnethercote

More derive(Debug) cleanups for structs

This removes duplication from the debug helpers and unifies tuples with structs.

More details in individual commits.

I think this is makes the code simpler, but it's a bit of a judgement call.

r? nnethercote
@rustbot rustbot added this to the 1.101.0 milestone Nov 2, 2026
BenMac31 pushed a commit to graphide-oss/rust-analyzer that referenced this pull request Nov 2, 2026
…uwer

Rollup of 2 pull requests

Successful merges:

 - rust-lang/rust#165140 (More derive(Debug) cleanups for structs)
 - rust-lang/rust#165160 (New solver opts for diesel (part 3))
@rust-timer

Copy link
Copy Markdown
Collaborator

Note

This PR was benchmarked as part of triage of its containing rollup: triage URL.

Finished benchmarking commit (d4ef51e): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-0.5%, -0.4%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-0.5%, -0.4%] 4

Max RSS (memory usage)

Results (secondary 2.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Cycles

This perf run didn't have relevant results for this metric.

Binary size

Results (primary -0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Artifact size: 406.62 MiB -> 406.61 MiB (-0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants