"missing optimized MIR" due to privacy violation, via associated type equality constraint in associated type bound
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This bug was found while investigating #146470, based on the snippet in https://github.com/rust-lang/rust/pull/146470#issuecomment-3755229532. cc @petrochenkov
I tried this code:
src/dep/lib.rs
pub trait ToPriv {
type AssocPriv;
}
pub trait PubTr {
#[expect(private_bounds)]
type Assoc: ToPriv<AssocPriv = Priv>;
}
struct Dummy;
struct DummyToPriv;
impl PubTr for Dummy {
type Assoc = DummyToPriv;
}
impl ToPriv for DummyToPriv {
type AssocPriv = Priv;
}
pub fn get_dummy() -> impl PubTr {
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;
}
}
src/main.rs
use dep::{GetUnreachable, PubTr, ToPriv, get_dummy};
fn main() {
wut(get_dummy());
}
fn wut<T: PubTr>(_: T) {
<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;
}
Compiling the above code resulted in the following error:
error: missing optimized MIR for `dep::m::Unreachable::generic::<i32>` 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 generic<T>() {}
| ^^^^^^^^^^^^^^^^^^^
error: could not compile `foo` (bin "foo") due to 1 previous error
I assume that this error isn't supposed to happen for normal cargo usage.
Meta
rustc --version --verbose:
rustc 1.94.0-nightly (31cd367b9 2026-01-08)
binary: rustc
commit-hash: 31cd367b9ca1ce359268e7adf4ea540408c0ad85
commit-date: 2026-01-08
host: x86_64-pc-windows-msvc
release: 1.94.0-nightly
LLVM version: 21.1.8
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
Reproduce the issue with the examples in src/dep/lib.rs and src/main.rs using the reported nightly toolchain. Start by tracing the associated-type equality and privacy handling that leads to the cross-crate call. Done means normal Cargo compilation no longer reports missing optimized MIR for dep:Ⓜ️:Unreachable::generic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100