Skip to content
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

Private types in public interface #71628

Closed
gahag opened this issue Apr 28, 2020 · 1 comment
Closed

Private types in public interface #71628

gahag opened this issue Apr 28, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@gahag
Copy link

gahag commented Apr 28, 2020

I'm using the Surf crate (1.0.3), and I've hit a very rough edge: there is a public method whose return type is not public. Therefore, I can call this method and use the returned value directly, but I can't return it from my functions and neither have it as a parameter. I can't even store in a variable with explicit type signature, even though I can have a variable with implicit type.

The crate is already undergoing a new major release, and this issue has already been adressed. I'm curious about the language point of view of this behavior. Is this intended? Are there reasons why Rust should allow this? Has this been discussed already? It feels like something that really isn't right, and doesn't cope with the basic language mechanisms.

Here is a short example that reproduces the issue: playground

I would expect Rust to disallow this kind of construct. A public opaque type would have the same effect, without restricting users from passing the value around.

Meta

Both on Stable (1.43.0) and Nightly (1.45.0-nightly).

@gahag gahag added the C-bug Category: This is a bug. label Apr 28, 2020
phansch pushed a commit to phansch/rust-clippy that referenced this issue Apr 28, 2020
phansch pushed a commit to phansch/rust-clippy that referenced this issue Apr 28, 2020
@jonas-schievink
Copy link
Contributor

Yes, this is intended. The type must be pub, but it can be located somewhere the user can't name it.

ThibsG pushed a commit to ThibsG/rust-clippy that referenced this issue May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants