constify from_fn, try_from_fn, try_map, map by bend-n · Pull Request #147071 · rust-lang/rust (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation67 Commits3 Checks11 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

@bend-n

adds the const_array feature
reimplements try_map in more or less the same way

@rustbot rustbot added S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

labels

Sep 26, 2025

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n marked this pull request as ready for review

September 26, 2025 18:44

@rustbot rustbot removed the S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

label

Sep 26, 2025

@rustbot

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

oli-obk

else {
// SAFETY: this slice will contain only initialized objects.
unsafe {
x.array_mut.get_unchecked_mut(..x.initialized).assume_init_drop();

Choose a reason for hiding this comment

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

What part of this isn't const evaluable? The get_unchecked_mut?

Choose a reason for hiding this comment

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

assume_init_drop, and changing it to be const had some rammifications for some reason, causing some tests to fail. #147071 (comment)

Choose a reason for hiding this comment

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

Looks like just trivial stderr file changes. Feel free to just bless them.

But is that code path testable in const? Since it's only happening in a panic path, I think it's unreachable anyway in const contexts. They never unwind and never will unwind. So maybe just document that and move the entire drop method body into the non-const code path... Or can we keep it non-const and avoid any drop happening for it by "disarming it" in the success path?

Choose a reason for hiding this comment

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

its used in try_from_fn, so it can get dropped in const context?

Choose a reason for hiding this comment

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

Ah right. Hmm. Wondering how to write an observable test for this. I think if you use a type with a reference to a Cell and in its const drop impl increment that cell, you should see in a const context that the cell isn't incremented if try_map errors/returns None.

Choose a reason for hiding this comment

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

Ah oops, wanted to write this test but forgot about it when I was on a computer.

Need to reinvestigate this to get it all back into cache.

Choose a reason for hiding this comment

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

It oughtnt really be needed now, as the behaviour is identical to the non const version?

oli-obk

oli-obk

@rustbot

The Miri subtree was changed

cc @rust-lang/miri

oli-obk

@rustbot

This comment has been minimized.

bend-n

where
F: [const] FnMut(T) -> U,
{
extern "rust-call" fn call_mut(&mut self, (i,): (usize,)) -> Self::Output {

Choose a reason for hiding this comment

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

it would be possible to ignore this i and just use moved, but, uh, i think that would be somewhat confusing.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot

Some changes occurred in src/tools/cargo

cc @ehuss

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

oli-obk

Choose a reason for hiding this comment

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

@bend-n

@bend-n

@rustbot

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.

@bend-n

@oli-obk

@bors

📌 Commit e3a2c23 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors 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

Nov 27, 2025

bors added a commit that referenced this pull request

Nov 27, 2025

@bors

Rollup of 8 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit that referenced this pull request

Nov 27, 2025

@rust-timer

Rollup merge of #147071 - bend-n:const_array-ops, r=oli-obk

constify from_fn, try_from_fn, try_map, map

adds the const_array feature reimplements try_map in more or less the same way

@bend-n bend-n deleted the const_array-ops branch

November 28, 2025 04:34

github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request

Dec 1, 2025

@bors

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.