Skip to content

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

@JarredAllen

Description

@JarredAllen

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

Metadata

Metadata

Assignees

No one assigned

    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