File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ # Generic const param types
2+
3+ We want to support the types of const parameters
4+ to depend on other generic parameters.
5+ ``` rust
6+ fn foo <const LEN : usize , const ARR : [u8 ; LEN ]>() -> [u8 ; LEN ] {
7+ ARR
8+ }
9+ ```
10+
11+ This is currently forbidden during name resolution.
12+
13+ Probably the biggest blocker is type-checking const arguments
14+ for generic parameters. This currently uses [ a hack] [ WithOptConstParam ]
15+ to supply the ` DefId ` of the corresponding const parameter.
16+
17+ Now, let's look at the following:
18+ ``` rust
19+ fn foo <const N : usize , const M : [u8 ; N ]>() {}
20+
21+ fn bar () {
22+ foo :: <3 , { [0 ; 3 ] }>();
23+ }
24+ ```
25+ Here the expected type of ` { [0; 3] } ` should be ` [u8; 3] ` . With the
26+ current approach it is ` [u8; N] ` instead. To fix this we would have to
27+ supply the affected queries the expected type of the const argument itself
28+ or use a ` (DefId, SubstsRef<'tcx>) ` pair instead.
29+
30+ Doing so isn't trivial because we have to worry about accidentially
31+ ending up with different types for the same const argument which would
32+ break stuff.
33+
34+ Potential dangers include partially resolved types and projections.
35+
36+ [ WithOptConstParam ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.WithOptConstParam.html
You can’t perform that action at this time.
0 commit comments