worik
December 4, 2018, 10:08pm
1
If I have the code:
const fixed_thing[usize;3] = [1,2,3,4];
I get error:
29 | const fixed_thing:[usize;3] = [1,2,3,4];
| ^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 4 elements
|
= note: expected type `[usize; 3]`
found type `[usize; 4]`
Fair enough. Except why can I not write:
const fixed_thing:[usize;] = [1,2,3,4];
The compiler has all the information that it needs to determine the size of the object. What am I missing?
This has been asked before
https://github.com/rust-lang/rust/issues/40269
and const generics may help with it
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).
1 Like