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] triggers on macro-generated code #10417

Closed
Arjentix opened this issue Feb 27, 2023 · 0 comments · Fixed by #10203
Closed

[arithmetic_side_effects] triggers on macro-generated code #10417

Arjentix opened this issue Feb 27, 2023 · 0 comments · Fixed by #10203
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

@Arjentix
Copy link

Arjentix commented Feb 27, 2023

Summary

The problem is that arithmetic_side_effects triggers on the code generated by macro. In my case by quote! macro.

I think this issue is related to #9757.

So as said in #9757 dtolnay/quote#232 (comment) this thing should be fixed on clippy side, not on quote side.

arithmetic_side_effects is being triggered only when I have , at the end.

Lint Name

arithmetic_side_effects

Reproducer

I tried this code:

#![deny(clippy::arithmetic_side_effects)]

fn main() {
    let array = [1, 2, 3];
    let _ = quote::quote!(#(#array),*);
}

I saw this happen:

error: arithmetic operation that can potentially result in unexpected side-effects
 --> src/main.rs:5:13
  |
5 |     let _ = quote::quote!(#(#array),*);
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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/main.rs:1:9
  |
1 | #![deny(clippy::arithmetic_side_effects)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: this error originates in the macro `$crate::quote_token_with_context` which comes from the expansion of the macro `quote::quote` (in Nightly builds, run with -Z macro-backtrace for more info)

I expected to see this happen:

Successful pass

Version

rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: aarch64-apple-darwin
release: 1.66.0
LLVM version: 15.0.2

Additional Labels

No response

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.

1 participant