Skip to content

[arithmetic_side_effects] Shifts by in-bounds literals trigger a false positive. #10252

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

Closed
dead-claudia opened this issue Jan 29, 2023 · 1 comment · Fixed by #10309
Closed
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dead-claudia
Copy link

dead-claudia commented Jan 29, 2023

Summary

Shifts cannot overflow if their scale is in-bounds. Stuff like (a as i32) << 31 obviously will never fail, and so they shouldn't trigger that lint.

Lint Name

arithmetic_side_effects

Reproducer

I tried this code:

#![deny(clippy::arithmetic_side_effects)]
fn main() {
    let a = 1_i32;
    let b = a >> 4;
}

I saw this happen:

error: arithmetic operation that can potentially result in unexpected side-effects
 --> src/main.rs:4:13
  |
4 |     let b = a >> 4;
  |             ^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects

I expected to see this happen: No error

Version

rustc 1.66.1 (90743e729 2023-01-10)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: x86_64-unknown-linux-gnu
release: 1.66.1
LLVM version: 15.0.2

Additional Labels

No response

@dead-claudia dead-claudia added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jan 29, 2023
@c410-f3r
Copy link
Contributor

c410-f3r commented Feb 9, 2023

@rustbot claim

c410-f3r added a commit to c410-f3r/rust-clippy that referenced this issue Feb 9, 2023
c410-f3r added a commit to c410-f3r/rust-clippy that referenced this issue Feb 9, 2023
c410-f3r added a commit to c410-f3r/rust-clippy that referenced this issue Feb 9, 2023
bors added a commit that referenced this issue Mar 9, 2023
[arithmetic_side_effects] Fix #10252

Fix #10252

At least for integers, shifts are already handled by the compiler.

----

changelog: [`arithmetic_side_effects`]: No longer lints on right or left shifts with constant integers, as the compiler warns about them.
[#10309](#10309)
<!-- changelog_checked-->
@bors bors closed this as completed in c439373 Mar 9, 2023
J-ZhengLi pushed a commit to TogetherGame/rust-clippy that referenced this issue Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants