Rust errors / Names, paths and imports
Rust compiler error · checked with rustc 1.99.0
Rust error E0603: is private
What it meansThe item exists but is private to its module. Items are private by default; mark them pub (or pub(crate)) to use them elsewhere.
What rustc prints
error[E0603]: constant `PRIVATE` is private --> main.rs:9:34 | 9 | println!("const value: {}", foo::PRIVATE); // error: constant `PRIVATE` | ^^^^^^^ private constant | note: the constant `PRIVATE` is defined here --> main.rs:4:5 | 4 | const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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.
Why it happens
- A function or struct in another module without
pub. - A crate item that is private; use the public re-export it documents.
How to fix it
1. Make it public
pub mod parser {
pub fn parse(s: &str) {}
}Other wordings of this error
is private, private type, private function, private struct, private module
The compiler team's explanation
A private item was used outside its scope.
Erroneous code example:
mod foo {
const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we
// can't use it outside of the
// `foo` module.
}
println!("const value: {}", foo::PRIVATE); // error: constant `PRIVATE`
// is private
In order to fix this error, you need to make the item public by using the pub keyword. Example:
mod foo {
pub const PRIVATE: u32 = 0x_a_bad_1dea_u32; // We set it public by using the
// `pub` keyword.
}
println!("const value: {}", foo::PRIVATE); // ok!From rustc --explain E0603 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
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?