Skip to content

Only include dyn Trait<Assoc = ...> associated type bounds for Self: Sized associated types if they are provided#140684

Merged
bors merged 2 commits intorust-lang:masterfrom
compiler-errors:unnecessary-assoc
May 9, 2025
Merged

Only include dyn Trait<Assoc = ...> associated type bounds for Self: Sized associated types if they are provided#140684
bors merged 2 commits intorust-lang:masterfrom
compiler-errors:unnecessary-assoc

Conversation

@compiler-errors
Copy link
Copy Markdown
Contributor

@compiler-errors compiler-errors commented May 5, 2025

Since #136458, we began filtering out associated types with Self: Sized bounds when constructing the list of associated type bounds to put into our dyn Trait types. For example, given:

trait Trait {
    type Assoc where Self: Sized;
}

After #136458, even if a user writes dyn Trait<Assoc = ()>, the lowered ty would have an empty projection list, and thus be equivalent to dyn Trait. However, this has the side effect of no longer constraining any types in the RHS of Assoc = ..., not implying any WF implied bounds, and not requiring that they hold when unsizing.

After this PR, we include these bounds, but (still) do not require that they are provided. If the are not provided, they are skipped from the projections list.

This results in dyn Trait types that have differing numbers of projection bounds. This will lead to re-introducing type mismatches e.g. between dyn Trait and dyn Trait<Assoc = ()>. However, this is expected and doesn't suffer from any of the deduplication unsoundness from before #136458.

We may want to begin to ignore thse bounds in the future by bumping unused_associated_type_bounds to an FCW. I don't want to tangle that up into the fix that was originally intended in #136458, so I'm doing a "fix-forward" in this PR and deferring thinking about this for the future.

Fixes #140645

r? lcnr

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Unused" associated type bounds in dyn no longer parameterize the type

5 participants