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

redundant_pub_crate FP for macro definition #8732

Closed
Kage-Yami opened this issue Apr 22, 2022 · 3 comments · Fixed by #8736
Closed

redundant_pub_crate FP for macro definition #8732

Kage-Yami opened this issue Apr 22, 2022 · 3 comments · Fixed by #8736
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

@Kage-Yami
Copy link

Kage-Yami commented Apr 22, 2022

Summary

I've written an "internal" macro in my crate, and don't want it to be exported at the root/publicly, so instead of annotating it with #[macro_export], I've added pub(crate) use bit; after the definition. Following the recommendation from clippy::redundant_pub_crate to remove (crate) prevents the crate from compiling because the macro:

is only public within the crate, and cannot be re-exported outside

Lint Name

redundant_pub_crate

Reproducer

I tried this code:

// in lib.rs
#![warn(clippy::nursery)]
mod util;

// in util.rs
macro_rules! bit {
    ($bit:literal, $value:ident) => {
        $value >> $bit & 1 == 1
    };

    ($bit:ident, $value:ident) => {
        $value >> $bit & 1 == 1
    };
}

pub(crate) use bit;

I saw this happen:

warning: pub(crate) import inside private module
  --> src\util.rs:40:1
   |
40 | pub(crate) use bit;
   | ----------^^^^^^^^
   | |
   | help: consider using: `pub`
   |
note: the lint level is defined here
  --> src\lib.rs:1:24
   |
1  | #![warn(clippy::cargo, clippy::nursery, clippy::pedantic)]
   |                        ^^^^^^^^^^^^^^^
   = note: `#[warn(clippy::redundant_pub_crate)]` implied by `#[warn(clippy::nursery)]`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate

I expected to not see a lint warning.

Version

rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-pc-windows-msvc
release: 1.60.0
LLVM version: 14.0.0

Additional Labels

@rustbot label +I-suggestion-causes-error

@Kage-Yami Kage-Yami 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 22, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Apr 22, 2022
@Kage-Yami
Copy link
Author

(Updated OP to add missing #![warn(clippy::nursery)] into lib.rs; lint won't trigger otherwise.)

@Kage-Yami
Copy link
Author

Kage-Yami commented Apr 22, 2022

And it turns out I can't even explicitly allow it at the usage site, because then clippy::useless_attribute fires (which would also be a FP?), which is deny-by-default.

Though it does work if I then allow clippy::useless_attribute. 😂

#[allow(clippy::useless_attribute)]
#[allow(clippy::redundant_pub_crate)]
pub(crate) use bit;

The originally-reported warning now no longer occurs.

@Serial-ATA
Copy link
Contributor

@rustbot claim

@bors bors closed this as completed in 2a5ee68 Apr 24, 2022
bors added a commit that referenced this issue Apr 27, 2022
…, r=llogiq

ignore `redundant_pub_crate` in `useless_attribute`

changelog: [`useless_attribute`] no longer lints [`redundant_pub_crate`]

As mentioned in #8732 (comment)

> And it turns out I can't even explicitly allow it at the usage site, because then `clippy::useless_attribute` fires (which would also be a FP?), which is deny-by-default.
>
> Though it does work if I then allow `clippy::useless_attribute`. 😂
>
> ```rust
> #[allow(clippy::useless_attribute)]
> #[allow(clippy::redundant_pub_crate)]
> pub(crate) use bit;
> ```
>
> The originally-reported warning now no longer occurs.
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

Successfully merging a pull request may close this issue.

3 participants