Suggest the [const] Destruct bound for type parameters in const functions when missing#155013
Suggest the [const] Destruct bound for type parameters in const functions when missing#155013jakubadamw wants to merge 3 commits into
[const] Destruct bound for type parameters in const functions when missing#155013Conversation
|
Some changes occurred to constck cc @fee1-dead Some changes occurred to the CTFE machinery |
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
[const] Destruct bound for type parameters in const functions[const] Destruct bound for type parameters in const functions when missing
|
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 |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@wesleywiser, thank you, I made the suggestion trigger on nightly only. 🙂 |
This comment has been minimized.
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.
|
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. |
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.
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.
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.
When a const function drops a value whose type is a type parameter without a
[const] Destructbound, suggest adding it so that the destructor can be evaluated at compile-time.Closes #103270.
Example:
Before:
After:
No new tests as the existing ones had their results updated with the new suggestion.