Skip to content

Require coherence of supertrait associated item bounds for dyn-compability#158915

Open
theemathas wants to merge 2 commits into
rust-lang:mainfrom
theemathas:coherent-dyn-compat
Open

Require coherence of supertrait associated item bounds for dyn-compability#158915
theemathas wants to merge 2 commits into
rust-lang:mainfrom
theemathas:coherent-dyn-compat

Conversation

@theemathas

Copy link
Copy Markdown
Contributor

This PR is an alternative to #157710. However, unlike that PR, this PR does not address #150936.

Fixes #154662

In a dyn type, if multiple bounds are specified via supertraits for the same associated item, then we previously accepted them if the relevant trait's generics are different, even if the bounds conflict.

This was unsound, since those generics could end up being instantiated with identical concrete types, causing the dyn type to have two different "values" for the same bound.

Thus, if a trait has multiple supertrait bounds for the same associated item, we check whether those bounds are coherent, similarly to how we check for overlap between impulse (i.e., we check if the generics could be instantiated to be the same while the "values" of the bounds are different). If the bounds are incoherent, then we consider the trait to be dyn-incompatible.

r? @fmease

…ics.

See rust-lang#154662

These tests will be fixed in a subsequent commit.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jul 7, 2026
@theemathas

Copy link
Copy Markdown
Contributor Author

I'm unsure of what to do with the now-failing tests.

I'm also rather unsure of my code in general. Please be careful with the review to make sure I didn't do anything stupid. Thank you.

@theemathas theemathas added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. needs-crater This change needs a crater run to check for possible breakage in the ecosystem. labels Jul 7, 2026
…ility

Fixes rust-lang#154662

In a `dyn` type, if multiple bounds are specified via supertraits for
the same associated item, then we previously accepted them if
the relevant trait's generics are different,
even if the bounds conflict.

This was unsound, since those generics could end up being instantiated
with identical concrete types, causing the `dyn` type to have
two different "values" for the same bound.

Thus, if a trait has multiple supertrait bounds for the same
associated item, we check whether those bounds are coherent,
similarly to how we check for overlap between impulse (i.e., we check
if the generics could be instantiated to be the same while the "values"
of the bounds are different). If the bounds are incoherent, then we
consider the trait to be dyn-incompatible.
@theemathas theemathas force-pushed the coherent-dyn-compat branch from 4d67fa1 to 256670e Compare July 7, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-crater This change needs a crater run to check for possible breakage in the ecosystem. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conflicting supertrait associated type in dyn causes unsoundness and ICE

3 participants