Open
Description
What it does
I discovered yesterday that it's possible to leak private struct types in public functions if that struct is public but lives in a private module. Those on the Rust discord considered this a bug in Rust itself but since it's a breaking change, it might need to wait until 2024. So perhaps this should be added to clippy for the time being.
Categories (optional)
- Kind: correctness?
Drawbacks
Perhaps this should instead just be added as a warning into rustc
The issue is that this pattern is supposedly intended and is a feature to implement sealed Traits, but it seems pretty much a bug to me for Structs.
Example
This is a minimal example showing the leaking of structs.
use foo::bbb;
// use foo::bar::Bar; // error since `bar` is private
fn main() {
bbb();
}
mod foo {
use bar::Bar;
pub fn bbb() -> Bar {
Bar
}
mod bar {
pub struct Bar;
}
}