You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
traitPrivateTrait{}pubtraitPublicTrait{}impl<T>PublicTraitforTwhereT:PrivateTrait{}/*Comment this out and the error is gone and the code compiles with a warning*/pub(crate)structFoo;
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)
I believe #48054 means this should one day be accepted without any diagnostic, although the current implementation status is that it still triggers the legacy public-in-private lint. Even so, that lint ought to be a warning, not an error.
I think the intent is that since newer crates can use pub(crate) and similar visibilities, they no longer need to use private-in-public items to achieve the same effect, and so the compiler can emit a hard error instead of accepting the behavior for compatibility reasons when the new visibilities are being used.
That seems like pretty surprising behaviour, especially given Rust's avoidance of action at a distance. Granted, the warning is a future compat lint, but I'd expect it to always warn or always error in a given release using a given edition.
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: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
The text was updated successfully, but these errors were encountered: