rust-lang / rust-lang/rust-clippy

needless_pub_self lint when necessary for crate macros

Open
#12,808 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

Simple false positive. needless_pub_self lint is giving warnings when pub(self) is actually necessary to import macros anywhere below crate level. Removing the pub(self) causes compilation error on unresolved import.

Lint Name

needless_pub_self

Reproducer

I tried this code:

// In mod.rs:
macro_rules! vis_methods {
}

pub(self) use vis_methods;

// In submodule:
use super::{vis_methods, other_imports};

I saw this happen:

unnecessary `pub(self)`
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pub_self
`#[warn(clippy::needless_pub_self)]` on by default

I expected to see this happen:

Lint shouldn't trigger.

Version
rustc 1.79.0-nightly (7f2fc33da 2024-04-22)
binary: rustc
commit-hash: 7f2fc33da6633f5a764ddc263c769b6b2873d167
commit-date: 2024-04-22
host: x86_64-pc-windows-msvc
release: 1.79.0-nightly
LLVM version: 18.1.4
Additional Labels

@rustbot label +l-suggestion-causes-error

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the needless_pub_self lint and run the Rust reproducer from the issue, checking both the warning and the unresolved-import failure after removing pub(self). Add a regression test for the macro import case, and consider the issue done when the necessary pub(self) is no longer warned about and the code compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.