Skip to content

Ensure we can optimize out does-nothing drops like array::IntoIter<NotNeedsDrop, N> #139422

Open
@scottmcm

Description

@scottmcm
Member

Noticed this looking at #139415.

We already do this for !needs_drop types, but std::array::IntoIter<&mut usize, 1> does have a Drop, and thus needs_drop is true because it's not trivially obvious that the Drop::drop won't actually do anything.

But if you look at https://rust.godbolt.org/z/raWrq6rsY you can see that we're emitting the call to the drop.

This probably is about inlining drop shims in MIR? Might be another way, though, if somehow we could notice in cg_ssa.

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Apr 5, 2025
the8472

the8472 commented on Apr 5, 2025

@the8472
Member

Could we help the compiler to make a better needs_drop determination by having an unsafe NoDrop marker trait?

Hrrm, I guess it would be rather limited, a newtype would already defeat that.

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing such
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler 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

        Participants

        @the8472@scottmcm@jieyouxu@rustbot

        Issue actions

          Ensure we can optimize out does-nothing `drop`s like `array::IntoIter<NotNeedsDrop, N>` · Issue #139422 · rust-lang/rust