Skip to content

visible_private_types lint sometimes should explain why type is private #13422

@pnkfelix

Description

@pnkfelix

Here is some code:

#![crate_type="lib"]

pub mod hello {
    pub use self::inner::foo;

    mod inner {
        pub fn foo() -> Bar { Bar }

        pub struct Bar;
    }
}

when I try to compile it, I get:

% rustc /tmp/p.rsb_
/tmp/p.rs:7:25: 7:28 warning: private type in exported type signature, #[warn(visible_private_types)] on by default
/tmp/p.rs:7         pub fn foo() -> Bar { Bar }
                                    ^~~

Now, maybe in the above code the problem is obvious, but in the original context where this arose, the inner was in a separate file from hello, and I did a lot of head scratching, saying "but I said pub struct Bar..."

I think that if the lint is complaining about a type that is itself declared public, then the lint should have a note indicating at least one module along the chain that is private. And maybe a note saying "you can fix this by either doing pub use self::inner::Bar or by making the mod inner public."

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions