-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 generic arguments should be disambiguated from type arguments #60804
Comments
Do you think I could help with this? I've never contributed to rustc before, so I don't know if this is beginner difficulty... |
@imbrem: you are welcome to try, but I think it's probably not going to be straightforward to resolve this. The general idea is to introduce a new variant to I think the main problem is that we do some things depending on whether a parameter represents a type or constant before lowering to the HIR, and if we don't know which of the two it is, it might make some checks difficult. I haven't tried doing this properly, so I'm not sure how much of a problem this will actually turn out to be. (It's also possible that we don't have enough information till type-checking, so we might not be able to resolve these ambiguities until after lowering.) Fixing this is probably going to involve some experimentation, and I don't know how hard this will be ahead-of-time. If you want to give it a try, you're welcome to, and I can try to answer questions, but there are probably easier issues to tackle (i.e. |
Well, I've got an hour, so I'll give it a shot and see where it leads |
The best existing analogy to |
@imbrem: this is essentially the issue (but yes, the (The reason it doesn't hit the const block is because |
@varkor so does that mean On one hand, Rust seems to like to syntactically differentiate things (e.g. lifetimes vs types). On the other hand, I feel like from a type theoretic perspective having values and types be treated the same, at least in one context, is a lot cleaner. Could also be really nice if, in the far future, we get more dependent typing features... |
As long as there aren't any other location where we know that a generic argument is a type (and I don't think there are), yes.
As you say, this is entirely a syntactic ambiguity. For the most part, types and constants are treated quite differently. I don't think this is in general something we want to move towards. |
@eddyb suggested the following variant: GenericArg::Ident {
ident: Ident,
ty_res: Res,
val_res: Res,
} |
So, I looked into this a bit more, and this feature doesn't even require extending AST structures. |
@petrochenkov: if you actually have a fix for this, you're very welcome to take it — I only assigned myself to remind myself to get to it, but I don't think I'll have time very soon. Thanks for investigating, in any case! |
No, I don't have a ready fix. |
I'm working on this currently :) |
@jplatte Do you have any update on your progress on this issue? |
No, sorry. I've been busy with another project. If you want to take over, there is some discussion about the implementation on zulip. |
@jplatte I certainly understand getting busy with other projects. I'll see if I can't move this forward a little from the work you did. |
At the moment, const arguments have to be wrapped in curly brackets, even if they are parameters.
E.g.
Due to:
https://github.com/rust-lang/rust/blob/036e368d6883e0bc141c1b54578876cd5bfb2468/src/libsyntax/parse/parser.rs#L5952-L5957
Edit: Direct repro: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=85fcc01c6258677c94c5a8cd3d144cbe
The text was updated successfully, but these errors were encountered: