Skip to content

integer_arithmetic triggers in derive macro code #10185

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
michaelsproul opened this issue Jan 10, 2023 · 1 comment · Fixed by #10203
Closed

integer_arithmetic triggers in derive macro code #10185

michaelsproul opened this issue Jan 10, 2023 · 1 comment · Fixed by #10203
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@michaelsproul
Copy link
Contributor

Summary

The integer_arithmetic lint triggers in code generated by derive macros.

It seems this is a slightly broader issue affecting multiple lints, e.g. #9657, #7845.

If the right solution is to check any_parent_is_automatically_derived or in_external_macro I would be happy to do the implementation for integer_arithmetic.

Reproducer

I tried this code with arbitrary@1.2.2:

#![deny(clippy::integer_arithmetic)]

use arbitrary::Arbitrary;

#[derive(Arbitrary)]
pub struct Thing {
    pub x: u64,
}

The error is:

error: integer arithmetic detected
 --> src/lib.rs:5:10
  |
5 | #[derive(Arbitrary)]
  |          ^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![deny(clippy::integer_arithmetic)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: this error originates in the derive macro `Arbitrary` (in Nightly builds, run with -Z macro-backtrace for more info)

Version

rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-unknown-linux-gnu
release: 1.66.0
LLVM version: 15.0.2

Additional Labels

No response

@michaelsproul michaelsproul added the C-bug Category: Clippy is not doing the correct thing label Jan 10, 2023
@Jarcho
Copy link
Contributor

Jarcho commented Jan 11, 2023

This needs is_from_proc_macro. any_parent_is_automatically_derived would work if the proc macro adds the #[automatically_derived] attribute, but quite a few of them don't. The other issues have the same fix.

nagisa added a commit to rust-fuzz/arbitrary that referenced this issue Jan 20, 2023
Lack of this can trigger lints in `clippy` such as
rust-lang/rust-clippy#10185 with no obvious
way to allow this lint for the generated impl specifically.

It is a good style and hygiene to add this attribute anyhhow.
nagisa added a commit to rust-fuzz/arbitrary that referenced this issue Jan 23, 2023
Lack of this can trigger lints in `clippy` such as
rust-lang/rust-clippy#10185 with no obvious
way to allow this lint for the generated impl specifically.

It is a good style and hygiene to add this attribute anyhhow.
bors bot pushed a commit to sigp/lighthouse that referenced this issue Mar 28, 2023
## Proposed Changes

To prevent breakages from `cargo update`, this updates the `arbitrary` crate to a new commit from my fork. Unfortunately we still need to use my fork (even though my `bound` change was merged) because of this issue: rust-lang/rust-clippy#10185.

In a couple of Rust versions it should be resolved upstream.
@bors bors closed this as completed in f1a552c Apr 19, 2023
ghost pushed a commit to oone-world/lighthouse that referenced this issue Jul 13, 2023
## Proposed Changes

To prevent breakages from `cargo update`, this updates the `arbitrary` crate to a new commit from my fork. Unfortunately we still need to use my fork (even though my `bound` change was merged) because of this issue: rust-lang/rust-clippy#10185.

In a couple of Rust versions it should be resolved upstream.
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this issue Jan 6, 2024
To prevent breakages from `cargo update`, this updates the `arbitrary` crate to a new commit from my fork. Unfortunately we still need to use my fork (even though my `bound` change was merged) because of this issue: rust-lang/rust-clippy#10185.

In a couple of Rust versions it should be resolved upstream.
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants