-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Unable to parse expression a as usize < b
#22644
Comments
|
Maybe we can at least detect the ambiguous cases and provide a hint. |
At least Scala, Nemerle, Nim and Boo began to use square brackets for type parameters. Is there any reason why Rust can not do the same? I think it would significant simplify parsing and get rid of ambiguities. |
That is my preference as well, but the discussion already happened and a decision was made (before my time, I believe). |
We use |
@huonw, actually no, because unlike |
I don't thinks that's totally the reason. The token sequence Of course, it is probably rarer that one wishes to index a cast expression, so using In any case, the generic syntax is here to stay. There's been more than enough discussion about it (e.g. rust-lang/rfcs#148). |
Is If we don't accept I'd love to write a PoC for this. And if my idea's totally wrong, I guess I'll find out soon. (like in |
The question of how to properly parsing sequence |
At least I don't see the possibility we change the syntax on 1.x |
The ambiguity on I believe fixing this issue means we can also drop the I think introducing an C#-style disambiguation rule could possibly solve this issue with only very minor breaking changes. (these were also breaking changes in C# when generics were introduced in version 2.0, and affected very little code) |
I don't know about C#, but it's responsible for some of the ugliest special cases in C++ syntax, like void f() {
T::template g<int>();
} |
C++ needs a symbol table for parsing. |
I agree that we don't want to copy C++'s mistakes here. The idea is: when the parser encounters a
Note that if this heuristic is wrong, the user can always choose force one or the other interpretation: Putting parentheses around the less-than operator (e.g.
We can also exploit the fact that RFC 558 makes I think this heuristic will work well enough that stuff will "just work" in most cases. Upsides:
Downsides:
|
I think #20078 is the same underlying issue. |
I wonder why in this example the comparison is prioritized but in a line such as thread_local!(static LOCAL:Cell<u32>=Cell::new(0)); the comparison operator is resolved first. The above code yields:
|
Because |
anyway, |
@arielb1 Thanks. I guess I now have a real reason to change my coding style. Regarding the other problem, wish you good luck fixing that…. |
@dgrunwald We had this discussion back when RFC 558 was accepted and determined that such a scheme wouldn't allow us to get rid of |
@bstrie: The C#-style lookahead heuristic in my comment works for arity > 1; it just requires adding parentheses to disambiguate some rare cases (it never requires It doesn't require exploiting RFC 558 for the disambiguation. RFC 558 could theoretically be used to improve the heuristic (no need to look at the token following The ugliness of The main downside of the C#-style heuristic is that future additions to the type-level syntax would be breaking changes. So I think this should be postponed until type-level integer syntax is worked out. |
Duplicate of #11962? |
Yes, though there is more discussion here. |
Learn to parse `a as usize < b` Parsing `a as usize > b` always works, but `a as usize < b` was a parsing error because the parser would think the `<` started a generic type argument for `usize`. The parser now attempts to parse as before, and if a DiagnosticError is returned, try to parse again as a type with no generic arguments. If this fails, return the original `DiagnosticError`. Fix #22644.
It seems like the parser tries to read the type where it isn't:
I think it's rather strange that the operator
>
works, but the operator<
doesn't at the same place.rustc 1.0.0-nightly (522d09dfe 2015-02-19) (built 2015-02-20)
The text was updated successfully, but these errors were encountered: