Skip to content

False positive visible private types with super #25532

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
thepowersgang opened this issue May 17, 2015 · 3 comments
Closed

False positive visible private types with super #25532

thepowersgang opened this issue May 17, 2015 · 3 comments

Comments

@thepowersgang
Copy link
Contributor

Referencing a private parent type with super in a public method of a private module generates an error, despite the type not being exposed outside its scope.

struct Filesystem;

mod dir {
    pub fn new(fs: &super::Filesystem) {}
}

fn main() { }

(playpen http://is.gd/7Hhjfw)

<anon>:4:21: 5:38 error: private type in exported type signature
<anon>:4     pub fn new(fs: &super::Filesystem) {}
                             ^~~~~~~~~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101
@alexcrichton
Copy link
Member

This is actually currently working as intended, the definition of "public" is that the target type is marked with pub (see the associated RFC for details), so in this case the pub function new is referencing the non-pub structure Filesystem.

@thepowersgang
Copy link
Contributor Author

Hmm... I think I can see why this is intended behaviour, but I'm not sure it's "correct". This snippet does not expose any types that would not be accessible by those that can see the method.

There is a workaround by using the following snippet, but the fact that this workaround works could also be a bug.

mod dir {
    pub type Filesystem = super::Filesystem;
}

@alexcrichton
Copy link
Member

The problem is that if dir::new were reexported at a different publicly-reachable location then the type Filesystem would indeed be a private API in a public signature. It's generally quite difficult to determine if something is publicly reexported somewhere else (as it could be a very long chain of reexports), so it's much easier to think about in terms of "is it pub or not?"

The workaround you have reexports Filesystem as a public type, so that is working as intended.

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