-
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
Underscore suffixes allowed in literals #41723
Comments
According to the reference, decimal points are optionally followed by another "decimal literal". Since Here the parser is recognizing In addition, the reference says |
It seems to me that @arielb1 points out that Basically, I do not expect a suffix to begin with |
Shifting nomination to T-lang for now. |
The language team discussed this in today's meeting. We also considered cases like (By contrast, So, the recommendation from the language team would be to always parse One question that didn't come up in the language team meeting: does anything rely on the current (apparently inconsistent) lexing behavior here? Would fixing this ambiguity break anything? |
I'll try to write a patch for this issue. |
I would think not, at least for numbers, given that it results in an error. Not sure about |
…loat, r=petrochenkov Disallow ._ in float literal. This patch makes lexer stop parsing number literals before `._`, as well as before `.a`. Underscore itself is still allowed like in `4_000_000.000_000_`. Fixes a half part of rust-lang#41723. The other is `""_`.
…loat, r=petrochenkov Disallow ._ in float literal. This patch makes lexer stop parsing number literals before `._`, as well as before `.a`. Underscore itself is still allowed like in `4_000_000.000_000_`. Fixes a half part of rust-lang#41723. The other is `""_`.
…loat, r=petrochenkov Disallow ._ in float literal. This patch makes lexer stop parsing number literals before `._`, as well as before `.a`. Underscore itself is still allowed like in `4_000_000.000_000_`. Fixes a half part of rust-lang#41723. The other is `""_`.
Do you mean by "never include" also forbidding literals like |
@qnighy No, that's fine. I meant specifically that |
@joshtriplett I see. Then #41946 and #41990 will close this issue. |
…ike-literals, r=nikomatsakis Disallow underscore suffix for string-like literals. This patch turns string/bytestring/char/byte literals followed by an underscore, like `"Foo"_`, to an error. `scan_optional_raw_name` will parse `_` as a valid raw name, but it will be rejected by the parser. I also considered just stopping parsing when the suffix is `_`, but in that case `"Foo"_` will be lexed as two valid tokens. Fixes the latter half of #41723.
I found these pathlogical examples pass the lexer and the parser:
The reason is that
scan_optional_raw_name
eats_
, but reports no suffix.scan_number
distinguishes between decimal points and field/method syntax byis_xid_start
, which in fact excludes_
.According to the reference, it seems these examples shouldn't be allowed.
Tested on stable (
rustc 1.17.0 (56124baa9 2017-04-24)
) and nightly (rustc 1.19.0-nightly (6a5fc9eec 2017-05-02)
) on the playground.The text was updated successfully, but these errors were encountered: