Skip to content

Improve "private type in public interface" message #50430

Description

@spacekookie

There seems to be an issue with detecting the pub-ness of types on the current nightly (EDIT: and actually stable) branch. Consider the following code:

main.rs:

mod hardware;

fn main() {
    hardware::do_stuff();
}

hardware/mod.rs:

mod parser;

#[derive(Debug)]
struct Hardware {
    foo: u32
}

pub fn do_stuff() {
    let hw = parser::get_hardware();
    println!("{:?}", hw);
}

hardware/parser.rs:

use super::Hardware;

pub fn get_hardware() -> Hardware {
    Hardware { foo: 5 }
}

There are no public types in the hardware module that are exposed in any way. Yet, I get this error from the compiler:

[rustc]
private type `hardware::Hardware` in public interface

can't leak private type

Play Link

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions