Skip to content

"Private trait in public interface warning" changes to error when an unrelated pub(crate) is present #89857

Closed
@simonadameit

Description

@simonadameit

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions