Implementing a public trait for all types that implement a private trait emits a warning. However the presence of pub(crate) in an unrelated piece of code turns that warning into an error.
The warning is: warning: private trait `PrivateTrait` in public interface (error E0445)
The error is: error[E0445]: private trait `PrivateTrait` in public interface
The behaviour can be reproduced by commenting out pub(crate) struct Foo in this code:
trait PrivateTrait {}
pub trait PublicTrait {}
impl<T> PublicTrait for T where T: PrivateTrait {}
/*
Comment this out and the error is gone and the code compiles with a warning
*/
pub(crate) struct Foo;
Meta
I confirmed the presence of this behaviour on the rust playground for:
-
Stable channel
Build using the Stable version: 1.55.0
-
Beta channel
Build using the Beta version: 1.56.0-beta.4
(2021-10-04 e6e620e)
-
Nightly channel
Build using the Nightly version: 1.57.0-nightly
(2021-10-12 d7c97a0)
References