Skip to content

redundant_pub_crate false positive on local macros #8756

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
digama0 opened this issue Apr 28, 2022 · 5 comments
Closed

redundant_pub_crate false positive on local macros #8756

digama0 opened this issue Apr 28, 2022 · 5 comments
Assignees
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@digama0
Copy link
Contributor

digama0 commented Apr 28, 2022

Summary

This is similar to #8732, but it triggers even without a re-export. Here we are defining a module-scoped macro foo inside private module test, and the error message says that it is a pub(crate) macro (which is false, you can't access the macro from another file even if test was pub because it is not #[macro_export]), and you should use pub instead (which does not match the intended meaning of the code, it's a private macro) (and this is also not syntactically correct, pub macro_rules! is not legal).

Lint Name

redundant_pub_crate

Reproducer

I tried this code:

#![warn(clippy::redundant_pub_crate)]
mod test {
  macro_rules! foo { () => {} }
  foo! {}
}
fn main() {}

I saw this happen:

warning: pub(crate) macro inside private module
 --> src/main.rs:3:3
  |
3 |   macro_rules! foo { () => {} }
  |   -^^^^^^^^^^^^^^^
  |   |
  |   help: consider using: `pub`
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::redundant_pub_crate)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate

Version

rustc 1.62.0-nightly (69a5d2481 2022-04-27)
binary: rustc
commit-hash: 69a5d2481e856a5a18885390b8cf6950b9ff8dd3
commit-date: 2022-04-27
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

Additional Labels

@rustbot label +I-suggestion-causes-error

@digama0 digama0 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 28, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Apr 28, 2022
@digama0 digama0 changed the title redundant_pub_crate false positive on local macros redundant_pub_crate false positive on local macros Apr 28, 2022
@Serial-ATA
Copy link
Contributor

@rustbot claim

@Serial-ATA
Copy link
Contributor

Pretty sure #8736 fixed this, I can't reproduce it.

@digama0
Copy link
Contributor Author

digama0 commented Apr 30, 2022

Just pulled the latest nightly, the issue still seems to happen:

$ rustc +nightly -Vv
rustc 1.62.0-nightly (a707f4010 2022-04-29)
binary: rustc
commit-hash: a707f401074bc769bab4efb2bfdde7f6c5a4068d
commit-date: 2022-04-29
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

$ cargo +nightly clippy --version
clippy 0.1.62 (a707f40 2022-04-29)

$ cargo +nightly clippy
    Checking rust-test v0.1.0 (/rust-test)
warning: pub(crate) macro inside private module
 --> src/main.rs:3:3
  |
3 |   macro_rules! foo { () => {} }
  |   -^^^^^^^^^^^^^^^
  |   |
  |   help: consider using: `pub`
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::redundant_pub_crate)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate

warning: `rust-test` (bin "rust-test") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s

I also tried the test files from #8736, and I got the same error:

mod issue_8732 {
    #[allow(unused_macros)]
    macro_rules! some_macro { // error here
        () => {};
    }

    #[allow(unused_imports)]
    pub(crate) use some_macro; // error here
}

@y21
Copy link
Member

y21 commented Jun 16, 2023

This issue seems to be fixed? None of the test cases trigger anymore: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a31d64a5ff10926dd80c2c97a03b2978

@digama0
Copy link
Contributor Author

digama0 commented Jun 16, 2023

Confirmed, the tests seem to pass after nightly-2022-05-06. Looking at what happened on that day I can only guess it was something that changed in the upstream nightly bump 7e017db.

@digama0 digama0 closed this as completed Jun 16, 2023
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

4 participants