-
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
const_prop_lint can't tell when code guarded with && is dead #113905
Comments
Here's a significantly more silly minimized version: if false && false {
let _ = 1u64 << 64;
} The problem is that the lint here has trouble seeing that code is dead. Something about the way we lower |
#111752 may help with that. To check once it lands. |
Even this code also don't have a lint? if false {
let _ = 1u64 << 64;
} I expect something like |
@chenyukang In current stable, that code correctly does not have a lint. In 1.69 and before, it actually did hit this lint. So things have gotten better recently, but it's still too easy to hit these scuffed cases. |
The result of 1.67.1 for code: fn main() {
if 1 < 2 {
let _ = 1u64 << 64;
} else {
let v = 1u64 << 64;
eprintln!("v: {:?}", v);
}
} is: ~/rust ❯❯❯ rustc ./p/if.rs
error: this arithmetic operation will overflow
--> ./p/if.rs:3:17
|
3 | let _ = 1u64 << 64;
| ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow
|
= note: `#[deny(arithmetic_overflow)]` on by default
error: this arithmetic operation will overflow
--> ./p/if.rs:5:17
|
5 | let v = 1u64 << 64;
| ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow
error: aborting due to 2 previous errors Should we check the ~/rust ❯❯❯ rustc ./p/if.rs
error: this arithmetic operation will overflow
--> ./p/if.rs:3:17
|
3 | let _ = 1u64 << 64;
| ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow
|
= note: `#[deny(arithmetic_overflow)]` on by default
error: this block is unreachable
--> ./p/if.rs:5:17
|
5 | let v = 1u64 << 64;
|
error: aborting due to 2 previous errors We have
|
The lint that we are discussing here lints by running the const eval interpreter. We definitely should not warn or error on |
I think this is a duplicate of #109731? |
Output on fn main() {
if 1 < 2 {
let _ = 1u64 << 64;
} else {
let v = 1u64 << 64;
eprintln!("v: {:?}", v);
}
} Output:
|
I tried this code:
I expected to see this happen: i expected the code to run if i simply passed sq=64 to the macro as an parameter, however it threw an:
which is pretty strange since it will never be able to actually perform the bitwise if sq >= 64.
It's also to note if i change the bitwise operation to
bb |= (1u64 << sq);
(removing the dollar sign) it won't throw this error.I thinks this is due to an oversight where if the sq operator is copied to an different variable it won't release a if-statement is done to prevent a arithmetic_overflow.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: