You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking issue for RFC 2438, "Deny the overflowing_literals lint for the 2018 edition" #54502
On Sep 28, 2018, at 8:59 AM, Felix S Klock II ***@***.***> wrote:
The decision of what to do at this point is probably best laid in the hands of the docs team, not the compiler team.
So I'm unassigning myself, reassigning the issue to the docs team, and tagging with I-nominated to try to promote its discussion amongst that team.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
Well I couldn't find any reason for it to only be deny by default on the 2018 edition so I've submitted #55632 to make it deny by default on all editions.
This broke some of my doc test code in inkwell while updating to 2018e which looked like this: assert_eq!(0b1110_0000i8 >> 1, 0b1111_0000i8);
It was used as an example as to how sign extended bitshifting works.
I don't really understand why this isn't valid. For example, looking at an even simpler example: let _x = 0b1110_0000i8; also won't compile:
error: literal out of range for i8
--> src/main.rs:2:14
|
2 |let _x = 0b1110_0000i8;| ^^^^^^^^^^^^^ help: consider using `u8` instead: `0b1110_0000u8`|
= note: #[deny(overflowing_literals)] on by default
= note: the literal `0b1110_0000i8` (decimal `224`) does not fit into an `i8` and will become `-32i8`
However, it is my intent to specify the bit representation of an -32i8 (and it clearly has the i8 suffix), so how is this an overflow?
Rust's literals are not the bit representation of the final value. If they were, you'd get different result depending on whether you are on a big endian or a little endian machine (ok not for u8 and i8, but everything else).
Instead the binary literals are the canonical binary representation of a positive integer, just like decimal literals are the canonical decimal representation of a positive integer. If you write 255_i8 that's the same thing as writing 0b1111_1111_i8, and 255 is not a valid i8.
Activity
Centril commentedon Sep 23, 2018
Marked as P-high for T-compiler due to edition 2018.
eddyb commentedon Sep 23, 2018
@nikomatsakis Do we have a mechanism for per-edition default lint levels?
varkor commentedon Sep 23, 2018
Yes we do. We should just be able to replace:
https://github.com/rust-lang/rust/blob/f0bae412e97db7ef26e24546bce5199c6a086152/src/librustc_lint/types.rs#L38-L42
with:
ollie27 commentedon Sep 23, 2018
Is there any reason it can't be made deny by default in the 2015 edition as well?
Auto merge of #54507 - csmoe:deny_overflow, r=varkor
Centril commentedon Sep 24, 2018
Documentation is still todo
5 remaining items
steveklabnik commentedon Sep 30, 2018
ollie27 commentedon Nov 2, 2018
Well I couldn't find any reason for it to only be deny by default on the 2018 edition so I've submitted #55632 to make it deny by default on all editions.
Centril commentedon Feb 25, 2019
Only rust-lang/edition-guide#146 remains now that #55632 is merged; closing therefore.
TheDan64 commentedon Mar 13, 2019
This broke some of my doc test code in inkwell while updating to 2018e which looked like this:
assert_eq!(0b1110_0000i8 >> 1, 0b1111_0000i8);It was used as an example as to how sign extended bitshifting works.
I don't really understand why this isn't valid. For example, looking at an even simpler example:
let _x = 0b1110_0000i8;also won't compile:However, it is my intent to specify the bit representation of an
-32i8(and it clearly has the i8 suffix), so how is this an overflow?oli-obk commentedon Mar 13, 2019
Rust's literals are not the bit representation of the final value. If they were, you'd get different result depending on whether you are on a big endian or a little endian machine (ok not for
u8andi8, but everything else).Instead the binary literals are the canonical binary representation of a positive integer, just like decimal literals are the canonical decimal representation of a positive integer. If you write
255_i8that's the same thing as writing0b1111_1111_i8, and255is not a validi8.TheDan64 commentedon Mar 13, 2019
I guess that makes sense, thanks for explaining. But it's certainly surprising behavior