"missing optimized MIR" due to privacy violation, via associated type equality constraint in supertrait
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 #151284. cc @petrochenkov
I tried this code:
src/dep/lib.rs
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;
}
}
src/main.rs
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;
}
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:30:9
|
30 | 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.95.0-nightly (eda76d9d1 2026-01-21)
binary: rustc
commit-hash: eda76d9d1d133effbf7facb28168fd78d75fd434
commit-date: 2026-01-21
host: aarch64-apple-darwin
release: 1.95.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 two-crate example in src/dep/lib.rs and src/main.rs with the reported rustc version, starting from the associated type equality and privacy interaction. Trace how the compiler handles the resulting generic call and missing optimized MIR. Done means the example builds through normal Cargo usage without the missing optimized MIR error, with a regression test for the case.
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
- 35/100