rust/tests/ui/privacy/sealed-traits/sealed-trait-local.rs
Esteban Küber 6dbad23641 When encountering sealed traits, point types that implement it
```
error[E0277]: the trait bound `S: d::Hidden` is not satisfied
  --> $DIR/sealed-trait-local.rs:53:20
   |
LL | impl c::Sealed for S {}
   |                    ^ the trait `d::Hidden` is not implemented for `S`
   |
note: required by a bound in `c::Sealed`
  --> $DIR/sealed-trait-local.rs:17:23
   |
LL |     pub trait Sealed: self::d::Hidden {
   |                       ^^^^^^^^^^^^^^^ required by this bound in `Sealed`
   = note: `Sealed` is a "sealed trait", because to implement it you also need to implement `c::d::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it
   = help: the following types implement the trait:
            - c::X
            - c::Y
```

The last `help` is new.
2023-10-27 17:40:52 +00:00

56 lines
972 B
Rust

// provide custom privacy error for sealed traits
pub mod a {
pub trait Sealed: self::b::Hidden {
fn foo() {}
}
struct X;
impl Sealed for X {}
impl self::b::Hidden for X {}
mod b {
pub trait Hidden {}
}
}
pub mod c {
pub trait Sealed: self::d::Hidden {
fn foo() {}
}
struct X;
impl Sealed for X {}
impl self::d::Hidden for X {}
struct Y;
impl Sealed for Y {}
impl self::d::Hidden for Y {}
mod d {
pub trait Hidden {}
}
}
pub mod e {
pub trait Sealed: self::f::Hidden {
fn foo() {}
}
struct X;
impl self::f::Hidden for X {}
struct Y;
impl self::f::Hidden for Y {}
impl<T: self::f::Hidden> Sealed for T {}
mod f {
pub trait Hidden {}
}
}
struct S;
impl a::Sealed for S {} //~ ERROR the trait bound
impl c::Sealed for S {} //~ ERROR the trait bound
impl e::Sealed for S {} //~ ERROR the trait bound
fn main() {}