Skip to content

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

Closed
@dead-claudia

Description

@dead-claudia

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions