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, redundant_pub_crate should not warn external macros #10636

Closed
Erigara opened this issue Apr 12, 2023 · 2 comments · Fixed by #13952
Closed

arithmetic_side_effects, redundant_pub_crate should not warn external macros #10636

Erigara opened this issue Apr 12, 2023 · 2 comments · Fixed by #13952
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

@Erigara
Copy link

Erigara commented Apr 12, 2023

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

@Erigara Erigara 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 Apr 12, 2023
@c410-f3r
Copy link
Contributor

c410-f3r commented Apr 15, 2023

Potential dup of #10417, #11132

The arithmetic_side_effects warning will be fixed by #10203

@DCNick3
Copy link

DCNick3 commented Jan 10, 2024

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)

github-merge-queue bot pushed a commit that referenced this issue Jan 12, 2025
Some widely used crates, such as `pin-project-lite`, make use of a
`pub(crate)` construct in a private module inside a public macro. This
makes unrelated project trigger the lint.

There is also an unfortunate situation for Clippy itself: when a new
version of `pin-project-lite` or similar lint-trigerring crates is
released, those lints which can be found in hundreds of occurrences in
dependent crates will change, and appear as diffs in unrelated Clippy PR
because the base lintcheck run will be cached with the ancient release
of the crates. We currently have the situation
[here](https://github.com/rust-lang/rust-clippy/actions/runs/12635410895?pr=13851#user-content-redundant-pub-crate-removed),
which 219 lints removed and 219 lints added because of a
`pin-project-lite` version change between runs, and the fact that
`redundant_pub_crate` triggers on external macros.

Also:
- Fix #10636
- Fix #12213

changelog: [`redundant_pub_crate`]: do not trigger on external macros
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.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy