rust-lang / rust-lang/rust

missed optimimization: needless clone of stdlib non-copy type is not eliminated

Open
#138,118 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-optimization T-compiler T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

code: https://rust.godbolt.org/z/5M1nnhEbY (godbolt isn't letting me copy it for some reason)

compiler version: 1.85.0

I understand that technically Clone can have side effects, but standard library types should be able to use some sort of perma-unstable attribute to assert that their Clone impl does not (technically calling the allocator is an arbitrary side-effect, but i believe rust already has a policy that allocations can be eliminated).

Types that use derive(Clone), where all of the fields are pure types, should also have their clone impls marked as safe.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Godbolt example with compiler version 1.85.0 and compare the generated code for the standard-library non-copy type. Investigate how the compiler represents Clone side effects and derived Clone implementations, then define a regression check showing when the needless clone is eliminated without changing observable behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.