Description
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
fas
pub 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
.