Skip to content

Remove unneeded clone in macro deriving - #162004

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Kobzol:remove-unneeded-clone
Aug 30, 2026
Merged

Remove unneeded clone in macro deriving#162004
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Kobzol:remove-unneeded-clone

Conversation

@Kobzol

@Kobzol Kobzol commented Aug 30, 2026

Copy link
Copy Markdown
Member

Found this while looking at the parser and macro expansion. Note that newitem is already an owned Box<Item>, so there is no need to clone it.

I found a few other places where we clone unnecessarily before dropping a value, but they were all in diagnostics code and the clone was very cheap, so it isn't IMO worth the churn. None of them were detected by the redundant_clone Clippy lint, which is a shame - it should be more powerful!

r? nnethercote

@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. labels Aug 30, 2026
@Kobzol

Kobzol commented Aug 30, 2026

Copy link
Copy Markdown
Member Author

@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 Aug 30, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 30, 2026
Remove unneeded clone in macro deriving
@Kobzol

Kobzol commented Aug 30, 2026

Copy link
Copy Markdown
Member Author

This is a perf. run where I removed all the clones I found. I think/hope that this PR should cover most of those small perf. wins.

@nnethercote

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

📌 Commit f32a095 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 Aug 30, 2026
@rust-bors

rust-bors Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 70a39cf (70a39cfb7b741e95fcb6af8b15f5f694a3c2b271)
Base parent: 3cabe36 (3cabe36ceb022e2f56d4d330b1e2886f31117f18)

@rust-timer

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 30, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #162004 (Remove unneeded clone in macro deriving)
 - #161902 (coverage: Rename the three main coverage-info structs)
 - #161967 (Rerun `tests/debuginfo` tests if repr data has changed)
 - #161977 (update target-cpus test)
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (70a39cf): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@bors rollup=never 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.3% [-0.5%, -0.1%] 37
Improvements ✅
(secondary)
-0.7% [-2.1%, -0.1%] 37
All ❌✅ (primary) -0.3% [-0.5%, -0.1%] 37

Max RSS (memory usage)

Results (primary 0.9%, secondary -1.5%)

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

mean range count
Regressions ❌
(primary)
3.0% [3.0%, 3.0%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.2% [-1.2%, -1.2%] 1
Improvements ✅
(secondary)
-1.5% [-1.8%, -1.1%] 2
All ❌✅ (primary) 0.9% [-1.2%, 3.0%] 2

Cycles

Results (primary 3.1%, 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)
3.1% [3.1%, 3.1%] 1
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) 3.1% [3.1%, 3.1%] 1

Binary size

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

Bootstrap: 475.389s -> 473.445s (-0.41%)
Artifact size: 402.85 MiB -> 402.88 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 30, 2026
@rust-bors
rust-bors Bot merged commit aa94167 into rust-lang:main Aug 30, 2026
14 checks passed
rust-bors Bot pushed a commit that referenced this pull request Aug 30, 2026
Rollup merge of #162004 - Kobzol:remove-unneeded-clone, r=nnethercote

Remove unneeded clone in macro deriving

Found this while looking at the parser and macro expansion. Note that `newitem` is already an owned `Box<Item>`, so there is no need to clone it.

I found a few other places where we clone unnecessarily before dropping a value, but they were all in diagnostics code and the clone was very cheap, so it isn't IMO worth the churn. None of them were detected by the `redundant_clone` Clippy lint, which is a shame - it should be more powerful!

r? nnethercote
@rustbot rustbot added this to the 1.100.0 milestone Aug 30, 2026
@Kobzol
Kobzol deleted the remove-unneeded-clone branch August 30, 2026 15:51
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants