Skip to content

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

Open
@lolbinarycat

Description

@lolbinarycat

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions