Skip to content

unreachable_pub lint ignores nested re-exports #47816

Closed
@CAD97

Description

@CAD97

Playground: https://play.rust-lang.org/?gist=d9e9fe07b83f07a3f9b908c0c7405a99&version=nightly

#![deny(unreachable_pub)]

mod one {
    mod two {
        pub struct S;
    }
    pub use self::two::S;
}
pub use self::one::S;
error: unreachable `pub` item
 --> src/lib.rs:7:5
  |
7 |     pub use self::two::S;
  |     ---^^^^^^^^^^^^^^^^^^
  |     |
  |     help: consider restricting its visibility: `pub(crate)`
  |
note: lint level defined here
 --> src/lib.rs:1:32
  |
1 | #![crate_type = "lib"] #![deny(unreachable_pub)]
  |                                ^^^^^^^^^^^^^^^
  = help: or consider exporting it for use by other crates

#![deny(unreachable_pub)]

mod one {
    mod two {
        pub struct S;
    }
    pub(crate) use self::two::S;
}
pub use self::one::S;
error[E0364]: `S` is private, and cannot be reexported
 --> src/lib.rs:9:9
  |
9 | pub use self::one::S;
  |         ^^^^^^^^^^^^
  |
note: consider marking `S` as `pub` in the imported module
 --> src/lib.rs:9:9
  |
9 | pub use self::one::S;
  |         ^^^^^^^^^^^^

A single level of re-export works:

#![deny(unreachable_pub)]

mod one {
    pub struct S;
}
pub use self::one::S;
 Finished dev [unoptimized + debuginfo] target(s) in 0.27 secs

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2018Area: The 2018 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions