Skip to main content

## UNREACHABLE_PUB

# Static UNREACHABLE_PUB

Source

    pub static UNREACHABLE_PUB: &Lint

Expand description

The `unreachable_pub` lint triggers for `pub` items not reachable from other crates - that means neither directly accessible, nor reexported (with `pub use`), nor leaked through things like return types (which the `unnameable_types` lint can detect if desired).

#### §Example

ⓘ

    #![deny(unreachable_pub)]
    mod foo {
        pub mod bar {

        }
    }

{{produces}}

#### §Explanation

The `pub` keyword both expresses an intent for an item to be publicly available, and also signals to the compiler to make the item publicly accessible. The intent can only be satisfied, however, if all items which contain this item are also publicly accessible. Thus, this lint serves to identify situations where the intent does not match the reality.

If you wish the item to be accessible elsewhere within the crate, but not outside it, the `pub(crate)` visibility is recommended to be used instead. This more clearly expresses the intent that the item is only visible within its own crate.

This lint is “allow” by default because it will trigger for a large amount of existing Rust code. Eventually it is desired for this to become warn-by-default.