Skip to content

A public fn in a private mod with a private type in its signature #25934

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
IvanUkhov opened this issue May 31, 2015 · 4 comments
Closed

A public fn in a private mod with a private type in its signature #25934

IvanUkhov opened this issue May 31, 2015 · 4 comments

Comments

@IvanUkhov
Copy link
Contributor

If a crate has a private module and a private type, the module cannot have a public function whose signature refers to the private type. Here is an illustration:

type Baz = isize;

mod foo {
    use Baz;

    pub fn bar(_: Baz) { // error: private type in exported type signature
    }
}

The public function cannot presumably be qualified as a public-facing part of the crate, and it is not presumably a part of the public API of the crate.

Regards,
Ivan

@tomjakubowski
Copy link
Contributor

You can use pub use Baz inside the foo module. The idea is that the identifier Baz inside the module foo is private to it; you might some day replace use Baz with something like type Baz = String and suddenly break users of that module without appearing to change any public signatures.

You could also write:

pub fn bar(_: super::Baz) {
}

@IvanUkhov
Copy link
Contributor Author

@tomjakubowski, thank you for the response. There are no users of that module as the module is private to the crate. pub use Baz inside the module does not seem to help; the error in that case is error: Baz is private. super does not seem to help either. Could you please clarify what you have in mind?

@tomjakubowski
Copy link
Contributor

There are users of the module inside the crate. I don't mean users in the sense of people using it, just that other pieces of code ("users") are using it.

Anyway, it looks like I've internalized some old rules of privacy or something. Whoops. My mistake.

@alexcrichton
Copy link
Member

This is a dupe of #25532 and #25260, both of which are intended behavior, so closing (more details in those issues).

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