Rust

E0446 Private Type in Public Fix

E0446 is narrower than its message suggests. On the current compiler the hard error - private type in public interface - is the associated-type case: a public trait whose implementation names a private type as an associated type, a type the trait's audience cannot reach. Most of the other shapes the message brings to mind - a public function returning a private type, a public field of a private type, a public alias for one - are not this error anymore: they compile with a warning that the type is more private than the item. This guide works the probed split shape by shape, shows the repairs running, and separates the uncoded privacy error you get when a value of the private type is actually used across the module boundary.

Written November 30, 2026 · Tested with Rust 1.99.0 · 24 min read

By the end of this guide
  • The rule underneath: the type must be at least as reachable as the item naming it
  • How to read the diagnostic
  • The hard error: an associated type set to a private type
  • The warning family: public items exposing a private type

Written November 30, 2026

Tested with Rust 1.99.0

What this guide is

Error E0446 is about reach. The error codes index defines it in one sentence: "A private type or trait was used in a public associated type signature." An item that other code can reach - a public trait, in the index's definition - names a type that the same code cannot reach, and the compiler refuses the leak at the point where the two visibilities meet.

The practical payoff is knowing which shapes still carry this code and which do not. In this guide's probed set, exactly one family is E0446: an associated type set to a private type in the implementation of a more-visible trait. The neighboring shapes divide three other ways. Public functions, fields, aliases, enum variants, and trait methods that expose a private type compile with the private_interfaces warning - the compiler reports that the type "is more private than the item" and builds anyway. Actually using a value of the private type from outside its module is a different failure again, an uncoded privacy error at the use site. And naming a private item by path from outside its scope is neither of these - it is E0603. Reading the diagnostic in front of you against that split is most of the fix.

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 rule underneath: the type must be at least as reachable as the item naming it

Visibility in Rust is per module, and it composes. The Rust Reference's visibility and privacy page puts the base rule plainly: if an item is private, it may be accessed by the current module and its descendants - and a pub item inside a module is only as public as the paths that reach the module allow, including paths created by re-exports. So every item has an effective reach: how far away code can stand and still use it.

The E0446 comparison is between two reaches. When an associated type in a public trait's implementation is set to a type whose reach is smaller than the trait's, outside code could obtain a value of a type it cannot name, construct, or reason about - the leak the error names. The same comparison, applied to ordinary function signatures, fields, and aliases, is today reported by the private_interfaces lint as a warning rather than by E0446 as an error, in every such shape probed for this guide. The comparison is the same; the severity is not, and the sections below keep the two apart shape by shape.

Two consequences follow. First, narrowing the wider side works only when the narrowing is real: the trait and the type must end up with the same reach, as the pub(crate) pair below shows from both sides. Second, widening the narrower side always works: making the type public, or re-exporting it so a public path reaches it, removes the mismatch itself rather than arguing about which side to move.

How to read the diagnostic

The E0446 failure in the probed set is a single error. Its header names the type - "private type Bar in public interface" - and its span underlines the associated-type assignment, with the note "can't leak private type". A second span points back at the type's declaration, labeled "declared as private", so the two spans together show both sides of the mismatch: where the type leaks, and where its privacy is set. There is no help text performing a repair; the index page offers the two repairs in prose, and both are worked below.

The warning that replaces E0446 for the other shapes reads differently, and the difference is the fastest tell. Its header is "type Priv is more private than the item" - naming the item it is compared against - and its note gives both reaches explicitly: the item "is reachable at visibility pub" while the type "is only usable at visibility pub(self)". It is emitted under the private_interfaces lint, on by default, and the build continues. If your diagnostic says "more private than the item", you do not have E0446, whatever search result brought you here.

The hard error: an associated type set to a private type

The error index's own example is the smallest shape. A private unit struct, a public trait with one associated type, and an implementation for a public type that sets the associated type to the private struct:

Rust
struct Bar;
pub trait PubTr { type Alias; }
impl PubTr for u8 { type Alias = Bar; }
fn main() {}
Output
error[E0446]: private type `Bar` in public interface
 --> official.rs:3:21
  |
1 | struct Bar;
  | ---------- `Bar` declared as private
2 | pub trait PubTr { type Alias; }
3 | impl PubTr for u8 { type Alias = Bar; }
  |                     ^^^^^^^^^^ can't leak private type

error: aborting due to 1 previous error

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

Nothing here is exotic: the trait is public, so any code that can use the trait can ask what Alias is for u8 - and the answer is a type that code cannot reach. The same shape inside a public module, with the trait, the implementing struct, and the private type all declared in the module, fails identically:

Rust
pub mod inner {
    struct Priv(u8);
    pub trait Tr { type Out; }
    pub struct S;
    impl Tr for S { type Out = Priv; }
}
fn main() {}
Output
error[E0446]: private type `Priv` in public interface
 --> assocpub.rs:5:21
  |
2 |     struct Priv(u8);
  |     ----------- `Priv` declared as private
...
5 |     impl Tr for S { type Out = Priv; }
  |                     ^^^^^^^^ can't leak private type

warning: field `0` is never read
 --> assocpub.rs:2:17
  |
2 |     struct Priv(u8);
  |            ---- ^^
  |            |
  |            field in this struct
  |
  = help: consider removing this field
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

error: aborting due to 1 previous error; 1 warning emitted

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

The module being public is what makes the trait's reach pub; the type, declared without pub inside the module, is usable only within the module itself. The implementation is the meeting point, and it is where the error lands. In the probed set these two shapes - the index example at crate root and the public-module form - are the only E0446 failures, and every other shape in this guide divides elsewhere. That is the guide's central fact: if your code carries E0446, look for an associated type first.

The warning family: public items exposing a private type

A public function returning a private type, in a public module, compiles. The diagnostic is the private_interfaces warning, and with nothing outside the module touching the returned value, the build succeeds:

Rust
pub mod inner {
    struct Priv(u8);
    pub fn make() -> Priv { Priv(7) }
}
fn main() {}
Output
warning: type `Priv` is more private than the item `make`
 --> retclean.rs:3:5
  |
3 |     pub fn make() -> Priv { Priv(7) }
  |     ^^^^^^^^^^^^^^^^^^^^^ function `make` is reachable at visibility `pub`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> retclean.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: field `0` is never read
 --> retclean.rs:2:17
  |
2 |     struct Priv(u8);
  |            ---- ^^
  |            |
  |            field in this struct
  |
  = help: consider removing this field
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: 2 warnings emitted

The same is true of a public function taking the private type as an argument - this program declares both directions, the argument and the return, and both are warnings on the same terms:

Rust
pub mod inner {
    struct Priv(u8);
    pub fn take(_p: Priv) {}
    pub fn make() -> Priv { Priv(7) }
}
fn main() {}
Output
warning: type `Priv` is more private than the item `inner::take`
 --> argpub.rs:3:5
  |
3 |     pub fn take(_p: Priv) {}
  |     ^^^^^^^^^^^^^^^^^^^^^ function `inner::take` is reachable at visibility `pub`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> argpub.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: type `Priv` is more private than the item `make`
 --> argpub.rs:4:5
  |
4 |     pub fn make() -> Priv { Priv(7) }
  |     ^^^^^^^^^^^^^^^^^^^^^ function `make` is reachable at visibility `pub`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> argpub.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^

warning: field `0` is never read
 --> argpub.rs:2:17
  |
2 |     struct Priv(u8);
  |            ---- ^^
  |            |
  |            field in this struct
  |
  = help: consider removing this field
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: 3 warnings emitted

A public struct with a public field of the private type follows the same pattern - the warning names the field as the item the type is more private than:

Rust
pub mod inner {
    struct Priv(u8);
    pub struct Holder { pub f: Priv }
}
fn main() {}
Output
warning: type `Priv` is more private than the item `Holder::f`
 --> fieldpub.rs:3:25
  |
3 |     pub struct Holder { pub f: Priv }
  |                         ^^^^^^^^^^^ field `Holder::f` is reachable at visibility `pub`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> fieldpub.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: field `0` is never read
 --> fieldpub.rs:2:17
  |
2 |     struct Priv(u8);
  |            ---- ^^
  |            |
  |            field in this struct
  |
  = help: consider removing this field
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: 2 warnings emitted

So does a public trait whose method returns the private type. Note the contrast with the previous section: a trait method signature naming the private type is a warning, while an associated type assignment naming it is E0446 - the trait is involved in both, but only the associated type is the hard error in the probed set:

Rust
pub mod inner {
    struct Priv(u8);
    pub trait Tr { fn get(&self) -> Priv; }
}
fn main() {}
Output
warning: type `Priv` is more private than the item `Tr::get`
 --> traitret.rs:3:20
  |
3 |     pub trait Tr { fn get(&self) -> Priv; }
  |                    ^^^^^^^^^^^^^^^^^^^^^^ method `Tr::get` is reachable at visibility `pub`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> traitret.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: field `0` is never read
 --> traitret.rs:2:17
  |
2 |     struct Priv(u8);
  |            ---- ^^
  |            |
  |            field in this struct
  |
  = help: consider removing this field
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: 2 warnings emitted

A public type alias for the private type, and a public enum whose variant carries it, complete the family - in both, the warning names the alias and the variant field respectively as the wider item:

Rust
pub mod inner {
    struct Priv(u8);
    pub type Alias = Priv;
}
fn main() {}
Output
warning: type `Priv` is more private than the item `Alias`
 --> aliaspub.rs:3:5
  |
3 |     pub type Alias = Priv;
  |     ^^^^^^^^^^^^^^ type alias `Alias` is reachable at visibility `pub`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> aliaspub.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: field `0` is never read
 --> aliaspub.rs:2:17
  |
2 |     struct Priv(u8);
  |            ---- ^^
  |            |
  |            field in this struct
  |
  = help: consider removing this field
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: 2 warnings emitted

Rust
pub mod inner {
    struct Priv(u8);
    pub enum E { V(Priv) }
}
fn main() {}
Output
warning: type `Priv` is more private than the item `E::V::0`
 --> enumpub.rs:3:20
  |
3 |     pub enum E { V(Priv) }
  |                    ^^^^ field `E::V::0` is reachable at visibility `pub`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> enumpub.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: field `0` is never read
 --> enumpub.rs:2:17
  |
2 |     struct Priv(u8);
  |            ---- ^^
  |            |
  |            field in this struct
  |
  = help: consider removing this field
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: 2 warnings emitted

Across this family the pattern is constant: the program compiles, the warning names the type, the item, and both visibilities, and a dead_code warning about the unread field rides along in these small programs because nothing reads the value - it is not part of the visibility story. Treat the warning as a real defect in a library interface - downstream code is being handed a type it cannot name - but do not expect the E0446 repairs to be forced on you by the compiler here; the compiler is advising, not stopping.

Narrowing with pub(crate): it works only when it truly narrows

The error index's first repair is to make the public signature "only public to a module that also has access to the private type", using pub(crate) or a pub(in ...) restriction. That repair is about matching reaches, and the probed pair shows both sides of it. At crate root, a private type is reachable throughout its crate - the root module's descendants are the whole crate - so narrowing the trait to pub(crate) makes the two reaches equal, and the index's failing example compiles and runs:

Rust
struct Bar;
pub(crate) trait PubTr { type Alias; }
impl PubTr for u8 { type Alias = Bar; }
fn main() { println!("ok"); }
Output
ok

The output is ok. Inside a public module the same word does not save the associated type, because the type there is private to the module alone while a pub(crate) trait is reachable across the crate - the trait is still the wider side, and E0446 still fires:

Rust
pub mod inner {
    struct Priv(u8);
    pub(crate) trait Tr { type Out; }
    pub struct S;
    impl Tr for S { type Out = Priv; }
}
fn main() { println!("ok"); }
Output
error[E0446]: private type `Priv` in public interface
 --> assoccrate.rs:5:21
  |
2 |     struct Priv(u8);
  |     ----------- `Priv` declared as private
...
5 |     impl Tr for S { type Out = Priv; }
  |                     ^^^^^^^^ can't leak private type

warning: struct `Priv` is never constructed
 --> assoccrate.rs:2:12
  |
2 |     struct Priv(u8);
  |            ^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: trait `Tr` is never used
 --> assoccrate.rs:3:22
  |
3 |     pub(crate) trait Tr { type Out; }
  |                      ^^

error: aborting due to 1 previous error; 2 warnings emitted

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

And narrowing a function does not remove even the warning when the function remains wider than the type: a pub(crate) function inside a public module returning the module-private type still draws the private_interfaces warning, with the function's reach reported as pub(crate) against the type's pub(self):

Rust
pub mod inner {
    struct Priv(u8);
    pub(crate) fn make() -> Priv { Priv(7) }
}
fn main() {}
Output
warning: type `Priv` is more private than the item `make`
 --> cratefnclean.rs:3:5
  |
3 |     pub(crate) fn make() -> Priv { Priv(7) }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `make` is reachable at visibility `pub(crate)`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> cratefnclean.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: struct `Priv` is never constructed
 --> cratefnclean.rs:2:12
  |
2 |     struct Priv(u8);
  |            ^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: function `make` is never used
 --> cratefnclean.rs:3:19
  |
3 |     pub(crate) fn make() -> Priv { Priv(7) }
  |                   ^^^^

warning: 3 warnings emitted

The lesson is arithmetic, not keywords: compare the two reaches the diagnostic prints, and move a side until they match. A restriction that leaves the item wider than the type changes nothing.

The traps: neighbors that are not E0446

Trap
Two nearby failures look like this error's territory and are not it.

First, using the value is stricter than declaring the signature. The warning-family program above compiled while nothing outside the module touched the private type; the moment code outside the module holds the returned value, the build fails - not with E0446 and not with a code at all, but with a plain privacy error at the use site:

Rust
pub mod inner {
    struct Priv(u8);
    pub fn make() -> Priv { Priv(7) }
}
fn main() { let _p = inner::make(); }
Output
warning: type `Priv` is more private than the item `make`
 --> retpub.rs:3:5
  |
3 |     pub fn make() -> Priv { Priv(7) }
  |     ^^^^^^^^^^^^^^^^^^^^^ function `make` is reachable at visibility `pub`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> retpub.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: field `0` is never read
 --> retpub.rs:2:17
  |
2 |     struct Priv(u8);
  |            ---- ^^
  |            |
  |            field in this struct
  |
  = help: consider removing this field
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

error: type `Priv` is private
 --> retpub.rs:5:22
  |
5 | fn main() { let _p = inner::make(); }
  |                      ^^^^^^^^^^^^^ private type

error: aborting due to 1 previous error; 2 warnings emitted

The interface declaration drew only the warning; the use is what the compiler stops. This is why the warning family matters in practice even though it compiles: the first downstream use of the leaked type is an error, just a differently shaped one.

Second, naming a private item by path from outside its scope is E0603, the private-item code. A type annotation that names the module-private struct from the crate root:

Rust
pub mod inner {
    struct Priv(u8);
}
fn main() { let _x: Option<inner::Priv> = None; }
Output
error[E0603]: struct `Priv` is private
 --> e0603demo.rs:4:35
  |
4 | fn main() { let _x: Option<inner::Priv> = None; }
  |                                   ^^^^ private struct
  |
note: the struct `Priv` is defined here
 --> e0603demo.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

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

E0603 is about the path - the name itself is private - while E0446 is about a signature leaking a type to an audience that cannot reach it. When the diagnostic says "is private" about a path you wrote, it is E0603's territory; the E0603 guide works that family. (The neighboring order-and-kind error for generic arguments, E0747, is worked in the E0747 guide; the field-declaration neighbor is in the E0124 guide.)

One more shape cannot be written on stable Rust at all: giving the associated type a default in the trait declaration itself stops earlier, with E0658, because associated type defaults are unstable:

Rust
pub mod inner {
    struct Priv(u8);
    pub trait Tr { type Out = Priv; }
}
fn main() {}
Output
error[E0658]: associated type defaults are unstable
 --> traitdecl.rs:3:20
  |
3 |     pub trait Tr { type Out = Priv; }
  |                    ^^^^^^^^^^^^^^^^
  |
  = note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information

error: aborting due to 1 previous error

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

That is a feature-availability error, not a visibility one - the declaration form is not yet stable, whatever visibilities the types carry.

What is allowed: the controls

Code inside the type's own module uses it freely, including through the module's public functions. Here the private module's own public functions construct the private type and read it back, composed inside the module and called from outside by a function that returns only a public type:

Rust
mod inner {
    struct Priv(u8);
    pub fn make() -> Priv { Priv(7) }
    pub fn val(p: Priv) -> u8 { p.0 }
    pub fn run() -> u8 { val(make()) }
}
fn main() { println!("{}", inner::run()); }
Output
warning: type `Priv` is more private than the item `make`
 --> samemodrun.rs:3:5
  |
3 |     pub fn make() -> Priv { Priv(7) }
  |     ^^^^^^^^^^^^^^^^^^^^^ function `make` is reachable at visibility `pub(crate)`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> samemodrun.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: type `Priv` is more private than the item `val`
 --> samemodrun.rs:4:5
  |
4 |     pub fn val(p: Priv) -> u8 { p.0 }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^ function `val` is reachable at visibility `pub(crate)`
  |
note: but type `Priv` is only usable at visibility `pub(self)`
 --> samemodrun.rs:2:5
  |
2 |     struct Priv(u8);
  |     ^^^^^^^^^^^

warning: 2 warnings emitted

Output
7

The output is 7, the value the private type carried. The program compiles and runs: the two warnings remain, because pub functions inside a private module are reachable at pub(crate) while the type is usable only inside the module - but no value of the private type crosses the boundary, so there is no use-site error, and the composition is sound. The warnings are the compiler noting the signature's shape, not a failure of the program.

A private type can also stay private behind a trait the caller does know. Returning it as impl Trait, where the trait is declared in the same crate, compiles and runs - and note what the one warning is about: the trait is more private than the function, not the type. The concrete private type itself draws no diagnostic, because it never appears in the signature:

Rust
trait Hidden { fn val(&self) -> u8; }
struct Priv(u8);
impl Hidden for Priv { fn val(&self) -> u8 { self.0 } }
pub fn make() -> impl Hidden { Priv(9) }
fn main() { println!("{}", make().val()); }
Output
warning: trait `Hidden` is more private than the item `make`
 --> impltrait.rs:4:1
  |
4 | pub fn make() -> impl Hidden { Priv(9) }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `make` is reachable at visibility `pub`
  |
note: but trait `Hidden` is only usable at visibility `pub(crate)`
 --> impltrait.rs:1:1
  |
1 | trait Hidden { fn val(&self) -> u8; }
  | ^^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: 1 warning emitted

Output
9

The output is 9. The trait-object form behaves the same way in the probed set - a public function returning the private type boxed behind the crate's own trait compiles and runs, with the same warning about the trait and none about the type:

Rust
trait Hidden { fn val(&self) -> u8; }
struct Priv(u8);
impl Hidden for Priv { fn val(&self) -> u8 { self.0 } }
pub fn make() -> Box<dyn Hidden> { Box::new(Priv(11)) }
fn main() { println!("{}", make().val()); }
Output
warning: trait `Hidden` is more private than the item `make`
 --> dyntrait.rs:4:1
  |
4 | pub fn make() -> Box<dyn Hidden> { Box::new(Priv(11)) }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `make` is reachable at visibility `pub`
  |
note: but trait `Hidden` is only usable at visibility `pub(crate)`
 --> dyntrait.rs:1:1
  |
1 | trait Hidden { fn val(&self) -> u8; }
  | ^^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: 1 warning emitted

Output
11

The output is 11. In both forms the caller works through the trait and never names the concrete type, which is exactly the arrangement the visibility comparison is checking for.

Last, a public function at crate root returning a type that is public inside a private module produced no diagnostic at all in the probed set, and ran:

Rust
mod inner {
    pub struct Priv(pub u8);
    pub fn make() -> Priv { Priv(7) }
}
pub fn make() -> inner::Priv { inner::make() }
fn main() { println!("{}", make().0); }
Output
7

The output is 7. The type's reach through its module and the function's reach coincide closely enough in this single-crate shape that the lint stays silent; the re-export repair below is what turns that arrangement into a deliberately public one.

Fixes in reach order

First, widen the type. Making the private type public is the error index's second repair, and applied to its own example it compiles and runs:

Rust
pub struct Bar;
pub trait PubTr { type Alias; }
impl PubTr for u8 { type Alias = Bar; }
fn main() { println!("ok"); }
Output
ok

The output is ok. The same widening applied to the warning family's function - the type declared pub inside the public module - leaves a program with no visibility diagnostic at all, and it runs:

Rust
pub mod inner {
    pub struct Priv(pub u8);
    pub fn make() -> Priv { Priv(7) }
}
fn main() { println!("{}", inner::make().0); }
Output
7

The output is 7, the value the function returns inside the type. Widening is the right repair when the type genuinely belongs in the public interface: callers can name it, hold it, and match on it, and every shape in this guide that involved it goes quiet.

Second, narrow the trait - but only to the type's actual reach, per the pub(crate) section above: at crate root, where a private type is crate-reachable, pub(crate) on the trait matched the reaches and the program ran. Inside a module, the matching move is to keep the trait no wider than the module, or to move the type out to the wider scope. Check the two visibilities the diagnostic prints before choosing the keyword.

Third, re-export the type so a public path reaches it. The Reference's visibility page describes pub use as allowing public access into the re-exported item, and applied to the private-module arrangement above, the re-exported type can be named at the crate root under its own name:

Rust
mod inner {
    pub struct Priv(pub u8);
    pub fn make() -> Priv { Priv(7) }
}
pub use inner::Priv;
pub fn make() -> Priv { inner::make() }
fn main() { let p: Priv = make(); println!("{}", p.0); }
Output
7

The output is 7. The type is now part of the public surface at the path the re-export creates, which is the deliberate form of the private-module control: same module layout, but the type's reach is a chosen public path rather than an accident of the layout.

Fourth, when the type should stay private, hide it behind a trait the audience can use - the impl Trait and trait-object controls above are this repair: the signature names only the trait, callers work through the trait's methods, and the concrete type never enters the interface.

Decision summary

E0446, in this guide's probed set, fired exactly twice: the error index's example - an implementation of a public trait setting its associated type to a private type - and the same shape inside a public module. It did not fire for a public function returning or taking a private type, a public field of a private type, a trait method returning one, a public type alias for one, or a public enum variant carrying one: all of those compiled with the private_interfaces warning that the type "is more private than the item". Narrowing the trait to pub(crate) repaired the index example at crate root and did not repair the public-module shape, where the trait remained wider than the module-private type; a pub(crate) function still drew the warning against a module-private type. Using a leaked value from outside the module failed with an uncoded "type is private" error at the use site, and naming the private type by path from outside was E0603. Internal use inside the type's module compiled and ran; returning the type behind impl Trait or a trait object compiled and ran with warnings only about the private trait; and the repairs that ran were making the type public, matching the trait's reach to the type's, and re-exporting the type under a public path.

Checklist

  • Look for an associated type first: in the probed set, E0446 fired only where an implementation of a more-visible trait set an associated type to a private type.
  • Read the header before repairing: "private type in public interface" is the hard error; "type is more private than the item" is the private_interfaces warning, and the program compiles.
  • Compare the two reaches the diagnostic prints - the item's reachable visibility against the type's usable visibility - and move the side that is wrong: widen the type, narrow the item, or re-export the type.
  • Do not expect a keyword alone to narrow: in the probed set, pub(crate) on a trait inside a public module still left the trait wider than the module-private type, and E0446 still fired.
  • Expect the use to be stricter than the declaration: in the probed set, a signature exposing a private type only warned, but holding the returned value outside the module was an uncoded privacy error.
  • Keep the neighbors apart: naming a private item by path is E0603, and an associated-type default in the trait declaration is E0658 on stable - neither is repaired by visibility changes alone.

Sources

  • Rust error codes index, E0446 - a private type or trait was used in a public associated type signature; the erroneous example setting a public trait's associated type Alias to the private Bar in an implementation for u8; the two repairs - make the public signature only public to a scope that also has access to the private type, using pub(crate) or pub(in ...) (shown by narrowing the trait to pub(crate)), or make the private type public (shown by declaring Bar public).
  • The Rust Reference, Visibility and privacy - a private item may be accessed by the current module and its descendants; the scoped visibility forms pub(in path), pub(crate), pub(super), and pub(self); publicly re-exporting an item through a pub use directive allows public access into the re-exported item, as in the reference's example re-exporting an API module's contents.
  • Rust error codes index, E0603 - the neighboring path code: a private item was used outside its scope; its erroneous example uses a private constant from outside its module, and the fix is to make the item public or access it through its own module.

Keep Exploring