type privacy: Check constructor types in tuple struct patterns by petrochenkov · Pull Request #138458 · rust-lang/rust (original) (raw)

@traviscross
The examples in detail.

#![allow(private_interfaces, unreachable_code)]

mod m { struct Priv; pub struct TupleStruct(pub Priv); }

fn main() { // There's one type here - m::TupleStruct, it is public, no error. // There are also two values here // - _ (its type m::TupleStruct is public, no errror), // - loop {} (its types are ! and m::TupleStruct before and after coercion, both public, no error). let _: m::TupleStruct = loop {}; // OK // There's one type here - m::TupleStruct, it is public, no error. // There are also two values here // - m::TupleStruct { .. } (its type m::TupleStruct is public, no error) // - loop {} (same as above, no error). let m::TupleStruct { .. } = loop {}; // OK // There are no types here. // There are three values here // - m::TupleStruct (its type fn(Priv) -> m::TupleStruct is private due to Priv in the signature, error) // - m::TupleStruct(..) (its type m::TupleStruct is public, no error) // - loop {} (same as above, no error). let m::TupleStruct(..) = loop {}; // ERROR // There are no types here. // There are two values here // - m::TupleStruct (its type fn(Priv) -> m::TupleStruct is private due to Priv in the signature, error) // - _ (its type fn(Priv) -> m::TupleStruct is private due to Priv in the signature, error). let _ = m::TupleStruct; // ERROR }