Skip to content

private type in public API of non-pub mod is allowed #22261

Closed
@pnkfelix

Description

@pnkfelix

While reviewing the list of active feature gates and double-checking the behavior of visible_private_types, I found that the check is not working for e.g. the program below:

mod a {
    #[derive(Debug)]
    struct S { x: i32 }
    pub fn foo() -> S { S { x: 3 } }
    impl S { }
}

mod b {
    use a;

    #[cfg(expected)]
    pub fn call_foo() {
        let s: a::S = a::foo();
        println!("{:?}", s);
    }

    #[cfg(not(expected))]
    pub fn call_foo() {
        let s = a::foo();
        println!("{:?}", s);
    }
}

fn main() {
    b::call_foo();
}

In the playpen, the above compiles and runs. I expected to see an error due to the type of a::foo returning the private type a::S.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions