Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

@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

@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. labels May 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 5, 2025

HIR ty lowering was modified

cc @fmease

@@ -204,9 +204,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
.filter(|item| item.is_type())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not rly needed_associated_types anymore, is it. It's ordered_associated_types or whatever. Pls rename the variable and add a comment explaining the approach of

  • collect all associated types in a stable order by walking over the dyn trait with identity substitutions
  • then use that to order user annotations
  • then with elaborated super bounds, not replying user annotations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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