Skip to content

Wrong "Private type in exported type signature" error #27608

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

Closed
netvl opened this issue Aug 8, 2015 · 2 comments
Closed

Wrong "Private type in exported type signature" error #27608

netvl opened this issue Aug 8, 2015 · 2 comments

Comments

@netvl
Copy link
Contributor

netvl commented Aug 8, 2015

Consider this code:

mod a {
    pub mod x {
        pub fn return_x() -> ::X { ::X }
    }
}

struct X;

fn main() {
    let _value = a::x::return_x();
}

It fails to compile with the following error:

test.rs:3:30: 3:33 error: private type in exported type signature
test.rs:3         pub fn return_x() -> ::X { ::X }
                                       ^~~

However, while fn return_x() is pub and mod x is also pub, this function never gets exported from the crate because mod a is private. Therefore, X, being private, is also not available outside the crate. I think that such code should be allowed.

@crumblingstatue
Copy link
Contributor

I have run into this as well.

mod foo {
    // Private implementation detail struct
    struct Strut;
    fn doit() {
        self::bar::fun();
    }
    mod bar {
        // bar::fun() is a private implementation detail of mod foo
        pub fn fun() -> super::Strut {
            unimplemented!()
        }
    }
}

fn main() {
    // foo::bar::fun(); // inaccessible outside of `foo`
}
<anon>:9:25: 9:37 error: private type in exported type signature
<anon>:9         pub fn fun() -> super::Strut {
                                 ^~~~~~~~~~~~

@alexcrichton
Copy link
Member

This has been filed before and the gist is that the definition of a "public signature" is that the type is marked pub, so it's considered a public type subject to the privacy rules. You can find more details in the associated RFC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants