Skip to content

Private trait's methods reachable through a public subtrait #28514

Closed

Description

I'm not 100% sure how the privacy rules should work.

A's methods should not be callable because the trait is private, but it's reachable though the trait C that inherits A, by calling C::a().

B's methods are reachable the same way, even if it's marked pub but not publically reachable.

pub use inner::C;

mod inner {
    trait A {
        fn a(&self) { }
    }

    pub trait B {
        fn b(&self) { }
    }

    pub trait C: A + B {
        fn c(&self) { }
    }

    impl A for i32 {}
    impl B for i32 {}
    impl C for i32 {}
}

fn main() {
    // A is private
    // B is pub, not reexported
    // C : A + B is pub, reexported

    // 0.a(); // can't call
    // 0.b(); // can't call
    0.c(); // ok

    C::a(&0); // can call
    C::b(&0); // can call
    C::c(&0); // ok
}

Playpen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-resolveArea: Name resolutionArea: Name resolutionA-visibilityArea: Visibility / privacyArea: Visibility / privacyT-langRelevant to the language team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions