-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
arithmetic_side_effects
lint correctly considers operations such as (somevar: u64) / 2
as non-side-effectful. However as soon as 2
is extracted into a constant, the lint starts firing.
I don't think it is critical that we handle complex constant evaluation here, but it would be nice if it handled at least basic literals like that so that this lint didn't become a motivation to inline magic numbers into the code.
Lint Name
arithmetic_side_effects
Reproducer
I tried this code:
#![deny(clippy::arithmetic_side_effects)]
fn foo(input: u64) -> u64 {
const A: u64 = 1;
input / A
}
I saw this happen:
error: arithmetic operation that can potentially result in unexpected side-effects
--> src/lib.rs:5:5
|
5 | input / A
| ^^^^^^^^^
Version
rustc nightly / 0.1.68 (2023-01-17 3984bc5) on the playground
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have