Closed Y-Nak closed 7 months ago
@Y-Nak Will we allow dependent functions, with a return type that depends on the value of an argument? Eg
pub struct X<const N: u8> {}
pub fn bar(n: u8) -> X {
return X<n>{}
}
In the current implementation, should the syntax of -> X
be allowed, or should there be an error? (There currently isn't an error)
This PR is pretty restrictive so that we can introduce the basic const generics. I should've titled this PR as basic const generics
rather than dependent types(I couldn't make up my mind whether I should continue implementing a genuine dependent type system in this PR when I implemented this PR, then forgot to rename this in my mind).
So, for now, your example should be an error(I fixed this bug).
I'm trying to design a more sophisticated type system now in the separate PR, which will allow the snippet below.
pub struct X<const N: u8> {}
pub fn bar(n: u8) -> X<n> {
return X<n>{}
}
This PR introduces basic const types. Currently, there are some restrictions on the usage of const types, which will be mitigated when a type checker is implemented.
Usage
ADTs, functions, and traits can be declared with const type parameters. The basic example would be
Const type parameters can treated in the same way as normal type parameters in trait or method implementation. e.g.,
Limitations
There are two major restrictions on the type system.
bool
and integral types(e.g.,u8
,u16
, ...) are allowed for a const type.These limitations will be mitigated when we redesign type system.
MIsc
Replace
fxhash
withrustc_hash
inparser2
.