Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint possible leaked private structs #7301

Open
conradludgate opened this issue Jun 1, 2021 · 0 comments
Open

Lint possible leaked private structs #7301

conradludgate opened this issue Jun 1, 2021 · 0 comments
Labels
A-lint Area: New lints

Comments

@conradludgate
Copy link

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;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

1 participant