Skip to content

constify const Fn*: Destruct#153874

Open
bend-n wants to merge 1 commit intorust-lang:mainfrom
bend-n:constify-const-fn-destruct
Open

constify const Fn*: Destruct#153874
bend-n wants to merge 1 commit intorust-lang:mainfrom
bend-n:constify-const-fn-destruct

Conversation

@bend-n
Copy link
Contributor

@bend-n bend-n commented Mar 14, 2026

makes closures const destruct where their upvars are. i think this makes sense
and is how this should be implemented.

r? @oli-obk

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Mar 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2026

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 1d08de5 to 92b334a Compare March 14, 2026 15:52
#[test]
fn extra_const_array_ops() {
let x: [u8; 4] =
const { std::array::from_fn(const |i| i + 4).map(const |x| x * 2).map(const |x| x as _) };
Copy link
Contributor

@oli-obk oli-obk Mar 14, 2026

Choose a reason for hiding this comment

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

Also add a test with upvars (both trivial ones and ones with const Drop impls

Copy link
Contributor

Choose a reason for hiding this comment

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

And a UI test that fails if an upvar is not const Destruct

@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 92b334a to 9a21f8d Compare March 14, 2026 16:25
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 9a21f8d to cf2876e Compare March 14, 2026 17:59
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-const-fn-destruct branch 2 times, most recently from d2537d2 to 20dfeff Compare March 14, 2026 19:00
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 20dfeff to 29a13cc Compare March 14, 2026 21:10
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 29a13cc to bc613f8 Compare March 14, 2026 21:17
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-const-fn-destruct branch from bc613f8 to 5c1e5d5 Compare March 15, 2026 06:46
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 5c1e5d5 to 02e4873 Compare March 15, 2026 13:44
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 02e4873 to 50d7a00 Compare March 15, 2026 14:14
@oli-obk
Copy link
Contributor

oli-obk commented Mar 16, 2026

lgtm. Pls squash the commits as the test commit doesn't test "before this PR" behaviour but is just tied to the second commit

r=me

@bors delegate+

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 16, 2026

✌️ @bend-n, you can now approve this pull request!

If @oli-obk told you to "r=me" after making some further change, then please make that change and post @bors r=oli-obk.

@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 50d7a00 to 04b3bca Compare March 16, 2026 15:15
@bend-n
Copy link
Contributor Author

bend-n commented Mar 16, 2026

@bors r=oli-obk

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 16, 2026

📌 Commit 04b3bca has been approved by oli-obk

It is now in the queue for this repository.

@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 Mar 16, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 16, 2026

⌛ Testing commit 04b3bca with merge 629890a...

Workflow: https://github.com/rust-lang/rust/actions/runs/23156680213

rust-bors bot pushed a commit that referenced this pull request Mar 16, 2026
constify const Fn*: Destruct

makes closures const destruct where their upvars are. i think this makes sense
and is how this should be implemented.

r? @oli-obk
@rust-bors rust-bors bot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 16, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 16, 2026

💥 Test timed out after 21600s

@rust-bors rust-bors bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Mar 16, 2026

// Coroutines and closures could implement `[const] Drop`,
// Closures are [const] Destruct when all of their upvars (captures) are [const] Destruct.
ty::Closure(def, args) if cx.closure_is_const(def) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The old and next solvers in this PR seem to treat non-const closures differently. Please test if this code has the same behavior on the old solver and the next solver:

#![feature(const_trait_impl, const_destruct)]
use std::marker::Destruct;
const fn foo(x: i32) -> impl const Destruct {
    move || { std::hint::black_box(x); }
}

@bend-n
Copy link
Contributor Author

bend-n commented Mar 17, 2026

@bors retry

@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 Mar 17, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 17, 2026
… r=oli-obk

constify const Fn*: Destruct

makes closures const destruct where their upvars are. i think this makes sense
and is how this should be implemented.

r? @oli-obk
@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 04b3bca to 5ff4862 Compare March 17, 2026 16:42
@rust-bors rust-bors bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 17, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 17, 2026

⚠️ A new commit 5ff4862d1f014b3491095d98d280fbd15f2838d5 was pushed.

This pull request was unapproved.

This PR was contained in a rollup (#154007), which was closed.

@bend-n
Copy link
Contributor Author

bend-n commented Mar 17, 2026

@rustbot ready

@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 Mar 17, 2026
@bend-n bend-n force-pushed the constify-const-fn-destruct branch from 5ff4862 to b90abe6 Compare March 17, 2026 16:47
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. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants