Skip to content

Private types in public interface #71628

@gahag

Description

@gahag

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions