Add 2 more test cases from 151284 and 151479

This commit is contained in:
Vadim Petrochenkov 2026-01-29 16:44:05 +03:00
parent 7b5a4d8653
commit 7c9d149936
6 changed files with 160 additions and 0 deletions

View file

@ -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<AssocPriv = Priv>;
}
// 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<T: PubTr>();
}
pub fn call_handler<T: PubTrHandler>() {
T::handle::<Dummy>();
}
struct Priv;
pub trait GetUnreachable {
type Assoc;
}
mod m {
pub struct Unreachable;
impl Unreachable {
#[expect(dead_code)]
pub fn generic<T>() {}
}
impl crate::GetUnreachable for crate::Priv {
type Assoc = Unreachable;
}
}

View file

@ -0,0 +1,35 @@
struct Priv;
pub trait Super {
type AssocSuper: GetUnreachable;
}
#[expect(private_bounds)]
pub trait Sub: Super<AssocSuper = Priv> {}
// 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<T: Sub>();
}
pub fn call_handler<T: SubHandler>() {
<T as SubHandler>::handle::<Dummy>();
}
pub trait GetUnreachable {
type Assoc;
}
mod m {
pub struct Unreachable;
impl Unreachable {
#[expect(dead_code)]
pub fn generic<T>() {}
}
impl crate::GetUnreachable for crate::Priv {
type Assoc = Unreachable;
}
}

View file

@ -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::<Handler>();
}
struct Handler;
impl PubTrHandler for Handler {
fn handle<T: PubTr>() {
<T as Access>::AccessAssoc::generic::<i32>();
}
}
trait Access: PubTr {
type AccessAssoc;
}
impl<T: PubTr> Access for T {
type AccessAssoc = <<T::Assoc as ToPriv>::AssocPriv as GetUnreachable>::Assoc;
}
//~? ERROR missing optimized MIR

View file

@ -0,0 +1,10 @@
error: missing optimized MIR for `dep::m::Unreachable::generic::<i32>` 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<T>() {}
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error

View file

@ -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::<Handler>();
}
struct Handler;
impl SubHandler for Handler {
fn handle<T: Sub>() {
<T as Access>::AccessAssoc::generic::<i32>();
}
}
// Without this indirection, Handler::handle notices that
// it's mentioning dep::Priv.
trait Access: Super {
type AccessAssoc;
}
impl<T: Super> Access for T {
type AccessAssoc = <<T as Super>::AssocSuper as GetUnreachable>::Assoc;
}
//~? ERROR missing optimized MIR

View file

@ -0,0 +1,10 @@
error: missing optimized MIR for `dep::m::Unreachable::generic::<i32>` 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<T>() {}
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error