From 7c9d14993643fff92b8cf1351422b76e468d6a27 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 29 Jan 2026 16:44:05 +0300 Subject: [PATCH] Add 2 more test cases from 151284 and 151479 --- .../missing-mir-priv-bounds-extern-2.rs | 46 +++++++++++++++++++ .../missing-mir-priv-bounds-extern-3.rs | 35 ++++++++++++++ tests/ui/privacy/missing-mir-priv-bounds-2.rs | 29 ++++++++++++ .../privacy/missing-mir-priv-bounds-2.stderr | 10 ++++ tests/ui/privacy/missing-mir-priv-bounds-3.rs | 30 ++++++++++++ .../privacy/missing-mir-priv-bounds-3.stderr | 10 ++++ 6 files changed, 160 insertions(+) create mode 100644 tests/ui/privacy/auxiliary/missing-mir-priv-bounds-extern-2.rs create mode 100644 tests/ui/privacy/auxiliary/missing-mir-priv-bounds-extern-3.rs create mode 100644 tests/ui/privacy/missing-mir-priv-bounds-2.rs create mode 100644 tests/ui/privacy/missing-mir-priv-bounds-2.stderr create mode 100644 tests/ui/privacy/missing-mir-priv-bounds-3.rs create mode 100644 tests/ui/privacy/missing-mir-priv-bounds-3.stderr diff --git a/tests/ui/privacy/auxiliary/missing-mir-priv-bounds-extern-2.rs b/tests/ui/privacy/auxiliary/missing-mir-priv-bounds-extern-2.rs new file mode 100644 index 000000000000..38e3cdded5f2 --- /dev/null +++ b/tests/ui/privacy/auxiliary/missing-mir-priv-bounds-extern-2.rs @@ -0,0 +1,46 @@ +// Doesn't involve `impl Trait` unlike missing-mir-priv-bounds-extern.rs + +pub trait ToPriv { + type AssocPriv; +} + +pub trait PubTr { + #[expect(private_bounds)] + type Assoc: ToPriv; +} + +// Dummy and DummyToPriv are only used in call_handler +struct Dummy; +struct DummyToPriv; +impl PubTr for Dummy { + type Assoc = DummyToPriv; +} +impl ToPriv for DummyToPriv { + type AssocPriv = Priv; +} + +pub trait PubTrHandler { + fn handle(); +} +pub fn call_handler() { + T::handle::(); +} + +struct Priv; + +pub trait GetUnreachable { + type Assoc; +} + +mod m { + pub struct Unreachable; + + impl Unreachable { + #[expect(dead_code)] + pub fn generic() {} + } + + impl crate::GetUnreachable for crate::Priv { + type Assoc = Unreachable; + } +} diff --git a/tests/ui/privacy/auxiliary/missing-mir-priv-bounds-extern-3.rs b/tests/ui/privacy/auxiliary/missing-mir-priv-bounds-extern-3.rs new file mode 100644 index 000000000000..807abe2c4ad8 --- /dev/null +++ b/tests/ui/privacy/auxiliary/missing-mir-priv-bounds-extern-3.rs @@ -0,0 +1,35 @@ +struct Priv; + +pub trait Super { + type AssocSuper: GetUnreachable; +} +#[expect(private_bounds)] +pub trait Sub: Super {} + +// This Dummy type is only used in call_handler +struct Dummy; +impl Super for Dummy { + type AssocSuper = Priv; +} +impl Sub for Dummy {} + +pub trait SubHandler { + fn handle(); +} +pub fn call_handler() { + ::handle::(); +} + +pub trait GetUnreachable { + type Assoc; +} +mod m { + pub struct Unreachable; + impl Unreachable { + #[expect(dead_code)] + pub fn generic() {} + } + impl crate::GetUnreachable for crate::Priv { + type Assoc = Unreachable; + } +} diff --git a/tests/ui/privacy/missing-mir-priv-bounds-2.rs b/tests/ui/privacy/missing-mir-priv-bounds-2.rs new file mode 100644 index 000000000000..7676fdb4af4b --- /dev/null +++ b/tests/ui/privacy/missing-mir-priv-bounds-2.rs @@ -0,0 +1,29 @@ +// Test case from issue #151284. +// A private associated type bound allows to leak another private type and result in missing MIR. + +//@ build-fail +//@ aux-crate:dep=missing-mir-priv-bounds-extern-2.rs + +extern crate dep; +use dep::{GetUnreachable, PubTr, PubTrHandler, ToPriv, call_handler}; + +fn main() { + call_handler::(); +} + +struct Handler; +impl PubTrHandler for Handler { + fn handle() { + ::AccessAssoc::generic::(); + } +} + +trait Access: PubTr { + type AccessAssoc; +} + +impl Access for T { + type AccessAssoc = <::AssocPriv as GetUnreachable>::Assoc; +} + +//~? ERROR missing optimized MIR diff --git a/tests/ui/privacy/missing-mir-priv-bounds-2.stderr b/tests/ui/privacy/missing-mir-priv-bounds-2.stderr new file mode 100644 index 000000000000..29a10eb1223b --- /dev/null +++ b/tests/ui/privacy/missing-mir-priv-bounds-2.stderr @@ -0,0 +1,10 @@ +error: missing optimized MIR for `dep::m::Unreachable::generic::` in the crate `missing_mir_priv_bounds_extern_2` + | +note: missing optimized MIR for this item (was the crate `missing_mir_priv_bounds_extern_2` compiled with `--emit=metadata`?) + --> $DIR/auxiliary/missing-mir-priv-bounds-extern-2.rs:40:9 + | +LL | pub fn generic() {} + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/privacy/missing-mir-priv-bounds-3.rs b/tests/ui/privacy/missing-mir-priv-bounds-3.rs new file mode 100644 index 000000000000..1d277265451e --- /dev/null +++ b/tests/ui/privacy/missing-mir-priv-bounds-3.rs @@ -0,0 +1,30 @@ +// Test case from issue #151479. +// A private associated type bound allows to leak another private type and result in missing MIR. + +//@ build-fail +//@ aux-crate:dep=missing-mir-priv-bounds-extern-3.rs + +extern crate dep; +use dep::{GetUnreachable, Sub, SubHandler, Super, call_handler}; + +fn main() { + call_handler::(); +} + +struct Handler; +impl SubHandler for Handler { + fn handle() { + ::AccessAssoc::generic::(); + } +} + +// Without this indirection, Handler::handle notices that +// it's mentioning dep::Priv. +trait Access: Super { + type AccessAssoc; +} +impl Access for T { + type AccessAssoc = <::AssocSuper as GetUnreachable>::Assoc; +} + +//~? ERROR missing optimized MIR diff --git a/tests/ui/privacy/missing-mir-priv-bounds-3.stderr b/tests/ui/privacy/missing-mir-priv-bounds-3.stderr new file mode 100644 index 000000000000..ef464de08cb9 --- /dev/null +++ b/tests/ui/privacy/missing-mir-priv-bounds-3.stderr @@ -0,0 +1,10 @@ +error: missing optimized MIR for `dep::m::Unreachable::generic::` in the crate `missing_mir_priv_bounds_extern_3` + | +note: missing optimized MIR for this item (was the crate `missing_mir_priv_bounds_extern_3` compiled with `--emit=metadata`?) + --> $DIR/auxiliary/missing-mir-priv-bounds-extern-3.rs:30:9 + | +LL | pub fn generic() {} + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error +