-
Notifications
You must be signed in to change notification settings - Fork 13k
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
move some invalid exponent detection into rustc_session #131656
base: master
Are you sure you want to change the base?
move some invalid exponent detection into rustc_session #131656
Conversation
rustbot has assigned @petrochenkov. Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8b41315
to
e8c244e
Compare
This comment has been minimized.
This comment has been minimized.
a642bff
to
82a8103
Compare
This comment has been minimized.
This comment has been minimized.
I've added some ui tests and I think this is now ready for review. It doesn't stop @petrochenkov changing the whole thing later if they so choose. |
This comment has been minimized.
This comment has been minimized.
Apologies for the delays. |
This PR moves part of the exponent checks from
rustc_lexer
/rustc_parser
intorustc_session
.This change does not affect which programs are accepted by the complier, or the diagnostics that are reported, with one main exception. That exception is that floats or ints with suffixes beginning with
e
are rejected after the token stream is passed to proc macros, rather than being rejected by the parser as was the case. This gives proc macro authors more consistent access to numeric literals: currently a proc macro could interpret1m
or30s
but not7eggs
or3em
. After this change all are handled the same. The lexer will still reject input if it containse
followed by a number,+
/-
, or_
if they are not followed by a valid integer literal (number +_
), but this doesn't affect macro authors who just want to access alpha suffixes.This PR is a continuation of #79912. In that PR, it was suggested that a new enum was used to indicate type of exponent (whether accepted or rejected). I originally took that approach with this PR, but it didn't seem necessary and made the changes more complex. I can try to go down that road instead if that's the consensus. It is also solving exactly the same problem as #111628.
TODO before ready for review (assuming approach is OK)
1em
)e
(if suffix begins with 'e' suggest an exponential)Currently if the character following theThis now handles arbitrarye
is_
, then the lexer tries to parse an exponent and fails if there are no digits after. The issue is that a valid integer can have any number of_
s before the digit, meaning deciding whether a the suffix is a number or not requires unbounded lookahead. There are a few options here_
s, removing the special case.Although I haven't marked this PR as 'ready for review' since there are outstanding stuff that need doing, I do want to get feedback on the approach.Ready for review now.Also do you want me to write an MCP
r: @petrochenkov, since they reviewed #79912.