Is it possible to create "constrained ordinal" types ala pascal?
e.g. say you need numbers only 1..100 and anything else to compile error on literals and runtime error on out of range. Internally it'd be stored and behave exactly like u8 with the added constraints.
This could be really useful for coordinate systems and such where certain values are out of range. Catching any constant/compile time violations is a nice bonus too.
Not until const-generics becomes more powerful, you can track const-generics here
opened 11:17PM - 14 Sep 17 UTC
closed 03:26PM - 21 Mar 22 UTC
A-typesystem
B-RFC-approved
T-lang
T-compiler
A-const-fn
C-tracking-issue
A-const-generics
requires-nightly
F-const_generics
S-tracking-impl-incomplete
Tracking issue for rust-lang/rfcs#2000
Updates:
- 2 May 2019: https://github… .com/rust-lang/rust/issues/44580#issuecomment-488819344
- 19 Oct 2019: https://github.com/rust-lang/rust/issues/44580#issuecomment-544155666
- 2 Jan 2020: https://github.com/rust-lang/rust/issues/44580#issuecomment-570191702
- 22 Jul 2020: https://github.com/rust-lang/rust/issues/44580#issuecomment-662543117
- 17 Nov 2020: https://github.com/rust-lang/rust/issues/44580#issuecomment-728913127
- 11 Dez 2021: https://github.com/rust-lang/rust/issues/44580#issuecomment-991782799
If you want to help out, take a look at the [open const generics issues](https://github.com/rust-lang/rust/labels/A-const-generics) and feel free to ping @varkor, @eddyb, @yodaldevoid, @oli-obk or @lcnr for help in getting started!
---
Blocking stabilization:
- [ ] Design:
- [x] Resolving ordering of const and type parameters, with default parameters
- [ ] Decide what the best UX / implementation cost balance is for unifying abstract const expressions.
- [ ] How we determine well formedness of const expressions.
- [x] Implementation
- [ ] Documentation
- [ ] rustc guide
---
Remaining implementation issues:
- [ ] Resolve various `FIXME(const_generics)` comments.
- [ ] Resolve concerns with canonicalisation / lazy normalisation.
- [ ] Investigate handling of const parameters in patterns.
- [ ] Add more tests.
- [ ] Implement defaults for const parameters (`FIXME(const_generics_defaults)`).
- [ ] Fix other [A-const-generics issues](https://github.com/rust-lang/rust/labels/A-const-generics).
- [ ] Audit uses of `has_infer_types`.
- [x] Forbid complex expressions for const arguments involving parameters (for now), e.g. `{X * 2}`.
- [ ] Audit diagnostics (e.g. https://github.com/rust-lang/rust/pull/76401#discussion_r484819320).
Didn't realize that's a use case for const generics but it makes sense now. Makes me a bit sad, seems like rust is desperately missing them for a lot of things. I wish const generics got the attention of async/await instead...
2 Likes
system
Closed
December 10, 2019, 3:03am
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.