Rust errors / Names, paths and imports
Rust compiler error · checked with rustc 1.99.0
Rust error E0742: visibilities can only be restricted to ancestor modules
What it meansVisibility is restricted to a module which isn't an ancestor of the current item.
What rustc prints
error[E0742]: visibilities can only be restricted to ancestor modules
--> main.rs:3:9
|
3 | pub (in crate::sea) struct Shark; // error!
| ^^^^^^^^^^Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
Visibility is restricted to a module which isn't an ancestor of the current item.
Erroneous code example:
pub mod sea {}
pub (in crate::sea) struct Shark; // error!
fn main() {}
To fix this error, we need to move the Shark struct inside the sea module:
pub mod sea {
pub (in crate::sea) struct Shark; // ok!
}
fn main() {}
Of course, you can do it as long as the module you're referring to is an ancestor:
pub mod earth {
pub mod sea {
pub (in crate::earth) struct Shark; // ok!
}
}
fn main() {}From rustc --explain E0742 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0425cannot find value in this scope
- E0603is private
- E0432unresolved import
- E0005refutable pattern in local binding
- E0711feature `foo` is declared stable since 1.29.0, but was previously declared stable since 1.0.0
- E0725A feature attribute named a feature that was disallowed in the compiler command line flags
- E0754trying to load file for module `řųśť` with non-ascii identifier name
- E0761Multiple candidate files were found for an out-of-line module
Up next
Often hit nextE0425: cannot find value in this scopeA related error from the same family.Read it next →Did this answer your question?