Skip to content

Coherence with object types with overlapping supertrait projections is incomplete #133361

@compiler-errors

Description

@compiler-errors

I tried this code:

trait Sup<T> { type Assoc; } impl<T> Sup<T> for () { type Assoc = T; } impl<T, U> Dyn<T, U> for () {} trait Dyn<A, B>: Sup<A, Assoc = A> + Sup<B, Assoc = B> {} trait Trait { type Assoc; } impl Trait for dyn Dyn<(), ()> { type Assoc = &'static str; } impl<A, B> Trait for dyn Dyn<A, B> { type Assoc = usize; } fn call<A, B>(x: usize) -> <dyn Dyn<A, B> as Trait>::Assoc { x } fn main() { let x: &'static str = call::<(), ()>(0xDEADBEEF); println!("{x}"); }

I expected to see this happen: It does not work.

Instead, this happened: Segfault

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (a47555110 2024-11-22) 

Metadata

Metadata

Labels

A-coherenceArea: CoherenceA-dyn-traitArea: trait objects, vtable layoutC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Completed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions