Skip to content

redundant_pub_crate false positive on local macros #8756

Closed
@digama0

Description

@digama0

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions