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.
…uwer Rollup of 22 pull requests Successful merges: - #156047 (Fix trait method resolution on an adjusted never type) - #157824 (Comptime inherent impls) - #158235 (Store `DefId` instead of `EiiDecl` in `EiiImplResolution::Known`) - #158723 (Support EII on Windows MSVC) - #158993 (rerun in original typing mode if we meet any opaques in post analysis) - #159160 (Make `HasTokens` a sub-trait of `HasAttrs`.) - #159183 (Introduce InstanceKind::LlvmIntrinsic) - #159251 (Bump rustc-perf submodule) - #155013 (Suggest the `[const] Destruct` bound for type parameters in const functions when missing) - #159155 (unstable book: Document `diagnostic_on_unknown` feature) - #159235 (Add regression test for #95719) - #159243 (inline Once wait and wait_force) - #159255 (Replace shortened type with `_` instead of `...` as placeholder) - #159259 (Add regression test for #144033) - #159265 (bootstrap: skip intrinsic-test when rustfmt is unavailable) - #159269 (disable range-len-try-from.rs on s390x) - #159272 (slice: make swap delegate to swap_unchecked) - #159274 (bootstrap: Rename `std_crates_for_run_make` to `std_crates_for_make_run`) - #159275 (remove obsolete comment) - #159277 (Construct `tokens` for attrs made by `mk_attr_word` and other variants) - #159283 (Remove obsolete verbose flag from deref/ref suggestions) - #159290 (rustc-dev-guide subtree update)
…uwer Rollup of 22 pull requests Successful merges: - #156047 (Fix trait method resolution on an adjusted never type) - #157824 (Comptime inherent impls) - #158235 (Store `DefId` instead of `EiiDecl` in `EiiImplResolution::Known`) - #158723 (Support EII on Windows MSVC) - #158993 (rerun in original typing mode if we meet any opaques in post analysis) - #159160 (Make `HasTokens` a sub-trait of `HasAttrs`.) - #159183 (Introduce InstanceKind::LlvmIntrinsic) - #159251 (Bump rustc-perf submodule) - #155013 (Suggest the `[const] Destruct` bound for type parameters in const functions when missing) - #159155 (unstable book: Document `diagnostic_on_unknown` feature) - #159235 (Add regression test for #95719) - #159243 (inline Once wait and wait_force) - #159255 (Replace shortened type with `_` instead of `...` as placeholder) - #159259 (Add regression test for #144033) - #159265 (bootstrap: skip intrinsic-test when rustfmt is unavailable) - #159269 (disable range-len-try-from.rs on s390x) - #159272 (slice: make swap delegate to swap_unchecked) - #159274 (bootstrap: Rename `std_crates_for_run_make` to `std_crates_for_make_run`) - #159275 (remove obsolete comment) - #159277 (Construct `tokens` for attrs made by `mk_attr_word` and other variants) - #159283 (Remove obsolete verbose flag from deref/ref suggestions) - #159290 (rustc-dev-guide subtree update)
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.