I have code like this:
mod _mod1 {
struct _A {}
pub(in crate::_mod1) mod _mod2 {
use super::_A;
pub struct _B {}
impl _B {
pub fn _test(_a: _A) {}
}
}
}
And then I run cargo check, it tells me that "private type _A in public interface".
error[E0446]: private type `_A` in public interface
--> src/main.rs:9:13
|
2 | struct _A {}
| --------- `_A` declared as private
...
9 | pub fn _test(_a: _A) {}
| ^^^^^^^^^^^^^^^^^^^^ can't leak private type
For more information about this error, try `rustc --explain E0446`.
error: could not compile `mytest` due to previous error
In my opinion, in this code, although _test method is pub, mod _mod2 is pub(in crate::_mod1). struct _B and _test method can only be accessed in mod _mod1, which meets A's access requirements. Does Rust infer control scope and privacy?