Files
rust/compiler/rustc_const_eval
Jonathan Brouwer 10c41afdc9 Rollup merge of #155013 - jakubadamw:issue-103270, r=oli-obk
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/rust#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.
2026-07-14 16:49:05 +02:00
..