Skip to content
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

arithmetic_side_effects: can’t see through trivial constant items #10209

Closed
nagisa opened this issue Jan 18, 2023 · 1 comment · Fixed by #10310
Closed

arithmetic_side_effects: can’t see through trivial constant items #10209

nagisa opened this issue Jan 18, 2023 · 1 comment · Fixed by #10310
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

@nagisa
Copy link
Member

nagisa commented Jan 18, 2023

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

@nagisa nagisa 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 18, 2023
@c410-f3r
Copy link
Contributor

c410-f3r commented Feb 9, 2023

@rustbot claim

I will try to at least see if the current machinery can handle this use-case but no promises.

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