-
Notifications
You must be signed in to change notification settings - Fork 48
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
Experiment: Generic const items #214
Labels
Comments
As before, I'm happy to second/liason an experiment for this. We already have cc @rust-lang/lang in case anyone wants to raise an objection. |
This was referenced Jul 14, 2023
@fmease We briefly raised this in the lang team meeting today, and there were still no objections, so the experiment is approved to move forward! |
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Jul 28, 2023
Implement generic const items This implements generic parameters and where-clauses on free and associated const items under the experimental feature gate `generic_const_items`. See rust-lang/lang-team#214. Tracking issue: rust-lang#113521. Fixes rust-lang#104400. This PR doesn't include rustfmt support as per [nightly style procedure](https://github.com/rust-lang/style-team/blob/master/nightly-style-procedure.md) and it doesn't add rustdoc JSON support (see [related Zulip topic](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Rustdoc.20JSON.3A.20Experimental.20rustc.20features)). CC `@scottmcm` `@compiler-errors` `@WalterSmuts` r? `@oli-obk` <details><summary>Resolved Questions</summary> * Q: Should `const ADD<const N: usize, const M: usize>: usize = N + M; ADD::<0, 1>` trigger the error *generic parameters may not be used in const operations* (which can be unlocked with `#![feature(generic_const_exprs)]`). Currently it doesn't. Or does this fall under [this paragraph](https://github.com/rust-lang/rust/blob/71f71a5397c42fec01f5c1045c638d961fa9f7ca/compiler/rustc_resolve/src/late.rs#L191)? * A: No, rust-lang#113522 (comment) * Q: Should `const UNUSED: () = () where String: Copy;` (with `#![feature(trivial_bounds)]` and with `UNUSED` unused) succeed compilation? Currently it doesn't: *evaluation of constant value failed // entering unreachable code* * A: Yes, but postponed until stabilization (latest), rust-lang#113522 (comment) </details>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the current version of Rust it is impossible to place generic parameters and where-clauses on free and associated constant items. This limits developers in their expressive power and renders certain desired functionality unattainable.
I hereby propose an experiment carried out by me in which the compiler gets extended to support generic const items addressing the aforementioned shortcoming of the language in an attempt to identify benefits and concerns in preparation for an RFC.
Motivation and use-cases
In no particular order:
TyCtxtConsts::<'tcx>::DEREF_PROJECTION
(example kindly provided by @compiler-errors)generic_const_exprs
) on constant items unblocking many useful patterns. See also no place to add evaluatable bounds to assoc const items rust#104400.generic_const_exprs
. See also https://lcnr.de/blog/generic-const-expressions/where Self: Sized
to each associated constant just like they would do with associated functions and types. See also Don't require associated types with Self: Sized bounds indyn Trait
objects rust#112319.Links
Initial people involved
The text was updated successfully, but these errors were encountered: