-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-trait-systemArea: Trait systemArea: Trait systemA-visibilityArea: Visibility / privacyArea: Visibility / privacyC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
This bug was found while investigating #146470, based on the snippet in #146470 (comment). 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
MolotovCherry and ArhanChaudhary
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-trait-systemArea: Trait systemArea: Trait systemA-visibilityArea: Visibility / privacyArea: Visibility / privacyC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.