Skip to content

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

Open
jakubadamw wants to merge 3 commits into
rust-lang:mainfrom
jakubadamw:issue-103270
Open

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

Conversation

@jakubadamw

@jakubadamw jakubadamw commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

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.

@rustbot

rustbot commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

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

rustbot commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

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

Kivooeo commented Apr 8, 2026

Copy link
Copy Markdown
Member

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

@wesleywiser wesleywiser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would probably only want to offer this suggestion if the user is on a nightly compiler.

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 24, 2026
@rustbot

rustbot commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@fee1-dead fee1-dead self-assigned this Apr 25, 2026
@rust-bors

This comment has been minimized.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Jul 13, 2026
@rustbot

This comment has been minimized.

@jakubadamw jakubadamw requested a review from wesleywiser July 13, 2026 00:05
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 13, 2026
@jakubadamw

Copy link
Copy Markdown
Contributor Author

@wesleywiser, thank you, I made the suggestion trigger on nightly only. 🙂

@rust-log-analyzer

This comment has been minimized.

…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.
The suggested bound requires the unstable `const_destruct` feature,
so it is not actionable on a stable compiler.
Add a run-make test that verifies the suggestion is only emitted on nightly.
@rustbot

rustbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@oli-obk oli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2f961b8 has been approved by oli-obk

It is now in the queue for this repository.

@rustbot rustbot assigned oli-obk and unassigned wesleywiser Jul 14, 2026
@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 14, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 14, 2026
Suggest the `[const] Destruct` bound for type parameters in const functions when missing

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 rust-lang#103270.

Example:

```rust
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.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 14, 2026
Suggest the `[const] Destruct` bound for type parameters in const functions when missing

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 rust-lang#103270.

Example:

```rust
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.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 14, 2026
Suggest the `[const] Destruct` bound for type parameters in const functions when missing

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 rust-lang#103270.

Example:

```rust
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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

7 participants