Skip to content
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

Constifying large traits in libstd (i.e. Iterator) #15

Open
compiler-errors opened this issue Oct 31, 2024 · 3 comments
Open

Constifying large traits in libstd (i.e. Iterator) #15

compiler-errors opened this issue Oct 31, 2024 · 3 comments

Comments

@compiler-errors
Copy link
Member

My understanding is that constifying iterator currently required constifying all of its extension methods. That was a lot of work.

Instead, we just slapped rustc_do_not_const_check onto all the methods, somewhat leaving us vulnerable to CTFE errors "post-mono" if any of the combinators ended up doing anything non-const.

Instead of doing this, we probably could introduce something like rustc_non_const_trait_method that forces a specific method to be non-const in a const trait.

This means we don't need to work towards constifying all of the combinators all at once. Then when we constify iterator, we can initially slap #[rustc_non_const_trait_method] on every combinator, and slowly work to peel them off until the trait is fully constified.

@Aloso
Copy link

Aloso commented Jan 18, 2025

Then when we constify iterator, we can initially slap #[rustc_non_const_trait_method] on every combinator, and slowly work to peel them off until the trait is fully constified.

This means that implementing const Iterator has to be forbidden outside the standard library at first. Otherwise, removing a #[rustc_non_const_trait_method] attribute would be a breaking change.

@compiler-errors
Copy link
Member Author

Well, nothing is breaking on nightly. I don't think I clear when I posted this issue, but I only suggested this for experimentation purposes. By the time we stabilize const traits we'd have to get rid of it.

@RalfJung
Copy link
Member

Instead, we just slapped rustc_do_not_const_check onto all the methods, somewhat leaving us vulnerable to CTFE errors "post-mono" if any of the combinators ended up doing anything non-const.

I am fairly strongly opposed to that strategy. The attribute exists for use by the panic hooks and should not be used for anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants