-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
const_generics: parsing fails with const expression in type parameter #70753
Comments
I also tried this: macro_rules! n {
($t:ty) => {
std::mem::size_of::<$t>()
}
}
type B = Foo<n!(u8)>; But that does not work for a different reason:
|
It's not supposed to work. In general, it's not possible, using finite look-ahead ( With finite look-ahead, the best we can do is recognize that What we have currently encoded is that simple identifiers, literals, and generic arguments starting with
According to the rules for I've noted above, |
Ah, interesting, thank you for the explanation! That |
In the compiler implementation. ;) Most of const generics isn't documented in any user facing docs. The rustc-dev-guide might be the next best thing, but I don't think it's well documented here.
Sure, although it's sorta a duplicate of #61175. To implement the diagnostics here, we would need to snapshot the parser state before parsing an argument, then if parsing a type failed, we can backtrack and attempt parsing as an expression, emitting a suitable diagnostic for that. The drawback here is that backtracking can slow down the parser (and thus compile-times). Whether that is notable is something we'd need to measure. Perhaps it's not significant, in which case we could add those diagnostics. |
Up to you really whether you think the two issues are distinct enough to be worth keeping them both. You know better than I do :) |
It's documented in the const generics RFC. We don't have proper documentation for const generics yet, because it's a work in progress. |
It may be sufficient to revive @estebank's following pull requests here: |
If no-one else is intending to take this issue, I'm going to take a look at it this weekend. |
I tried this code:
It fails to parse with
I assume that this is supposed to work though, since this code is accepted:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: