"missing optimized MIR" due to privacy violation, via associated type equality constraint in TAIT
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This bug is a variation of https://github.com/rust-lang/rust/issues/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 https://github.com/rust-lang/rust/issues/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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the two-file reproducer in src/dep/lib.rs and src/main.rs with the reported nightly toolchain, confirming the missing optimized MIR error. Then trace the compiler handling for type_alias_impl_trait, associated type equality constraints, and privacy across the dependency boundary. Done means the reproducer compiles normally without exposing the private type or producing the missing-MIR error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100