-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fixes missing overflow lint for i64 #15709
Conversation
Could you improve the commit message and PR description to actually describe what is being fixed, so that it stands somewhat independently of the issue? |
Also, hm, shouldn't this be part of the type-overflow lint, not a syntax error? |
@huonw is correct, this is not an appropriate syntax error. Personally, I think that integral literals in the AST simply need to support unsized values (or at least, absurdly-sized values). This will be necessary if we ever want to add support for user-defined types to be initialized from literals (e.g. A smaller change might be to add a |
Alternatively, |
Your suggestions seem plausible for a clean implementation of a c-like behaviour. |
@hirschenberger That doesn't work (during parsing), if for no other reason than that it cannot possibly work for unsuffixed literals. If the parser forbids wraparound of suffixed literals, people will expect it to forbid wraparound in general, and will get surprising behavior when the inferred type of an unsuffixed literal causes wraparound. This is why it's far more appropriate to put in a lint, which can actually warn about unsuffixed literals too. |
Yes, that's correct, i'll try to implement this, which of your suggested solutions do you prefer? I think combining all |
I think combining all of |
Who would be appropriate? Can you CC someone or does it even need to be discussed in an RFC? |
@hirschenberger libsyntax changes generally don't need to be discussed in an RFC (assuming it's not changing the syntax or semantics of the language). Offhand I don't know who has the most experience with this sort of thing. Perhaps @cmr or @alexcrichton might have an opinion. |
No, small changes to the structure of libsyntax don't need an RFC. If you're feeling good you can mark them with breaking-change, but even that's not all too necessary. I agree with others on this PR, many of our other messages about literals being out of range and such are all lints instead of compile-time errors, so it seems reasonable to keep up the trend. |
I merged the Overflowing |
I think |
What about this issue, any suggestions, hints, wishes? |
At first glance it looks ok to me, but I'd rather let someone else with more experience with the AST review it. |
@kballard Who would be appropriate? |
Not sure. @alexcrichton? @cmr? |
The `type_overflow` lint, doesn't catch the overflow for `i64` because the overflow happens earlier in the parse phase when the `u64` as biggest possible int gets casted to `i64` , without checking the for overflows. We can't lint in the parse phase, so a refactoring of the `LitInt` type was necessary. The types `LitInt`, `LitUint` and `LitIntUnsuffixed` where merged to one type `LitInt` which stores it's value as `u64`. An additional parameter was added which indicate the signedness of the type and the sign of the value.
Ok, I fixed the compile error. Unfortunately Travis has problems with a test which unrelated to my changes. So I think it's ready to roll. |
Fixes missing overflow lint for i64 #14269 The `type_overflow` lint, doesn't catch the overflow for `i64` because the overflow happens earlier in the parse phase when the `u64` as biggest possible int gets casted to `i64` , without checking the for overflows. We can't lint in the parse phase, so we emit a compiler error, as we do for overflowing `u64` Perhaps a consistent behaviour would be to emit a parse error for *all* overflowing integer types. See #14269
fix: Recognize custom main function as binary entrypoint for runnables
Fixes missing overflow lint for i64 #14269
The
type_overflow
lint, doesn't catch the overflow fori64
because the overflow happens earlier in the parse phase when theu64
as biggest possible int gets casted toi64
, without checking the foroverflows.
We can't lint in the parse phase, so we emit a compiler error, as we do for overflowing
u64
Perhaps a consistent behaviour would be to emit a parse error for all overflowing integer types.
See #14269