Rust

E0624 Method Is Private Fix

A method written without `pub` can be called only inside the module that defines it and inside that module's child modules. A call from anywhere else - the crate root, an unrelated module, another crate - is refused with E0624, however public the type itself is.

Written November 28, 2026 · Tested with Rust 1.99.1 · 12 min read

By the end of this guide
  • The rule underneath: a private item belongs to its module
  • The first failure: a call from the crate root
  • The same call from inside the module
  • A child module can call it too

Written November 28, 2026

Tested with Rust 1.99.1

What this guide is

Error E0624 fires when code calls a method that is private to another module. The type can be public, the value can be in hand, and the method name can be spelled exactly right - the call still fails, because a method written without pub is visible only inside the module that defines it and inside that module's child modules. The caller sits outside that scope, so the compiler refuses the call.

This guide reproduces the error from the two positions that fail - a call from the crate root and a call from an unrelated module - and sets them against the two positions that work: a call from inside the defining module itself, and a call from a child module of it. It then gives the two repairs: widen the method to pub so anyone who can name the type can call it, or widen it only to pub(crate) so the whole crate can call it and nothing outside the crate can. The last section separates the case that sounds closest but carries a different code: reading a private field is E0616, not E0624.

The rule underneath: a private item belongs to its module

The Rust Reference's visibility and privacy chapter states the default plainly: by default, everything is private. An item declared pub can be accessed from outside its module. A private item may be accessed by the current module and its descendants - the module it is defined in, plus every module nested inside that one, at any depth. No other position qualifies: not the parent module, not a sibling module, not the crate root, unless one of those is itself the defining module.

The same chapter covers the restricted forms of pub. pub(crate) makes an item visible within the current crate. pub(super) makes it visible to the parent module, and pub(self) is the same as leaving the item private. The official E0624 error page states the error from the other side: a private item was used outside of its scope, and it offers two repairs - use the item only in the scope where it was defined, or make the item public.

One point in that rule is easy to miss: the visibility of a type and the visibility of its methods are separate. A pub struct can carry a private method, and making the struct public does nothing for the method. Each item carries its own visibility, and the call below fails on the method's, not the type's.

The first failure: a call from the crate root

A public type with a private method, called from main outside the module:

Rust
mod bank {
    pub struct Account;

    impl Account {
        fn audit(&self) -> i32 {
            42
        }
    }
}

fn main() {
    let account = bank::Account;
    println!("audit {}", account.audit());
}
Terminal
$ rustc --edition 2021 p1_fail_private.rs -o p1_fail_private.bin
error[E0624]: method `audit` is private
  --> p1_fail_private.rs:13:34
   |
 5 |         fn audit(&self) -> i32 {
   |         ---------------------- private method defined here
...
13 |     println!("audit {}", account.audit());
   |                                  ^^^^^ private method

error: aborting due to 1 previous error

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

The diagnostic names both ends of the problem. One span underlines the definition and labels it "private method defined here"; the other underlines the call in main and labels it "private method". Account itself is never criticized - it is pub, the value is built without complaint, and the single error is the call. main sits at the crate root, which is the parent of mod bank, and a parent is outside the scope a private item allows.

The same call from inside the module

Move the call into the defining module, behind a public function the root can call, and the identical method call compiles:

Rust
mod bank {
    pub struct Account;

    impl Account {
        fn audit(&self) -> i32 {
            42
        }
    }

    pub fn run() -> i32 {
        let account = Account;
        account.audit()
    }
}

fn main() {
    println!("audit {}", bank::run());
}
Terminal
$ rustc --edition 2021 p2_ok_inside.rs -o p2_ok_inside.bin
$ ./p2_ok_inside.bin
audit 42

Nothing about the method changed - it is still written without pub. What changed is the caller's position: run is inside mod bank, the module that defines audit, so the call is in scope. This is also a repair pattern in its own right when the method should stay private: keep it private, and expose a public function in the same module that calls it for outside code. The E0624 error page gives this as its first solution - only use the item in the scope it has been defined.

A child module can call it too

The scope is not just the defining module itself. A module nested inside it is a descendant, and a call from there compiles as well:

Rust
mod bank {
    pub struct Account;

    impl Account {
        fn audit(&self) -> i32 {
            42
        }
    }

    pub mod checks {
        pub fn run(account: &super::Account) -> i32 {
            account.audit()
        }
    }
}

fn main() {
    let account = bank::Account;
    println!("audit {}", bank::checks::run(&account));
}
Terminal
$ rustc --edition 2021 p3_ok_child.rs -o p3_ok_child.bin
$ ./p3_ok_child.bin
audit 42

mod checks sits inside mod bank, so it is a descendant of the module that defines audit, and the private method is in its scope. This is why unit tests written in a child module of the code under test can reach private items without any change to their visibility: the test module is a descendant of the module it tests. Descent is the whole test - how the caller is nested relative to the defining module, not how close the two feel.

An unrelated module cannot

A caller in a module that is neither the defining module nor a descendant of it fails with the same error, even when it sits in the same file and the same crate:

Rust
mod bank {
    pub struct Account;

    impl Account {
        fn audit(&self) -> i32 {
            42
        }
    }
}

mod other {
    pub fn run(account: &crate::bank::Account) -> i32 {
        account.audit()
    }
}

fn main() {
    let account = bank::Account;
    println!("audit {}", other::run(&account));
}
Terminal
$ rustc --edition 2021 p4_fail_unrelated.rs -o p4_fail_unrelated.bin
error[E0624]: method `audit` is private
  --> p4_fail_unrelated.rs:13:17
   |
 5 |         fn audit(&self) -> i32 {
   |         ---------------------- private method defined here
...
13 |         account.audit()
   |                 ^^^^^ private method

error: aborting due to 1 previous error

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

mod other is a sibling of mod bank - neither contains the other - so the call is outside the scope, and the diagnostic is identical to the crate-root failure. Being in the same crate is not enough for a private item; that wider scope has to be asked for, which is what the second fix does. When an E0624 appears after code is moved between modules, this is usually the shape: the call did not change, the method did not change, but the caller's module is no longer the defining module or one of its descendants.

The first fix: make the method public

The direct repair widens the method itself. One word at its definition makes it callable from anywhere the type can be named:

Rust
mod bank {
    pub struct Account;

    impl Account {
        pub fn audit(&self) -> i32 {
            42
        }
    }
}

fn main() {
    let account = bank::Account;
    println!("audit {}", account.audit());
}
Terminal
$ rustc --edition 2021 p5_fix_pub.rs -o p5_fix_pub.bin
$ ./p5_fix_pub.bin
audit 42

The call in main is unchanged; only the definition gained pub. Choose this fix when the method is part of what the type offers to the world - the normal case for a method other code is meant to use, and the only form that lets code in another crate call it. The cost is just as plain: the method is now part of the module's public surface, and any caller who can name Account can call it.

The second fix: widen it only to the crate

When the callers are all in the same crate - other modules of one program, or one library's own internals - the method can be widened to the crate and no further:

Rust
mod bank {
    pub struct Account;

    impl Account {
        pub(crate) fn audit(&self) -> i32 {
            42
        }
    }
}

fn main() {
    let account = bank::Account;
    println!("audit {}", account.audit());
}
Terminal
$ rustc --edition 2021 p6_fix_pubcrate.rs -o p6_fix_pubcrate.bin
$ ./p6_fix_pubcrate.bin
audit 42

pub(crate) makes the item visible within the current crate, so the crate root, a sibling module, and every other module in the crate can call it - the unrelated-module failure above included. What it does not do is expose the method outside the crate: to code in another crate, a pub(crate) method is not public at all. Choose this fix for crate-internal plumbing that several modules share; choose plain pub when a caller in another crate needs the method, because no restricted form reaches that far.

Neighboring error: a private field is E0616

The same module boundary applied to data instead of behavior carries a different code. Reading a private field from outside the defining module is E0616:

Rust
mod bank {
    pub struct Account {
        balance: i32,
    }

    pub fn open() -> Account {
        Account { balance: 42 }
    }
}

fn main() {
    let account = bank::open();
    println!("balance {}", account.balance);
}
Terminal
$ rustc --edition 2021 p7_neighbour_field.rs -o p7_neighbour_field.bin
error[E0616]: field `balance` of struct `Account` is private
  --> p7_neighbour_field.rs:13:36
   |
13 |     println!("balance {}", account.balance);
   |                                    ^^^^^^^ private field

error: aborting due to 1 previous error

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

The reading rule is the one this guide is about: read the noun in the header. A private method call is E0624, "method is private"; a private field read is E0616, "field of struct is private", and its span labels the access "private field". The repairs rhyme - make the item public, widen it, or reach it through code inside the module - but the codes are distinct, and searching one code for the other's case leads to the wrong page.

Decision summary

  • The header says "method is private" (E0624) and the caller is the crate root or a function outside the defining module: the call is out of scope - move the call inside the module, or widen the method with one of the fixes.
  • The header says E0624 and the caller sits in a sibling or other unrelated module of the same crate: same-crate is not in scope for a private item - pub(crate) is the smallest widening that covers every module in the crate.
  • The call comes from a module nested inside the defining module and still fails: check what it actually names - a descendant calling the private method itself is in scope, so an E0624 there points at a different item, or at a caller that is not nested where it looks nested.
  • The method should stay private by design: leave it unmarked and expose a public function inside the defining module that calls it, as in the inside-the-module program above.
  • Callers in another crate need the method: only plain pub reaches them - pub(crate) and the other restricted forms stop at the crate boundary.
  • The header instead says "field of struct is private" (E0616): the private item is a field, not a method - the boundary is the same, the code and its fix page are the field ones.

Checklist

  • The failing call's module is identified against the defining module: it is the defining module, a descendant of it, or outside - and only the first two are in scope for a private method.
  • The type being pub is not treated as making its methods public; the method carries its own visibility at its own definition.
  • The widening matches the callers: pub for callers anywhere including other crates, pub(crate) for callers inside this crate only.
  • A method that stays private is reached through a public function defined in the same module, not by callers outside it.
  • An E0624 names a method and an E0616 names a field; the header's noun is checked before a fix is chosen.
  • The fixed program compiles, runs, and prints the value the method returns.
  • E0616 Field Is Private Fix - the field side of the same boundary: a private field read from outside its module, where here the private item being reached for is a method.
  • E0603 Private Item Fix - the import side of privacy: a use path names an item that is private, where E0624 is a direct method call on a value already in hand.
  • E0609 No Field Fix - the other field error: the named field does not exist on the type at all, where E0616's field exists and is private, and E0624's item is a method.

Sources

  • Rust, Error codes index: E0624 - the definition of the error: a private item was used outside of its scope; its two stated repairs are to use the item only in the scope it has been defined, shown with a public function inside the module calling the private method, or to make the item public - the inside-the-module pattern and the first fix in this guide.
  • The Rust Reference, Visibility and privacy - the scope rule underneath: by default everything is private; a private item may be accessed by the current module and its descendants; pub(crate) makes an item visible within the current crate, alongside the pub(super) and pub(self) restrictions - the rule the failure shapes and the second fix rest on.
  • Rust, Error codes index: E0616 - the neighboring error: an attempt to access a private field on a struct, repaired by setting the field public or adding a getter function - the boundary the neighboring section draws.

Keep Exploring