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

Merged
merged 2 commits into from
May 9, 2025

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

}

impl Other for dyn Trait {}
// `dyn Trait<Assoc = ()>` is a different "nominal type" than `dyn Traiat`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// `dyn Trait<Assoc = ()>` is a different "nominal type" than `dyn Traiat`.
// `dyn Trait<Assoc = ()>` is a different "nominal type" than `dyn Trait`.

@lcnr lcnr added the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 7, 2025
@lcnr
Copy link
Contributor

lcnr commented May 7, 2025

cc @rust-lang/types this PR fixes an unintended side-effect of a larger change from #136458.

r=me after nit

@lcnr
Copy link
Contributor

lcnr commented May 8, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 8, 2025

📌 Commit 3799d84 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 8, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 8, 2025
… r=lcnr

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

Since rust-lang#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:

```rust
trait Trait {
    type Assoc where Self: Sized;
}
```

After rust-lang#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 rust-lang#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 rust-lang#136458, so I'm doing a "fix-forward" in this PR and deferring thinking about this for the future.

Fixes rust-lang#140645

r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this pull request May 8, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#140095 (Eliminate `word_and_empty` methods.)
 - rust-lang#140341 (Clarify black_box warning a bit)
 - rust-lang#140684 (Only include `dyn Trait<Assoc = ...>` associated type bounds for `Self: Sized` associated types if they are provided)
 - rust-lang#140707 (Structurally normalize in range pattern checking in HIR typeck)
 - rust-lang#140716 (Improve `-Zremap-path-scope` tests with dependency)
 - rust-lang#140800 (Make `rustdoc-tempdir-removal` run-make tests work on other platforms than linux)
 - rust-lang#140802 (Add release notes for 1.87.0)
 - rust-lang#140811 (Enable triagebot note functionality for rust-lang/rust)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a054be7 into rust-lang:master May 9, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 9, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2025
Rollup merge of rust-lang#140684 - compiler-errors:unnecessary-assoc, r=lcnr

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

Since rust-lang#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:

```rust
trait Trait {
    type Assoc where Self: Sized;
}
```

After rust-lang#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 rust-lang#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 rust-lang#136458, so I'm doing a "fix-forward" in this PR and deferring thinking about this for the future.

Fixes rust-lang#140645

r? lcnr
@pietroalbini pietroalbini added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels May 9, 2025
@pietroalbini
Copy link
Member

Accepting for beta backport (directly into the stable PR) given the vote in Zulip.

bors added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2025
[stable] Prepare the 1.87.0 release

Preparing the stable artifacts as described in the release process.

This PR also includes the following last minute backports:

* rust-lang#140810
* rust-lang#140601
* rust-lang#140684

r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2025
[stable] Prepare the 1.87.0 release

Preparing the stable artifacts as described in the release process.

This PR also includes the following last minute backports:

* rust-lang#140810
* rust-lang#140601
* rust-lang#140684

r? `@ghost`
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