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

Bounds checking for float literals #2252

Closed
catamorphism opened this issue Apr 19, 2012 · 8 comments
Closed

Bounds checking for float literals #2252

catamorphism opened this issue Apr 19, 2012 · 8 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-parser Area: The parsing of Rust source code to an AST

Comments

@catamorphism
Copy link
Contributor

As per a FIXME in syntax::parse::lexer, check (maybe in the parser, definitely somewhere earlier than trans) that 32-bit and 64-bit floating-point literals are in the right range.

@z0w0
Copy link
Contributor

z0w0 commented Apr 23, 2013

How exactly can I implement this in the parser? LIT_FLOAT takes an ident, so would I make LIT_FLOAT take an f64 and then parse it using f32:: for explicitly marked f32 suffixes and f64:: for f64 suffixes and then raise an error if there is an error parsing them? Where/how is this handled for ints?

@emberian
Copy link
Member

emberian commented Jul 1, 2013

See also #4220. @z0w0 it isn't handled for any literal, that's part of the problem.

@thestinger
Copy link
Contributor

This is still not implemented.

@catamorphism
Copy link
Contributor Author

De-milestoning, we agreed it's not a major concern.

@pnkfelix
Copy link
Member

cc me

@huonw
Copy link
Member

huonw commented Jan 31, 2014

Triage, no change.

@emberian
Copy link
Member

Unmarking as easy. Correct string floatification isn't trivial, and Rust doesn't have anything for it today.

@steveklabnik
Copy link
Member

Today, we have

hello.rs:2:18: 2:60 warning: literal out of range for f32, #[warn(overflowing_literals)] on by default
hello.rs:2     let x: f32 = 1000000000000000000000000000000000000000.0;
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So seems good!

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Format tests with rustfmt (225-275 of 300)

Extracted from rust-lang#2097.

These cases all involve a line comment at the end of a block that rustfmt has chosen to wrap.

```diff
- unsafe { (*ptr).set(20); } //~ ERROR does not exist in the borrow stack
+ unsafe {
+     (*ptr).set(20);
+ } //~ ERROR does not exist in the borrow stack
```

I have moved all of those comments back onto the same line as the content of the block instead, as was indicated being `@RalfJung's` preference in rust-lang/miri#2097 (comment).

```diff
+ unsafe {
+     (*ptr).set(20); //~ ERROR does not exist in the borrow stack
+ }
```
BoxyUwU pushed a commit to BoxyUwU/rust that referenced this issue Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-parser Area: The parsing of Rust source code to an AST
Projects
None yet
Development

No branches or pull requests

7 participants