rust-lang / rust-lang/rust-clippy
redundant_pub_crate false positive
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
This code:
#![allow(dead_code, unused_variables)]
#![warn(clippy::nursery)]
mod foo {
pub(crate) enum Bar<T, const LEN: usize> {
Inline { len: u8, arr: [T; LEN] },
Heap { v: Vec<T> }
}
impl <T: Copy + Default, const LEN: usize> Bar<T, LEN> {
pub(crate) fn new() -> Self {
Self::Inline {
len: 0,
arr: [T::default(); LEN],
}
}
}
}
use foo::Bar;
fn main() {
let sv = Bar::<u32, 10>::new();
}
Gives:
warning: pub(crate) enum inside private module
--> src/main.rs:5:5
|
5 | pub(crate) enum Bar<T, const LEN: usize> {
| ----------^^^^^^^^^
| |
| help: consider using: `pub`
|
note: the lint level is defined here
--> src/main.rs:2:9
|
2 | #![warn(clippy::nursery)]
| ^^^^^^^^^^^^^^^
= 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
But if I replace "pub(crate) enum Bar" with "pub enum Bar" the code doesn't compile.
Lint Name
No response
Reproducer
I tried this code:
<code>
I saw this happen:
<output>
I expected to see this happen:
Version
No response
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Rust reproducer and the redundant_pub_crate lint entry point. Verify why the lint suggests pub for an item inside a private module even though the replacement fails to compile, then add or update coverage for this generic enum and const-generic case. Done means the false positive no longer appears while valid redundant-publication cases remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100