-
-
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-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-trait-systemArea: Trait systemArea: Trait systemA-visibilityArea: Visibility / privacyArea: Visibility / privacyC-bugCategory: This is a bug.Category: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]``#[feature(type_alias_impl_trait)]`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
#![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 #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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-trait-systemArea: Trait systemArea: Trait systemA-visibilityArea: Visibility / privacyArea: Visibility / privacyC-bugCategory: This is a bug.Category: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]``#[feature(type_alias_impl_trait)]`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.