Skip to content

Suggest the [const] Destruct bound for type parameters in const functions when missing#155013

Open
jakubadamw wants to merge 2 commits intorust-lang:mainfrom
jakubadamw:issue-103270
Open

Suggest the [const] Destruct bound for type parameters in const functions when missing#155013
jakubadamw wants to merge 2 commits intorust-lang:mainfrom
jakubadamw:issue-103270

Conversation

@jakubadamw
Copy link
Copy Markdown
Contributor

@jakubadamw jakubadamw commented Apr 8, 2026

When a const function drops a value whose type is a type parameter without a [const] Destruct bound, suggest adding it so that the destructor can be evaluated at compile-time.

Closes #103270.

Example:

const fn f(_x: impl std::fmt::Debug) {}

Before:

error[E0493]: destructor of `impl std::fmt::Debug` cannot be evaluated at compile-time
  --> $DIR/min_const_fn.rs:1:11
   |
LL | const fn f(_x: impl std::fmt::Debug) {}
   |                  ^^                         - value is dropped here
   |                  |
   |                  the destructor for this type cannot be evaluated in constant functions

After:

error[E0493]: destructor of `impl std::fmt::Debug` cannot be evaluated at compile-time
  --> $DIR/min_const_fn.rs:1:11
   |
LL | const fn f(_x: impl std::fmt::Debug) {}
   |                  ^^                         - value is dropped here
   |                  |
   |                  the destructor for this type cannot be evaluated in constant functions
   |
help: consider restricting opaque type `impl std::fmt::Debug` with unstable trait `Destruct`
   |
LL | const fn f(_x: impl std::fmt::Debug + [const] Destruct) {}
   |                                           ++++++++++++++++++

No new tests as the existing ones had their results updated with the new suggestion.

…ctions

When a const function drops a value whose type is a type parameter,
suggest adding a `[const] Destruct` bound so the destructor can be
evaluated at compile-time.
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 8, 2026

Some changes occurred to constck

cc @fee1-dead

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 8, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 8, 2026

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 12 candidates

@jakubadamw jakubadamw changed the title Suggest the [const] Destruct bound for type parameters in const functions Suggest the [const] Destruct bound for type parameters in const functions when missing Apr 8, 2026
@Kivooeo
Copy link
Copy Markdown
Member

Kivooeo commented Apr 8, 2026

thanks for the contribution, but this is experimental syntax which means syntax may change in future, so I think it should be held until stabilization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest ~const std::marker::Destruct for type parameters when needed

4 participants