Uh oh!
There was an error while loading. Please reload this page.
Lint overflowing integer casts in const prop - #67676
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
a186122 to
60a3038Comparewesleywiser
commented
Dec 28, 2019
Force pushed with new error message |
60a3038 to
554458fCompare
This comment has been minimized.
This comment has been minimized.
554458f to
afb73a6Comparewesleywiser
commented
Dec 28, 2019
Blessed tests |
Uh oh!
There was an error while loading. Please reload this page.
9c5b7e2 to
df79825Compareoli-obk
commented
Dec 29, 2019
r=me with a comment about the weird zst situation added |
wesleywiser
commented
Dec 29, 2019
@bors r=oli-bok |
bors
commented
Dec 29, 2019
📌 Commit d2eddfe7d139051df4ad569224b5d97dee395698 has been approved by |
This extends the invalid cases we catch in const prop to include overflowing integer casts using the same machinery as the overflowing binary and unary operation logic.
d2eddfe to
001cea4Comparewesleywiser
commented
Dec 31, 2019
Rebased @bors r=oli-obk |
bors
commented
Dec 31, 2019
📌 Commit 001cea4 has been approved by |
…sts, r=oli-obk Lint overflowing integer casts in const prop This extends the invalid cases we catch in const prop to include overflowing integer casts using the same machinery as the overflowing binary and unary operation logic. r? @oli-obk
Dylan-DPC-zz
commented
Jan 1, 2020
bors
commented
Jan 1, 2020
Lint overflowing integer casts in const prop This extends the invalid cases we catch in const prop to include overflowing integer casts using the same machinery as the overflowing binary and unary operation logic. r? @oli-obk
bors
commented
Jan 2, 2020
☀️ Test successful - checks-azure |
rust-highfive
commented
Jan 2, 2020
Tested on commit rust-lang/rust@0ec3706. Direct link to PR: <rust-lang/rust#67676> 💔 miri on windows: test-pass → test-fail (cc @oli-obk@eddyb@RalfJung, @rust-lang/infra). 💔 miri on linux: test-pass → test-fail (cc @oli-obk@eddyb@RalfJung, @rust-lang/infra).
To me it looks like the lint is handling enum variants incorrectly: enumSigned{Bar = -42,Baz,Quux = 100,}fnsigned() -> [i8;3]{let baz = Signed::Baz;// let-expansion changes the MIR significantly[Signed::Barasi8, baz asi8,Signed::Quuxasi8]}This errors at Cc https://github.com/rust-lang/miri/pull/1138/files#r362443894 |
wesleywiser
commented
Jan 2, 2020
@RalfJung Yeah, you're totally correct. I'm surprised we don't have any tests that exercise this code in |
SimonSapin
commented
Jan 2, 2020
The premise of this PR seems flawed. Truncating is in some cases the legitimate desired behavior, and Compare with overflow checking in |
wesleywiser
commented
Jan 2, 2020
@SimonSapin The lint does not fire on every instance of To draw a comparison with the let x = 1026u16asu8;// lint fires herelet y = (1026u16&0x00FFu16)asu8;// lint does not fire here |
SimonSapin
commented
Jan 2, 2020
It is unfortunate that there is no way to tell intentional truncation apart from accidental truncation, and https://internals.rust-lang.org/t/pre-rfc-add-explicitly-named-numeric-conversion-apis/11395 tries to fix that, but it is a fact of today’s Rust. |
oli-obk
commented
Jan 2, 2020
It's not an error and not a stability problem because it's just a lint that you can turn off (even locally). I suggest you disable the lint for your code instead of using a workaround. |
SimonSapin
commented
Jan 2, 2020
https://perf.rust-lang.org/status.html currently shows: […] error: truncating cast: the value 4294967292 requires 32 bits but the target type is only 16 bits
--> /tmp/.tmpmCOmcQ/target/debug/build/style-f46d78432390fdd0/out/gecko_properties.rs:10050:21
|
10050 | structs::NS_FONT_STRETCH_ULTRA_CONDENSEDasi16,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[deny(const_err)]` on by default(I don’t know if there is a permanent URL for this log.) pubconstNS_FONT_STRETCH_ULTRA_CONDENSED:::std::os::raw::c_int = -4;However I didn’t manage to reproduce the error with this reduction: pubconstA:::std::os::raw::c_int = -4;pubconstB:i16 = Aasi16;fnmain(){dbg!(B);}and
The above shows there’s at least one case in the wild of previously-valid code where this lint triggers. This suggests that Crater is needed to determine how much of a stability issue it is to make this lint deny by default. |
lqd
commented
Jan 2, 2020
This may be a case similar to the bug Ralf pointed out earlier |
oli-obk
commented
Jan 2, 2020
Yes, the lint has a signedness bug |
SimonSapin
commented
Jan 2, 2020
Two separate things:
|
wesleywiser
commented
Jan 2, 2020
|
Thank you for taking care of the revert. Intentional cases are not gonna look like literally constBITS:u16 = 0x1234;let upper = (BITS >> 8)asu8;let lower = BITSasu8; |
oli-obk
commented
Jan 2, 2020
I disagree that
Something like
That seems nearly impossible to do. Just like it's super hard to really prove with data that using Though since we are doing that in clippy, if we had a Second: So... while there are ways to move forward for general truncation casts, the situation we have here is that we statically know that you are truncating a value. We are allowed to add more lints for statically knowing that the user is doing something buggy as per RFC 1229. The example from that RFC is let x = 5u32 << 42;which actually used to be a hard error and we weakened it to the That example from the RFC is in fact also a truncation causing the bitshift to be
So the big difference between this new trigger of the lint is that it's not triggering on behaviour that panics at runtime with debug assertions. Which brings us back to the question "should For now, let's leave such lints to clippy until we have a way to truncate via |
Reverts part of rust-lang#67676
Reverts part of rust-lang#67676
SimonSapin
commented
Jan 3, 2020
Yes, and we’re not making lossless
This is pretty much my point, but not what this PR does. |
Revert `const_err` lint checking of casts Reverts part of rust-lang#67676 r? @oli-obk cc @SimonSapin
This extends the invalid cases we catch in const prop to include
overflowing integer casts using the same machinery as the overflowing
binary and unary operation logic.
r? @oli-obk