Skip to content

Private structure can escape from its module through impl for another private structure #30079

Closed
@petrochenkov

Description

@petrochenkov
struct PrivOuter;

mod m {
    struct PrivInner;
    impl PrivInner {
        pub fn secret(&self) { println!("Hello!"); }
    }

    // This impl is considered private because its type `super::PrivOuter` is private
    // Probably, impls should be considered public if their type is defined outside of the current module even if this type is private
    impl super::PrivOuter {
        pub fn reveal(&self) -> PrivInner { PrivInner }
    }

}

fn main() {
    PrivOuter.reveal().secret();
}

This is not fixed in #29973.
It shouldn't be a common scenario, so it can be fixed later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions