rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

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

Open lolbinarycat opened this issue 1 year ago • 0 comments

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() {}

lolbinarycat avatar Oct 04 '24 19:10 lolbinarycat