This bug is a variation of #151284. cc @petrochenkov
I tried this code:
src/dep/lib.rs
#![feature(type_alias_impl_trait)]
struct Priv;
struct Middle;
// Priv -> Middle
pub trait Chain {
type AssocChain: GetUnreachable;
}
impl Chain for Priv {
type AssocChain = Middle;
}
// Middle -> Unreachable
pub trait GetUnreachable {
type AssocUnreachable;
}
impl GetUnreachable for Middle {
type AssocUnreachable = m::Unreachable;
}
type Opaque = impl Chain<AssocChain: GetUnreachable<AssocUnreachable = m::Unreachable>>;
#[define_opaque(Opaque)]
const _: Opaque = Priv;
// This trait is used to mention Opaque without mentioning Priv
pub trait GetOpaque<T> {}
impl GetOpaque<Opaque> for i32 {}
mod m {
pub struct Unreachable;
impl Unreachable {
#[expect(dead_code)]
pub fn exploit() {
println!("huh");
}
}
}
src/main.rs
use dep::{Chain, GetOpaque, GetUnreachable};
fn main() {
<i32 as Access<_>>::Goal::exploit();
}
trait Access<T> {
type Goal;
}
impl<T: Chain, U: GetOpaque<T>> Access<T> for U {
type Goal = <<T as Chain>::AssocChain as GetUnreachable>::AssocUnreachable;
}
Compiling the above code resulted in the following error:
error: missing optimized MIR for `dep::m::Unreachable::exploit` in the crate `dep`
|
note: missing optimized MIR for this item (was the crate `dep` compiled with `--emit=metadata`?)
--> dep\src\lib.rs:34:9
|
34 | pub fn exploit() {
| ^^^^^^^^^^^^^^^^
I assume that this error isn't supposed to happen for normal cargo usage.
The use of the only-one-trait-impl rule to access a private type is from #151115
Meta
rustc --version --verbose:
rustc 1.95.0-nightly (a293cc4af 2026-01-30)
binary: rustc
commit-hash: a293cc4af8b26701c42738381c0c6f9d2ba881e0
commit-date: 2026-01-30
host: x86_64-pc-windows-msvc
release: 1.95.0-nightly
LLVM version: 22.1.0
This bug is a variation of #151284. cc @petrochenkov
I tried this code:
src/dep/lib.rs
src/main.rs
Compiling the above code resulted in the following error:
I assume that this error isn't supposed to happen for normal cargo usage.
The use of the only-one-trait-impl rule to access a private type is from #151115
Meta
rustc --version --verbose: