Description
pub use should not be able to make a private item public, e.g., this is illegal:
mod a {
pub use self::b::Bar; // error: type `Bar` is private
mod b {
struct Bar;
}
}
However, if the private item is in an enclosing module then this is allowed. That is wrong (I think). However, it gets more complicated depending on if the enclosing module is itself public, because there is a useful pattern where the submodule pub use
s an item in the enclosing module and that does not increase its visibility. Here are the possibilities:
mod a {
struct Foo;
mod b {
pub use super::Foo; // ok - only already visible in a and sub-mods
}
}
mod c {
struct Foo;
pub mod d {
pub use super::Foo; // not ok - increases visibility to a sibling of c
}
}
pub mod e {
struct Foo;
mod f {
pub use super::Foo; // ok, but only if e does not pub use f
}
}
pub mod g {
struct Foo;
pub mod h {
pub use super::Foo; // not ok, increases visibility to the whole world
}
}
I'm not sure if we can check the third case easily (or at all). It might only be worth allowing the first case (this would break some code in the Rust repo and probably others though).
Note also that this interacts with the ban on private types in public items - this hole in visibility makes that work some times (I need to think more about that though)