rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.49k stars 1.55k forks source link

arithmetic_side_effects, redundant_pub_crate should not warn external macros #10636

Open Erigara opened 1 year ago

Erigara commented 1 year ago

Summary

arithmetic_side_effects and redundant_pub_crate currently warns on code generated by external macros (in my case tokio::select!).

Lint Name

arithmetic_side_effects, redundant_pub_crate

Reproducer

I tried this code:

#![deny(clippy::arithmetic_side_effects, clippy::redundant_pub_crate)]

extern crate tokio; // 1.27.0

#[tokio::main]
async fn main() {
    let (_, mut receiver) = tokio::sync::mpsc::channel(1);

    loop {
        tokio::select! {
            Some(()) = receiver.recv() => {}
            else => break,
        }
    }
}

I saw this happen:

error: pub(crate) enum inside private module
  --> src/main.rs:10:9
   |
10 | /         tokio::select! {
11 | |             Some(()) = receiver.recv() => {}
12 | |             else => break,
13 | |         }
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate
note: the lint level is defined here
  --> src/main.rs:1:42
   |
1  | #![deny(clippy::arithmetic_side_effects, clippy::redundant_pub_crate)]
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the macro `$crate::select_priv_declare_output_enum` which comes from the expansion of the macro `tokio::select` (in Nightly builds, run with -Z macro-backtrace for more info)

error: pub(crate) type alias inside private module
  --> src/main.rs:10:9
   |
10 | /         tokio::select! {
11 | |             Some(()) = receiver.recv() => {}
12 | |             else => break,
13 | |         }
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate
   = note: this error originates in the macro `$crate::select_priv_declare_output_enum` which comes from the expansion of the macro `tokio::select` (in Nightly builds, run with -Z macro-backtrace for more info)

error: arithmetic operation that can potentially result in unexpected side-effects
  --> src/main.rs:10:9
   |
10 | /         tokio::select! {
11 | |             Some(()) = receiver.recv() => {}
12 | |             else => break,
13 | |         }
   | |_________^
   |
   = 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, clippy::redundant_pub_crate)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the macro `$crate::select` which comes from the expansion of the macro `tokio::select` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `playground` (bin "playground") due to 3 previous errors

I expected to see this happen: compile without errors.

Version

rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: aarch64-apple-darwin
release: 1.68.2
LLVM version: 15.0.6

Additional Labels

No response

c410-f3r commented 1 year ago

Potential dup of #10417, #11132

The arithmetic_side_effects warning will be fixed by #10203

DCNick3 commented 10 months ago

The arithmetic_side_effects fp is indeed fixed now.

Clippy still emits a redundant_pub_crate lint for this repro though:

$ cargo +nightly clippy --version
clippy 0.1.77 (190f4c9 2024-01-09)
$ cargo +nightly clippy
    Checking aboba v0.1.0 (/tmp/tmp.tiKPmRlfI0/aboba)
error: pub(crate) enum inside private module
  --> src/main.rs:10:9
   |
10 | /         tokio::select! {
11 | |             Some(()) = receiver.recv() => {}
12 | |             else => break,
13 | |         }
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate
note: the lint level is defined here
  --> src/main.rs:1:42
   |
1  | #![deny(clippy::arithmetic_side_effects, clippy::redundant_pub_crate)]
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the macro `$crate::select_priv_declare_output_enum` which comes from the expansion of the macro `tokio::select` (in Nightly builds, run with -Z macro-backtrace for more info)

error: pub(crate) type alias inside private module
  --> src/main.rs:10:9
   |
10 | /         tokio::select! {
11 | |             Some(()) = receiver.recv() => {}
12 | |             else => break,
13 | |         }
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate
   = note: this error originates in the macro `$crate::select_priv_declare_output_enum` which comes from the expansion of the macro `tokio::select` (in Nightly builds, run with -Z macro-backtrace for more info)