Skip to content

Imprecise visibility error message #82872

Open
@vchekan

Description

@vchekan

When an associated function is declared as pub(crate) and attempt is made to call it from outside of the crate, the error message is

error[E0624]: associated function `new` is private
 --> src/bin/tool/main.rs:4:39
  |
4 |     let c = rust_scratchpad::Cluster::new();
  |                                       ^^^ private associated function

Notice that error says that function is private when in fact it is pub(crate). Compiler makes conclusion, that from outside of crate it is as good as private but does not spell this logical step.
In big project with complex exporting this skipped explanation can add to confusion.

If function is not associated, then error message is still the same, but attempt to reexport is supplemented with useful tip note: consider marking faspub in the imported module:

error[E0364]: `f` is private, and cannot be re-exported
  --> src/lib.rs:11:9
   |
11 | pub use self::cluster::f;
   |         ^^^^^^^^^^^^^^^^
   |
note: consider marking `f` as `pub` in the imported module
  --> src/lib.rs:11:9
   |
11 | pub use self::cluster::f;
   |         ^^^^^^^^^^^^^^^^

src/lib.rs

mod cluster {
    pub struct Cluster{}
    impl Cluster {
        pub(crate) fn new() -> Self {unimplemented!()}
    }

    pub(crate) fn f() {}
}

pub use self::cluster::Cluster;
// pub use self::cluster::f;

bin/tool/main.rs

use rust_scratchpad;

fn test1() {
    let c = rust_scratchpad::Cluster::new();
}

fn main() {}

It would be nice to have more precise error message which quote visibility problem as-is, or even better, explain that crate pub(crate) of crate B is private from crate A point of view.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-visibilityArea: Visibility / privacyD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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