-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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 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
Reactions are currently unavailable
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.