-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
constified implementations of Default
#86808
Conversation
r? @scottmcm (rust-highfive has picked a reviewer for you, use r? to override) |
What would be the policy for changing to |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Update: in this zulip thread we felt comfortable marking the feature not incomplete and start experimenting (non generic impls) in libstd. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Have the incomplete / not yet ready for use parts of the feature gate been split out yet? I'm not sure we should be using it until that has been done: we've run into ongoing trouble with specialization, for example, precisely because of the actually-not-ok bits in min_specialization. I'd prefer to avoid doing so with const trait if there are known limitations. Regardless, I think a decision from T-libs-api on what the policy for const-unstable trait impls should look like would be merited. I'm a little surprised this is possible since historically impls weren't possible to feature gate - is the story different in the const case for some reason? |
I don't think we currently have incomplete / not yet ready for use parts. There are actually aspects of the RFC that are yet to be implemented, but I don't think this PR can expose not-ok stuff to users.
AFAIK the stability should be inherited and maybe this is only true for const stability. But I did add a test for this: https://github.com/rust-lang/rust/blob/master/src/test/ui/rfc-2632-const-trait-impl/staged-api.rs |
Yes it is. const stability is a separate system that does not participate in trait resolution, so you don't get type-system unsoundness where a trait is both implemented and not. Instead you just get an error if you call a non-const impl from a const context. |
5510d43
to
77382fb
Compare
Ping @rust-lang/libs-api @rustbot label T-libs-api -S-waiting-on-review S-waiting-on-team |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a decision from T-libs-api on what the policy for const-unstable trait impls should look like would be merited.
I don't think we have any objection to starting to land const impls as long as they are properly gated, i.e. stable code cannot be broken by ongoing churn in the const impl feature, all the way through its stabilization or eventual removal. I can't judge that from the PR but if the compiler team asserts it's properly gated, then it's ready.
As for which impls to make const, I think the bar is going to be the same as for const inherent methods: it has to be reasonably usable in const or have an extremely strong justification otherwise. For example we regularly reject const on an inherent method of a type that is impossible to construct in const, even if that method's implementation is otherwise compatible with const.
I think:
Update: Upon digging further, I think it is actually fine to add impls that match any point above. The only case where I am unsure is traits where associated types have bounds. |
☔ The latest upstream changes (presumably #87725) made this pull request unmergeable. Please resolve the merge conflicts. |
When you say "non-generic" in this case you mean traits that don't have generic parameters like |
Sorry, to be clear, I meant that const impls without trait bounds other than @rustbot label -S-waiting-on-team S-waiting-on-review |
The libs-api team agrees to allow const_trait_impl to appear in the standard library as long as stable code cannot be broken (they are properly gated) this means if the compiler teams thinks it's okay, then it's okay. My priority on constifying would be: 1. Non-generic impls (e.g. Default) or generic impls with no bounds 2. Generic functions with bounds (that use const impls) 3. Generic impls with bounds 4. Impls for traits with associated types For people opening constification PRs: please cc me and/or oli-obk.
@bors r+ |
📌 Commit 6bd2ecb has been approved by |
⌛ Testing commit 6bd2ecb with merge 1805ef4dd4df410428fb1cd37a47f88781bc469c... |
💥 Test timed out |
@bors retry |
☀️ Test successful - checks-actions |
Constify ?-operator for Result and Option Try to make `?`-operator usable in `const fn` with `Result` and `Option`, see rust-lang#74935 . Note that the try-operator itself was constified in rust-lang#87237. TODO * [x] Add tests for const T -> T conversions * [x] cleanup commits * [x] Remove `#![allow(incomplete_features)]` * [?] Await decision in rust-lang#86808 - I'm not sure * [x] Await support for parsing `~const` in bootstrapping compiler * [x] Tracking issue(s)? - rust-lang#88674
No description provided.