Rust

E0603 Private Item Fix

Every name in Rust carries its own visibility, and a path is only as public as its least visible link. E0603 is the compiler saying the item itself - not a field of it, not a method on it - was named from somewhere its visibility does not reach: a private module, struct, function, constant, enum, static, type alias, or trait, or a public item sitting behind a private module. This guide separates the nine shapes that produce it and matches each one to its repair: mark the item pub, widen it with a restricted pub form, publish the module on the path, or re-export the item at a level callers can reach.

Written November 25, 2026 · Tested with Rust 1.99.1 · 32 min read

By the end of this guide
  • The rule underneath: every link in the path must be visible from where the path is written
  • How to read the diagnostic
  • The first failure: naming a private module
  • The second failure: naming a private struct

Written November 25, 2026

Tested with Rust 1.99.1

What this guide is

Error E0603 is an item named from outside its visibility. The error codes index defines it in one sentence - a private item was used outside its scope - and its example is a private constant in a module, read from outside that module. The header names the kind of item and the item itself - "module inner is private", "constant LIMIT is private" - and that pair is the whole diagnosis: what was named, and the fact that the naming code stands somewhere the item does not reach.

The forms in this guide each reproduce E0603 with a small, complete program, and each names a different kind of item: a module, a struct, a function, a constant, an enum, a static, a type alias, and a trait, each private inside its module and named from the crate root. The ninth form names an item that is itself pub and still fails, because the module on its path is private - visibility composes along the whole path, so one private link closes the path no matter how public the item at the end of it is. The fix for the first eight is the repair the error index names: make the item public with pub, or with one of the restricted forms where the readers are a known set. The ninth family's fix works on the path instead: publish the module, or re-export the item where callers can reach it.

Several neighboring results are not the plain E0603 item-naming shape and are worked only in the traps and the checklist. An item used inside its own module compiles, and so does an item used from a descendant of that module - privacy runs downward. A private module declared at the crate root compiles when named from the root, because the whole crate stands inside the root module. A pub(crate) item compiles when read from elsewhere in the same crate, and a pub use re-export makes an item behind a private module reachable under a new path. The error also arrives through a use import and on a private union, both E0603 itself. Naming a private field is not E0603: it is E0616. Calling a private method is E0624. Building a struct with a literal whose fields are private is E0451. And importing a name that does not exist at all is E0432.

Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.

The Rust Reference's visibility and privacy page states the default first: by default, everything is private. It then gives the two access cases. If an item is public, it can be accessed from outside its module - provided every ancestor module of the item can be accessed from there too. If an item is private, it may be accessed by the current module and its descendants: the module that defines it, and any module nested inside that one, at any depth. Every other position is outside the item's reach: the parent of the defining module, a sibling module, and another crate all stand on the far side of the boundary. The crate root is the one position to handle with care: a module declared at the root is defined in the root module, so the root and everything under it are the defining module and its descendants, which is why a private module at the root is reachable from anywhere in the crate while the same module nested one level down is not.

The same page defines the restricted forms of pub. pub(crate) makes an item visible within the current crate. pub(super) makes an item visible to the parent module. pub(in path) makes an item visible within a named ancestor module's subtree. These forms widen an item's visibility to a named scope instead of to everyone, so an item whose readers are all inside the crate, or all in one parent module, never has to become fully public to become reachable - and the restriction applies to the item it is written on, never around a private module standing in front of it, a point the ninth family turns on.

The Reference also covers the second way a path opens: re-export. Rust allows publicly re-exporting items through a pub use directive, and the re-export gives the item a second path that does not pass through the private module. A caller who cannot write outer::inner::LIMIT, because inner is private, can still write outer::LIMIT when outer re-exports the constant - the traps show that program compiling. The error codes index names the direct repair for its constant example: make the item public by using the pub keyword. Between the two, the choice is about which path callers should write: pub on the item opens the original path, a re-export adds a shorter public path while the original module stays private.

How to read the diagnostic

Every failure in the nine families prints the same shape of output. The first family's, in full:

Terminal
$ rustc --edition 2021 fail_module.rs -o fail_module
error[E0603]: module `inner` is private
  --> fail_module.rs:10:12
   |
10 |     outer::inner::ping();
   |            ^^^^^  ---- function `ping` is not publicly re-exported
   |            |
   |            private module
   |
note: the module `inner` is defined here
  --> fail_module.rs:2:5
   |
 2 |     mod inner {
   |     ^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

Read it in order. The header names the kind of item first and the item second - a module, inner. The word for the kind changes with the item and with nothing else: the families below print "private struct", "private function", "private constant", "private enum", "private static", "private type alias", and "private trait" in the same position. The caret span underlines just the item's name in the path at the naming site, with the header restated at the span as its note. Where the path continues past the private item - a function inside the module, a constant inside it, an associated function on the trait - a second label on the same line names what the path was reaching for and adds that it is not publicly re-exported, which is the compiler pointing at the re-export repair. Below the span, a note points back at the item's definition: "the module inner is defined here". The definition is shown because which item is private is the question this error answers; the repair is chosen by asking who should be able to name the item. If a known set of modules should, the item's visibility widens to exactly that set. If everyone should, it becomes pub. If the item should stay private, the naming moves into the defining module or one of its descendants, behind a public function that does the work there.

That shape is also the fastest way to tell this error from its neighbors. When the failing name is a field of a struct that was itself reachable, the header says "field" and the code is E0616, in the traps. When it is a method, the header says "method" and the code is E0624. When the value is being built rather than named - a struct literal naming private fields - the code is E0451. And when the name does not exist in the module at all, there is no definition note, because there is no definition to point at: the code is E0432.

The first failure: naming a private module

A program that names a module nested inside another module, from the crate root:

Rust
mod outer {
    mod inner {
        pub fn ping() {
            println!("ping");
        }
    }
}

fn main() {
    outer::inner::ping();
}
Terminal
$ rustc --edition 2021 fail_module.rs -o fail_module
error[E0603]: module `inner` is private
  --> fail_module.rs:10:12
   |
10 |     outer::inner::ping();
   |            ^^^^^  ---- function `ping` is not publicly re-exported
   |            |
   |            private module
   |
note: the module `inner` is defined here
  --> fail_module.rs:2:5
   |
 2 |     mod inner {
   |     ^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

inner is declared without pub inside outer, so it is visible only in outer and in modules nested inside outer. The function at the end of the path is pub, and it makes no difference: the path is checked link by link, and the first link the crate root cannot use is the module itself. The second label on the span, naming ping as not publicly re-exported, records that the path was otherwise complete. The shape appears wherever an internal module is organized as a submodule - helpers grouped under a feature module - and a caller outside the parent reaches for the group directly instead of going through the parent.

The fix marks the module pub:

Rust
mod outer {
    pub mod inner {
        pub fn ping() {
            println!("ping");
        }
    }
}

fn main() {
    outer::inner::ping();
}
Terminal
$ rustc --edition 2021 fix_module.rs -o fix_module
$ ./fix_module
ping

The output is ping. Every link in outer::inner::ping is now visible from the crate root: outer is defined at the root, inner is public inside it, and ping is public inside inner. Where the module is an internal grouping that only the crate should see into, pub(crate) mod inner is the narrower form of the same repair - it opens the path to the whole crate and to no one outside it.

The second failure: naming a private struct

A program that names a struct type from the crate root, in a type position:

Rust
mod meter {
    struct Meter {
        pub value: i32,
    }

    pub fn make() -> i32 {
        let m = Meter { value: 7 };
        m.value
    }
}

fn main() {
    let m: Option<meter::Meter> = None;
    match m {
        Some(_) => println!("some"),
        None => println!("{}", meter::make()),
    }
}
Terminal
$ rustc --edition 2021 fail_struct.rs -o fail_struct
error[E0603]: struct `Meter` is private
  --> fail_struct.rs:13:26
   |
13 |     let m: Option<meter::Meter> = None;
   |                          ^^^^^ private struct
   |
note: the struct `Meter` is defined here
  --> fail_struct.rs:2:5
   |
 2 |     struct Meter {
   |     ^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

The struct is declared without pub inside mod meter. The naming here is a type annotation - Option<meter::Meter> - and a path in a type position is checked exactly like a path in an expression: the type has to be visible where the annotation is written. Note what does compile in the same program: meter::make() is a public function, and calling it is fine. What the caller cannot do is write the type's name - in an annotation, a field type, a function signature, or a pattern. This is the E0616 guide's trap from the other side: there, a private struct failed with this same code before any field was reached, because a type that cannot be named cannot have its fields reached either.

The fix marks the struct pub, and its field pub with it, since the fixed program constructs and reads the value directly:

Rust
mod meter {
    pub struct Meter {
        pub value: i32,
    }
}

fn main() {
    let m = meter::Meter { value: 7 };
    println!("{}", m.value);
}
Terminal
$ rustc --edition 2021 fix_struct.rs -o fix_struct
$ ./fix_struct
7

The output is 7. Marking the type pub is the whole repair for the naming failure; the field's pub answers a different question - whether callers may also construct the struct with a literal and read the field - and a struct whose values are only built inside its module needs the type public and its fields private, the combination the field guide works through.

The third failure: calling a private function

A program that calls a function from the crate root:

Rust
mod meter {
    fn secret() -> i32 {
        7
    }
}

fn main() {
    println!("{}", meter::secret());
}
Terminal
$ rustc --edition 2021 fail_fn.rs -o fail_fn
error[E0603]: function `secret` is private
 --> fail_fn.rs:8:27
  |
8 |     println!("{}", meter::secret());
  |                           ^^^^^^ private function
  |
note: the function `secret` is defined here
 --> fail_fn.rs:2:5
  |
2 |     fn secret() -> i32 {
  |     ^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

A function declared without pub is callable from its own module and that module's descendants, and from nowhere else. The call in main is an ordinary path expression, meter::secret(), and it fails at the function's name in the path. The shape appears when a helper written for one module's internal use - a computation several of the module's public functions share - is reached for directly from outside, usually because it does exactly the one thing the caller needs and the public surface offers it only bundled with other work.

The fix marks the function pub:

Rust
mod meter {
    pub fn secret() -> i32 {
        7
    }
}

fn main() {
    println!("{}", meter::secret());
}
Terminal
$ rustc --edition 2021 fix_fn.rs -o fix_fn
$ ./fix_fn
7

The output is 7. The alternative repair keeps the helper private and adds a public function that calls it - the shape the traps show compiling, where a module's own public function and a descendant module both reach the private helper legally. Which repair fits depends on whether the helper is part of what the module means to offer: a function other code should call by name gets pub; an implementation detail stays private behind the public functions that use it.

The fourth failure: reading a private constant

A program that reads a constant from the crate root:

Rust
mod meter {
    const LIMIT: i32 = 7;
}

fn main() {
    println!("{}", meter::LIMIT);
}
Terminal
$ rustc --edition 2021 fail_const.rs -o fail_const
error[E0603]: constant `LIMIT` is private
 --> fail_const.rs:6:27
  |
6 |     println!("{}", meter::LIMIT);
  |                           ^^^^^ private constant
  |
note: the constant `LIMIT` is defined here
 --> fail_const.rs:2:5
  |
2 |     const LIMIT: i32 = 7;
  |     ^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

This is the error index's own example shape: a constant declared without pub inside a module, named from outside it. A constant has no fields and no methods, so there is no indirect way to reach its value - either the name is visible where it is written, or the value is unavailable there. The shape appears with limits, sizes, and fixed configuration values that a module defines for its own arithmetic and that code outside the module later needs to compare against or display.

The fix is the one the error codes index gives for this exact program - mark the constant pub:

Rust
mod meter {
    pub const LIMIT: i32 = 7;
}

fn main() {
    println!("{}", meter::LIMIT);
}
Terminal
$ rustc --edition 2021 fix_const.rs -o fix_const
$ ./fix_const
7

The output is 7. Where the constant's readers are all inside the crate, pub(crate) is the narrower width: the name opens to every module in the crate and stays out of the crate's public surface. The traps show a pub(crate) function read from a sibling module compiling on exactly that rule.

The fifth failure: naming a private enum

A program that names an enum type from the crate root, in a type annotation:

Rust
mod meter {
    enum State {
        On,
        Off,
    }

    pub fn describe(s: State) -> &'static str {
        match s {
            State::On => "on",
            State::Off => "off",
        }
    }

    pub fn current() -> State {
        State::On
    }

    pub fn other() -> State {
        State::Off
    }
}

fn main() {
    let s: meter::State = meter::current();
    println!("{}", meter::describe(s));
    println!("{}", meter::describe(meter::other()));
}
Terminal
$ rustc --edition 2021 fail_enum.rs -o fail_enum
error[E0603]: enum `State` is private
  --> fail_enum.rs:24:19
   |
24 |     let s: meter::State = meter::current();
   |                   ^^^^^ private enum
   |
note: the enum `State` is defined here
  --> fail_enum.rs:2:5
   |
 2 |     enum State {
   |     ^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

The enum is declared without pub inside mod meter, and the annotation meter::State names it from the crate root. Everything else in the program is reachable: describe, current, and other are public functions, and they pass State values in and out without the caller ever writing the type's name. That arrangement compiles right up to the line that names the type - a caller can hold the value, hand it back, and never be allowed to say what it is. Naming an enum also covers naming its variants: a variant path like meter::State::On starts with the enum's name, so it stands or falls with the enum's own visibility. The Reference states the default that makes this surprising: variants of a pub enum are public by default, but that default only applies once the enum itself is public.

The fix marks the enum pub:

Rust
mod meter {
    pub enum State {
        On,
        Off,
    }

    pub fn describe(s: State) -> &'static str {
        match s {
            State::On => "on",
            State::Off => "off",
        }
    }

    pub fn current() -> State {
        State::On
    }

    pub fn other() -> State {
        State::Off
    }
}

fn main() {
    let s: meter::State = meter::current();
    println!("{}", meter::describe(s));
    println!("{}", meter::describe(meter::other()));
}
Terminal
$ rustc --edition 2021 fix_enum.rs -o fix_enum
$ ./fix_enum
on
off

The output is on and then off, the two values the module's functions hand out, now nameable by the caller, and its variants can be matched on. With the enum public, its variants are public with it, so no per-variant marking exists or is needed.

The sixth failure: reading a private static

A program that reads a static from the crate root:

Rust
mod meter {
    static COUNT: i32 = 7;
}

fn main() {
    println!("{}", meter::COUNT);
}
Terminal
$ rustc --edition 2021 fail_static.rs -o fail_static
error[E0603]: static `COUNT` is private
 --> fail_static.rs:6:27
  |
6 |     println!("{}", meter::COUNT);
  |                           ^^^^^ private static
  |
note: the static `COUNT` is defined here
 --> fail_static.rs:2:5
  |
2 |     static COUNT: i32 = 7;
  |     ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

A static declared without pub follows the same rule as the constant in the fourth family: the name is visible in its module and that module's descendants, and the read in main is outside both. The diagnostic's kind word is "static", and the definition note points at the static declaration. The shape appears with crate-wide counters, registries, and fixed tables that a module keeps for itself and that reporting or setup code outside the module later needs to read.

The fix marks the static pub:

Rust
mod meter {
    pub static COUNT: i32 = 7;
}

fn main() {
    println!("{}", meter::COUNT);
}
Terminal
$ rustc --edition 2021 fix_static.rs -o fix_static
$ ./fix_static
7

The output is 7. A static's visibility governs naming only; it says nothing about mutation, which a plain static does not allow from anywhere. Where the readers are all in the crate, pub(crate) static keeps the name out of the public surface at the same width as the constant fix.

The seventh failure: naming a private type alias

A program that names a type alias from the crate root, in a type annotation:

Rust
mod meter {
    type Count = i32;

    pub fn get() -> Count {
        7
    }
}

fn main() {
    let n: meter::Count = meter::get();
    println!("{}", n);
}
Terminal
$ rustc --edition 2021 fail_alias.rs -o fail_alias
error[E0603]: type alias `Count` is private
  --> fail_alias.rs:10:19
   |
10 |     let n: meter::Count = meter::get();
   |                   ^^^^^ private type alias
   |
note: the type alias `Count` is defined here
  --> fail_alias.rs:2:5
   |
 2 |     type Count = i32;
   |     ^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

The alias is declared without pub inside mod meter. The function get is public and returns the alias's type - an i32 - and calling it compiles; what fails is writing the alias's name in the annotation. An alias is an item like the types it abbreviates, with its own visibility, separate from the visibility of the type on the right-hand side: i32 is nameable everywhere, and meter::Count is nameable only where the alias is visible. The shape appears when a module introduces a short name for a type it uses throughout - a count, an identifier, a coordinate - and code outside the module adopts the same name for its own annotations and signatures.

The fix marks the alias pub:

Rust
mod meter {
    pub type Count = i32;

    pub fn get() -> Count {
        7
    }
}

fn main() {
    let n: meter::Count = meter::get();
    println!("{}", n);
}
Terminal
$ rustc --edition 2021 fix_alias.rs -o fix_alias
$ ./fix_alias
7

The output is 7. With the alias public, the annotation and the function's return type are the same written name on both sides of the module boundary, which is the state the caller's code assumed it was in.

The eighth failure: naming a private trait

A program that names a trait from the crate root, to call one of its associated functions through it:

Rust
mod meter {
    trait Greeter {
        fn greet(&self) -> i32;
    }

    pub struct Meter;

    impl Greeter for Meter {
        fn greet(&self) -> i32 {
            7
        }
    }

    pub fn make() -> Meter {
        Meter
    }
}

fn main() {
    let m = meter::make();
    println!("{}", meter::Greeter::greet(&m));
}
Terminal
$ rustc --edition 2021 fail_trait.rs -o fail_trait
error[E0603]: trait `Greeter` is private
  --> fail_trait.rs:21:27
   |
21 |     println!("{}", meter::Greeter::greet(&m));
   |                           ^^^^^^^  ----- associated function `greet` is not publicly re-exported
   |                           |
   |                           private trait
   |
note: the trait `Greeter` is defined here
  --> fail_trait.rs:2:5
   |
 2 |     trait Greeter {
   |     ^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

The trait is declared without pub inside mod meter. The struct is public, its constructor is public, and the implementation exists - Meter does implement Greeter - but the only path that names the trait's associated function runs through the trait's name, and that name is private. The second label on the span names greet as not publicly re-exported, the same trailing-label shape as the module family. The Reference gives traits one default that runs the other way: associated items in a pub trait are public by default. Here the trait itself is private, so the default never engages. The shape appears when a trait is written as an internal contract between a module's types and later needs to be named outside - in a bound, an implementation, or a qualified call like this one.

The fix marks the trait pub:

Rust
mod meter {
    pub trait Greeter {
        fn greet(&self) -> i32;
    }

    pub struct Meter;

    impl Greeter for Meter {
        fn greet(&self) -> i32 {
            7
        }
    }

    pub fn make() -> Meter {
        Meter
    }
}

fn main() {
    let m = meter::make();
    println!("{}", meter::Greeter::greet(&m));
}
Terminal
$ rustc --edition 2021 fix_trait.rs -o fix_trait
$ ./fix_trait
7

The output is 7. With the trait public, its associated function is public by default with it, and the qualified path meter::Greeter::greet(&m) names both legally.

The ninth failure: a public item behind a private module

A program that names a public constant through a private module:

Rust
mod outer {
    mod inner {
        pub const LIMIT: i32 = 7;
    }
}

fn main() {
    println!("{}", outer::inner::LIMIT);
}
Terminal
$ rustc --edition 2021 fail_privmod.rs -o fail_privmod
error[E0603]: module `inner` is private
 --> fail_privmod.rs:8:27
  |
8 |     println!("{}", outer::inner::LIMIT);
  |                           ^^^^^  ----- constant `LIMIT` is not publicly re-exported
  |                           |
  |                           private module
  |
note: the module `inner` is defined here
 --> fail_privmod.rs:2:5
  |
2 |     mod inner {
  |     ^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

Every item in this program is as public as it can be made: the constant is pub, and there is nothing else to mark on it. The failure is one link earlier. inner is private inside outer, so from the crate root the path outer::inner::LIMIT stops at inner - the span sits under the module segment of the path, shifted right because the path is longer - and the second label names the constant as not publicly re-exported. This is the Reference's first access case stated from the failing side: a public item can be accessed from a module only if all of the item's ancestor modules can be accessed from there too. Widening the item cannot repair this family, because the item is not the link that is closed. The shape appears whenever a public API is organized one level deeper than its callers - a constants module, a types module - and the grouping module was left private by default.

The fix publishes the module on the path:

Rust
mod outer {
    pub mod inner {
        pub const LIMIT: i32 = 7;
    }
}

fn main() {
    println!("{}", outer::inner::LIMIT);
}
Terminal
$ rustc --edition 2021 fix_privmod.rs -o fix_privmod
$ ./fix_privmod
7

The output is 7. The constant was already pub; adding pub to inner opens the one closed link, and the whole path resolves. The second repair leaves the module private and re-exports the item one level up - pub use inner::LIMIT; inside outer, after which callers write outer::LIMIT. The traps show that program compiling. Choose between them by what callers should see: publishing the module exposes everything public inside it, under its real path; a re-export exposes exactly the items named in it, under the shorter path.

The fixes in reach order

  • Read the header's pair: the kind word, and the item name. The kind word says what was named - module, struct, function, constant, enum, static, type alias, trait - and the repair is applied to that item, or, when a second label names something not publicly re-exported, to the path in front of it.
  • Check the span's position in the path. When the span sits on the last segment, the item itself is private. When it sits on an earlier segment, that module is the closed link, and marking the item at the end of the path changes nothing.
  • Work out the naming module's position relative to the defining module. The same module and its descendants can already reach the item; a parent, a sibling, the crate root above the defining module, or another crate cannot.
  • No new reader should get the item: keep it private and move the naming into the defining module or a descendant, behind a public function that does the work there.
  • The readers are a known, bounded set: widen the item's visibility to exactly that set - pub(super) for the parent module, pub(crate) for the crate, pub(in path) for a named ancestor's subtree.
  • The item is genuinely public: mark it pub, the error index's repair. For an enum or a trait, the variants and associated items become public with it by default.
  • The item is already pub and the span sits on a module: publish that module, at pub or pub(crate) width, or re-export the item with pub use at a level callers can reach.
  • The header names a field, a method, or a name that does not exist: the defect is E0616, E0624, or E0432 respectively, each repaired by its own rule.

Traps

  • An item used inside its own module compiles, and so does the same item used from a descendant of that module. Here a private function is called by a public function in its own module, and again from a probe module nested inside it:
Rust
mod meter {
    fn secret() -> i32 {
        7
    }

    pub fn call() -> i32 {
        secret()
    }

    pub mod probe {
        pub fn read() -> i32 {
            super::secret()
        }
    }
}

fn main() {
    println!("{} {}", meter::call(), meter::probe::read());
}
Terminal
$ rustc --edition 2021 trap_inside.rs -o trap_inside
$ ./trap_inside
7 7
Trap
The output is 7 7. This is the shape every move-the-access fix relies on: the call itself never had to change, only its location. When E0603 appears on code that used to work, a common cause is a call that was moved out of the defining module - into main, into a helper module - during a refactor, leaving the item behind. - A private module declared at the crate root compiles when named from the root. Here a private module's public function is called from main:
Rust
mod inner {
    pub fn ping() {
        println!("ping");
    }
}

fn main() {
    inner::ping();
}
Terminal
$ rustc --edition 2021 trap_rootmod.rs -o trap_rootmod
$ ./trap_rootmod
ping

The output is ping. The module is defined in the root module, and a private item may be accessed by the module that defines it and that module's descendants - which, for an item defined at the root, is the entire crate. This is why the first family's module had to be nested: move inner from the root into outer and the identical call from main becomes E0603, because the root is then the defining module's parent, not the defining module. - A pub(crate) item compiles when read from elsewhere in the same crate. Here a sibling module reads a crate-visible function:

Rust
mod meter {
    pub(crate) fn secret() -> i32 {
        7
    }
}

mod reader {
    pub fn read() -> i32 {
        crate::meter::secret()
    }
}

fn main() {
    println!("{}", reader::read());
}
Terminal
$ rustc --edition 2021 trap_pubcrate.rs -o trap_pubcrate
$ ./trap_pubcrate
7

The output is 7. pub(crate) is the restricted width the fixes keep pointing at: the item is visible in every module of the current crate and in no other crate. The same function marked plain private fails from the sibling module with E0603, and marked pub it is visible to every crate that depends on this one - three different audiences for one keyword's difference. - A re-export makes an item behind a private module reachable. Here the ninth family's constant is re-exported by the module that contains its private module:

Rust
mod outer {
    mod inner {
        pub const LIMIT: i32 = 7;
    }

    pub use inner::LIMIT;
}

fn main() {
    println!("{}", outer::LIMIT);
}
Terminal
$ rustc --edition 2021 trap_reexport.rs -o trap_reexport
$ ./trap_reexport
7

The output is 7. inner stays private - the path outer::inner::LIMIT still fails with E0603 - but pub use inner::LIMIT; gives the constant a second path, outer::LIMIT, whose every link is visible from the crate root. This is the Reference's re-export rule: the re-export short-circuits the privacy chain instead of passing through the namespace hierarchy. It is the repair that exposes one item without exposing the module it lives in. - Importing a private item with use fails with E0603 itself. Here the import names the second family's struct:

Rust
mod meter {
    struct Meter {
        pub value: i32,
    }

    pub fn make() -> i32 {
        let m = Meter { value: 7 };
        m.value
    }
}

use meter::Meter;

fn main() {
    println!("{}", meter::make());
}
Terminal
$ rustc --edition 2021 trap_use_import.rs -o trap_use_import
error[E0603]: struct `Meter` is private
  --> trap_use_import.rs:12:12
   |
12 | use meter::Meter;
   |            ^^^^^ private struct
   |
note: the struct `Meter` is defined here
  --> trap_use_import.rs:2:5
   |
 2 |     struct Meter {
   |     ^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

The span sits on the imported name in the use line, and the definition note points at the struct, exactly as when the name is written in an expression or an annotation. An import is an access like any other: the item has to be visible from the module the import is written in. The repair is the same pub on the item - importing a name does not lower the visibility it requires. - A private union gives E0603 itself. Here a union type is named in an annotation from outside its module:

Rust
mod meter {
    union Bits {
        int: i32,
        float: f32,
    }

    pub fn make() -> i32 {
        let b = Bits { int: 7 };
        unsafe { b.int }
    }
}

fn main() {
    let b: Option<meter::Bits> = None;
    match b {
        Some(_) => println!("some"),
        None => println!("{}", meter::make()),
    }
}
Terminal
$ rustc --edition 2021 trap_union.rs -o trap_union
error[E0603]: union `Bits` is private
  --> trap_union.rs:14:26
   |
14 |     let b: Option<meter::Bits> = None;
   |                          ^^^^ private union
   |
note: the union `Bits` is defined here
  --> trap_union.rs:2:5
   |
 2 |     union Bits {
   |     ^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

The header's kind word is "union", and everything else about the diagnostic is the struct family's shape: span on the type's name, note at the definition. The kind word is the only part of the header that changes across item kinds - module, struct, enum, union, trait, function, constant, static, type alias - and the repair never changes with it: the item is marked pub, or the naming moves inside its module. - Naming a private field fails - with E0616, not E0603. Here the struct is public and reachable, and the field is what is private:

Rust
mod meter {
    pub struct Meter {
        value: i32,
    }

    impl Meter {
        pub fn new(value: i32) -> Meter {
            Meter { value }
        }
    }
}

fn main() {
    let m = meter::Meter::new(7);
    println!("{}", m.value);
}
Terminal
$ rustc --edition 2021 trap_field.rs -o trap_field
error[E0616]: field `value` of struct `Meter` is private
  --> trap_field.rs:15:22
   |
15 |     println!("{}", m.value);
   |                      ^^^^^ private field

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0616`.

The header names the field and the struct that owns it, and there is no definition note: the question this error answers is about the field's visibility, given a type the caller could already name. The boundary between the two codes is exactly the boundary between the two guides: if the type's own name cannot be written at the access site, the failure is E0603 and no field is ever mentioned; if the type is reachable and one of its fields is not, the failure is E0616, repaired with an accessor, a setter, or a wider field. - Calling a private method fails - with E0624, not E0603. Here the method that reads the value is what is private:

Rust
mod meter {
    pub struct Meter {
        value: i32,
    }

    impl Meter {
        pub fn new(value: i32) -> Meter {
            Meter { value }
        }

        fn secret(&self) -> i32 {
            self.value
        }
    }
}

fn main() {
    let m = meter::Meter::new(7);
    println!("{}", m.secret());
}
Terminal
$ rustc --edition 2021 trap_method.rs -o trap_method
error[E0624]: method `secret` is private
  --> trap_method.rs:19:22
   |
11 |         fn secret(&self) -> i32 {
   |         ----------------------- private method defined here
...
19 |     println!("{}", m.secret());
   |                      ^^^^^^ private method

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0624`.

Methods carry their own visibility, separate from the items around them: the struct is public, the field is legally read inside the method, and the method itself is private, so the call fails. Note the diagnostic's shape - the span at the definition is labeled "private method defined here" and sits inside the same span block as the call site, where the E0603 definition note is a separate note below the span. The repair is to mark the method pub or to call it from inside the module; no item visibility is involved on either side. - Building the struct with a literal outside its module fails - with E0451, not E0603 or E0616. Here the value is constructed in main instead of being read:

Rust
mod meter {
    pub struct Meter {
        value: i32,
    }

    pub fn read(m: &Meter) -> i32 {
        m.value
    }
}

fn main() {
    let m = meter::Meter { value: 7 };
    println!("{}", meter::read(&m));
}
Terminal
$ rustc --edition 2021 trap_literal.rs -o trap_literal
error[E0451]: field `value` of struct `Meter` is private
  --> trap_literal.rs:12:28
   |
12 |     let m = meter::Meter { value: 7 };
   |                            ^^^^^ private field

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0451`.

The struct is public, so its name is legal in the literal; the fields the literal sets are private, and construction names every field it sets, so the literal needs every one of them visible. The header's sentence matches E0616's - same field, same struct - and only the code differs. The repair is a constructor function inside the module, or visible fields; it is not a wider visibility on the type, which was never the closed link. - Importing a name that does not exist fails - with E0432, not E0603. Here the module is real and public in what it offers, and the imported name is simply not in it:

Rust
mod meter {
    pub fn get() -> i32 {
        7
    }
}

use meter::Missing;

fn main() {
    println!("{}", meter::get());
}
Terminal
$ rustc --edition 2021 trap_import_missing.rs -o trap_import_missing
error[E0432]: unresolved import `meter::Missing`
 --> trap_import_missing.rs:7:5
  |
7 | use meter::Missing;
  |     ^^^^^^^-------
  |            |
  |            no `Missing` in `meter`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0432`.

The span covers the whole import path, the note says there is no Missing in meter, and there is no definition note, because there is no definition. That absence is the tell that separates the two import failures: an E0603 import names an item that exists and is private, so the compiler can point at where it is defined; an E0432 import names an item that does not exist, and the repair is to correct the name or add the item, not to change any visibility.

Checklist

  • The header's kind-and-item pair read as the diagnosis - the kind word names what kind of item was named, and the item named is where the repair lands.
  • The span's position in the path checked: last segment means the item is private; an earlier segment means a module on the path is the closed link.
  • The naming module's position checked against the defining module: same module and descendants compile; parent, sibling, and other crates do not.
  • A private module at the crate root recognized as reachable from the whole crate, and the same module nested one level down recognized as a different case.
  • Visibility widened only as far as the actual readers: pub(super) for a parent, pub(crate) for the crate, pub for a genuinely public item.
  • An enum or trait marked pub with its variants and associated items public by default - no per-variant or per-item marking expected.
  • A public item behind a private module repaired on the path: the module published, or the item re-exported with pub use at a reachable level.
  • A field failure read as E0616, a method failure as E0624, a literal failure as E0451, and a nonexistent name as E0432, each repaired by its own rule.
  • The fixed program run, and its output checked against what the program was meant to print.

Sources

  • Rust, Error codes index: E0603 — for the definition of the error as a private item used outside its scope, its example of a private constant in a module read from outside the module, and the repair it names: make the item public by using the pub keyword.
  • The Rust Reference, Visibility and privacy — for everything being private by default, for a public item being accessible only when all of its ancestor modules are accessible too, for a private item being accessible by the current module and its descendants, for the restricted visibilities pub(crate), pub(super), and pub(in path), for enum variants and trait associated items being public by default in a pub enum or trait, and for pub use re-exports giving an item a path that does not pass through a private module.

Keep Exploring