-
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
Disambiguate between ()
as type and as value in const generic arguments
#66615
Comments
Note that
|
Would this require going back to the initial idea of trying to parse generic arguments as either types or values, disambiguating at a later stage where we know whether the parameter is a const or a type? |
@jplatte: this isn't going to be very convenient to fix. The problem is that we aren't going to be able to disambiguate until type-checking itself. (This is the same problem as the snippet below, which currently also fails, because it can't tell what #![feature(const_generics)]
struct X;
struct S<const X: u8>;
impl<const X: u8> S<X> {} // error: wrong number of const arguments: expected 1, found 0 |
Okay so in cases we can't tell whether we've got a type or a value during parsing, we need to try resolving both, correct? Is that already done or is value resolution only done if type resolution fails? |
The problem is that |
Yeah, that's what I was thinking. So we'll need to keep around both a resolved type and a resolved value in cases like the one you showed above. And in cases where something can't be resolved (at all or in the right namespace) but the number of arguments given is still correct, I guess we will need yet more information to produce a reasonable error message. |
@rustbot claim |
Is it useful to disambiguate between The disambiguation is done for |
It makes the language more consistent, though it's definitely a less useful case than with identifiers. Let's see how much additional complexity it adds to support this case, and if it seems disproportionate, then we can re-evaluate. |
@rustbot release-assignment |
I think at the very least we need to improve diagnostics here for |
I think we disallow unit rn, so that's the easier solution 😆 |
Yes, if we don't have compound data types at all, it doesn't make sense to have unit anyway. |
This is essentially the same problem as getting multi-segment paths working with const generics (#66104 (comment) and Zulip conversation), which really would be useful to allow. |
visited during project-const-generics triage, added to rust-lang/project-const-generics#42 but don't expect us to make much progress here. |
I wonder if we can resolve the unit value correctly here (though maybe it'll require a small hack), because this is quite unfortunate.
The text was updated successfully, but these errors were encountered: