rust-lang / rust-lang/rust-clippy

lint agains using `pub(crate)` in the crate root

Open
#13,498 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

warn if an item is annotated with pub(crate) in the root module of a crate.

this would also apply to use items.

Advantage

the default visibility is pub(in self), making an item available to a module and all sub-modules.

if the root module, self is crate, so this is essentially the same as specifying pub(in self) manually.

usage of pub(crate) in this way may indicate an incorrect understanding of rust's visibility system.

Drawbacks

people might use pub(crate) because they anticipate moving the code into a sub-module in the future

Example
pub(crate) fn noop() {}

Could be written as:

fn noop() {}

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 by reviewing how Clippy defines lints for visibility and how crate-root items are represented. Use the examples in this issue as the behavior to check, including use items. Done means a lint warns for redundant pub(crate) annotations in the root module without warning for nested modules or other intended uses.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.