Skip to content

clippy::arithmetic_side_effects triggers on operations using Wrapping<T> in no_std environments #11424

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
JarredAllen opened this issue Aug 30, 2023 · 4 comments
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

@JarredAllen
Copy link
Contributor

JarredAllen commented Aug 30, 2023

Summary

#11145 was fixed when in an environment with access to std. However, the exception added to fix this only works for std::num::Wrapping specifically. If you're using #![no_std], then the type has the name core::num::Wrapping, which is a different name, and the lint still triggers.

Lint Name

arithmetic_side_effects

Reproducer

I tried this code:

#![deny(clippy::arithmetic_side_effects)]
#![no_std]

use core::num::Wrapping;

struct Foo {
    wrapping: Wrapping<usize>,
}

pub fn foo(n: usize) -> usize {
    let mut value = Foo {
        wrapping: Wrapping(5),
    };
    value.wrapping += n;
    value.wrapping.0
}

I saw this happen:

error: arithmetic operation that can potentially result in unexpected side-effects
  --> src/lib.rs:14:5
   |
14 |     value.wrapping += n;
   |     ^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects
note: the lint level is defined here
  --> src/lib.rs:1:9
   |
1  | #![deny(clippy::arithmetic_side_effects)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expected to see this happen:

No lints raised

As a note: removing the #![no_std] from the reproducer example silences the lint.

Version

rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: x86_64-unknown-linux-gnu
release: 1.72.0
LLVM version: 16.0.5

Additional Labels

No response

@JarredAllen JarredAllen 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 Aug 30, 2023
@J-ZhengLi
Copy link
Member

@rustbot claim

@c410-f3r
Copy link
Contributor

c410-f3r commented Sep 2, 2023

The snippet can not be reproduced with the latest nightly toolchain -> https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=87c9a7a9647ade5409ea2df14536a027

@J-ZhengLi
Copy link
Member

The snippet can not be reproduced with the latest nightly toolchain -> https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=87c9a7a9647ade5409ea2df14536a027

Nice, seems it got fixed somehow, cuz last week I tried and it triggers the warning.

Strangely enough, when I put that reproducer into a separated ui test last week (clippy was using nightly-2023-08-24 that time), no warning emitted, but when I put it in a project, and run clippy with the same tool-chain, it lints as expected... Which is kinda weird?
But anyway, since it's fixed then I'll stop worrying too much about it~

@J-ZhengLi J-ZhengLi removed their assignment Sep 4, 2023
@JarredAllen
Copy link
Contributor Author

I think #11395 happened to fix it while making unrelated changes for other issues. I'll close this since it's now fixed.

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

No branches or pull requests

3 participants