Skip to content

Constify Fn* traits #143640

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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Constify Fn* traits #143640

wants to merge 2 commits into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 8, 2025

r? @compiler-errors @fee1-dead

this should unlock a few things. A few const_closures tests have broken even more than before, but that feature is marked as incomplete anyway

@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. labels Jul 8, 2025
Comment on lines -532 to +536
deferred_call_resolution.resolve(self);
deferred_call_resolution.resolve(&mut FnCtxt::new(
self,
self.param_env,
closure_def_id,
));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was necessary, as otherwise

const FOO: impl Fn() = || {
    let x = || ();
    x()
};

would have performed some checks in the outer closure's body as if it were const, causing the x() invocation to fail because x is not a const closure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ICE test didn't seem like it was still testing anything meaningful

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2025
@compiler-errors
Copy link
Member

Can you add new solver support too?

@compiler-errors
Copy link
Member

Please also remove the hack from typeck around const_eval_select since now we can just require that intrinsic to provide both an impl FnOnce and impl const FnOnce

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 8, 2025

Can you add new solver support too?

you already added that and it was never removed. I made the tests run on both solvers

@rustbot
Copy link
Collaborator

rustbot commented Jul 8, 2025

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

lgtm

@compiler-errors
Copy link
Member

r=me when ci

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 8, 2025

@bors r=compiler-errors

@bors
Copy link
Collaborator

bors commented Jul 8, 2025

📌 Commit b1d45f6 has been approved by compiler-errors

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 8, 2025
@@ -72,7 +72,8 @@ use crate::marker::Tuple;
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
// FIXME(const_trait_impl) #[const_trait]
#[const_trait]
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we have a proper lib feature and tracking issue here, rather than slapping everything into a 5-year-old issue that was created for an entirely different generation of the const trait RFC evolution?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lang feature is not very useful without the lib feature, requiring separate lib features for different traits is just going to require one to add many features when using any somewhat large feature.

We could pick a new tracking issue, but that also just feels like shuffling things around for no good reason.

I have no idea what the process will be for stabilizing any of these, a lot of them are entangled. We'll likely want to stabilize many traits as const together with stabilizing the lang feature to not cause weird ecosystem churn

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants