Skip to content
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

The rust compiler is permissive of f32 and f64 suffix #922

Closed
wants to merge 2 commits into from

Conversation

philberty
Copy link

During development of gccrs it was found in PR Rust-GCC/gccrs#126 that the rust compiler is permissive of the float suffix on literals but the spec does not show this.

src/tokens.md Outdated Show resolved Hide resolved
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
@ehuss
Copy link
Contributor

ehuss commented Jan 8, 2021

Thanks for the PR! I think this is already covered in the floating point grammar:

DEC_LITERAL (. DEC_LITERAL)? FLOAT_EXPONENT? FLOAT_SUFFIX

Is there any particular reason to mention this as part of the integer grammar?

@Havvy
Copy link
Contributor

Havvy commented Jan 9, 2021

The floating point grammar, as quoted by ehuss, is defined at https://doc.rust-lang.org/stable/reference/tokens.html#floating-point-literals

The changes in this PR are factually incorrect, but there is at least one change that can be made: Adding 5f32 (or any other whole number...) as an example in the examples list. If you want to do that, go for it.

@philberty
Copy link
Author

Apologies if this is not the correct place to add this. When testing gccrs vs rust it was noticed that f32 and f64 suffix was allowed on integers abut the integer token spec didn't mention thus our lexer enforced that f32 and f64 was an invalid suffix for this integer token.

Maybe just adding f32 and f64 is enough to the list of accepted suffix types is enough for this change.

@ehuss
Copy link
Contributor

ehuss commented Jan 9, 2021

f32 and f64 suffixes are already listed in the FLOAT_LITERAL production. f32 and f64 suffixed DEC_LITERAL values aren't integers. The grammar needs to be considered as a whole to understand what kind of lookahead is necessary to parse the text to differentiate between different rules.

Havvy added a commit to Havvy/reference that referenced this pull request Jan 11, 2021
This seems to me to me the only actionable thing to the confusion in
pr rust-lang#922.

Also, move a link ref down to the rest of the link refs.
@Havvy
Copy link
Contributor

Havvy commented Jan 13, 2021

Since this PR is factually incorrect due to a misunderstanding of how to read the grammar, I am closing it.

Nonetheless, thanks for the attempt to help.

@Havvy Havvy closed this Jan 13, 2021
wsh pushed a commit to wsh/rust-reference that referenced this pull request Jan 17, 2021
This seems to me to me the only actionable thing to the confusion in
pr rust-lang#922.

Also, move a link ref down to the rest of the link refs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants