rust-lang / rust-lang/rust

Tracking Issue for `const_destruct`

Open
#133,214 8 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue F-const_trait_impl PG-const-traits T-lang T-libs T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Feature gate: #![feature(const_destruct)]

This is a tracking issue for const_destruct, which enables the naming of the Destruct trait and its use in ~const bounds to allow dropping values in const contexts.

Public API
pub trait Destruct { }
Steps / History
Unresolved Questions
  • Do we want to allow ~const bounds on const Drop impls?

I think we do, and sorely need them for const drop to ever be useful. See my justification in https://github.com/rust-lang/rust/pull/132329#discussion_r1838749569. We want to be able to implement a conditional drop impl like:

struct DropAndCall<F: Fn()>(F);

impl<F> const Drop for DropAndCall<F>
where
    F: ~const Fn(),
{
    fn drop(&mut self) {
        (self.0)(); // This should be allowed.
    }
}

This is what is implemented on nightly.

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 const_destruct feature gate and the implementation described in rust-lang/rust#132329, then read the linked stabilization guide. The implementation is marked complete; remaining work is to resolve whether ~const bounds belong on const Drop impls, complete the final comment period, and prepare a stabilization PR.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.