Skip to content

constify const Fn*: Destruct#153874

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
bend-n:constify-const-fn-destruct
Mar 24, 2026
Merged

constify const Fn*: Destruct#153874
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
bend-n:constify-const-fn-destruct

Conversation

@bend-n

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

Copy link
Copy Markdown
Contributor

View all comments

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

rustbot commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator

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
Comment thread library/coretests/tests/array.rs Outdated
#[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 _) };

@oli-obk oli-obk Mar 14, 2026

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.

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

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.

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

oli-obk commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

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

rust-bors Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

✌️ @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

bend-n commented Mar 16, 2026

Copy link
Copy Markdown
Contributor Author

@bors r=oli-obk

@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 16, 2026
@rust-bors

rust-bors Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

⌛ 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

rust-bors Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

💥 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
Copy Markdown
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

bend-n commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

@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

rust-bors Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

⚠️ A new commit 5ff4862d1f014b3491095d98d280fbd15f2838d5 was pushed.

This pull request was unapproved.

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

@bend-n

bend-n commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

@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
@oli-obk

oli-obk commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b90abe6 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 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Mar 24, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #152710 (Unalign `PackedFingerprint` on all hosts, not just x86 and x86-64)
 - #153874 (constify const Fn*: Destruct)
 - #154097 (improve validation error messages: show surrounding type)
 - #154277 (use `minicore` more in testing inline assembly)
 - #154293 (Use verbose span suggestion for type const)
@rust-bors rust-bors Bot merged commit 1e3d3bd into rust-lang:main Mar 24, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 24, 2026
github-actions Bot pushed a commit to rust-lang/miri that referenced this pull request Mar 25, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#152710 (Unalign `PackedFingerprint` on all hosts, not just x86 and x86-64)
 - rust-lang/rust#153874 (constify const Fn*: Destruct)
 - rust-lang/rust#154097 (improve validation error messages: show surrounding type)
 - rust-lang/rust#154277 (use `minicore` more in testing inline assembly)
 - rust-lang/rust#154293 (Use verbose span suggestion for type const)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. 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