rust-lang / rust-lang/rust

Ensure we can optimize out does-nothing `drop`s like `array::IntoIter<NotNeedsDrop, N>`

Open
#139,422 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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.

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 with the related issue #139415 and reproduce the linked Godbolt example for std::array::IntoIter<&mut usize, 1>. Investigate the suggested MIR drop-shim inlining and cg_ssa alternatives, then verify that the generated code no longer emits a call for this no-op drop case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.