Skip to content

Dont collect assoc ty item bounds from trait where clause for host effect predicates #143895

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 3 commits into from
Jul 17, 2025

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jul 13, 2025

For background, we uplift where Self::Assoc: Trait bounds in a trait's where clauses into item bounds on type Assoc;. This is because before we had syntactical item bounds, users would express their item bounds like so.

Let's opt out of doing this same behavior for HostEffect predicates like where Self::Assoc: [const] Trait. I left a comment in the code:

// FIXME(const_trait_impl): We *could* uplift the
// `where Self::Assoc: [const] Trait` bounds from the parent trait
// here too, but we'd need to split `const_conditions` into two
// queries (like we do for `trait_explicit_predicates_and_bounds`)
// since we need to also filter the predicates *out* of the const
// conditions or they lead to cycles in the trait solver when
// utilizing these bounds. For now, let's do nothing.

As an aside, this was an ICE that was only triggerable when building libraries and not binaries because we never were calling tcx.ensure_ok().explicit_implied_const_bounds(def_id); on associated types like we should have been. I adjusted the calls to ensure_ok to make sure this happens, so we catch bugs like this in the future more easily.

As another aside, I fixed the bound uplifting logic for always const predicates, since those act like normal clauses and have no notion of conditional constness.

r? @oli-obk @fee1-dead or anyone really

Fixes #133275

@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 Jul 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2025

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@compiler-errors compiler-errors force-pushed the trait-wc-item-bound-host-eff branch from 6eebb24 to 8daf98b Compare July 13, 2025 16:32
@@ -889,8 +889,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
tcx.ensure_ok().predicates_of(def_id);
tcx.ensure_ok().explicit_item_bounds(def_id);
tcx.ensure_ok().explicit_item_self_bounds(def_id);
tcx.ensure_ok().item_bounds(def_id);
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need to ensure these queries, since they're just computed from the explicit ones we're ensuring above.

@@ -1042,8 +1040,12 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
let has_type = match assoc_item.container {
ty::AssocItemContainer::Impl => true,
ty::AssocItemContainer::Trait => {
tcx.ensure_ok().item_bounds(def_id);
tcx.ensure_ok().item_self_bounds(def_id);
tcx.ensure_ok().explicit_item_bounds(def_id);
Copy link
Member Author

Choose a reason for hiding this comment

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

Ensuring the explicit flavor of the item bounds queries, and also making sure to ensure the const ones too.

@@ -124,6 +124,7 @@ fn remap_gat_vars_and_recurse_into_nested_projections<'tcx>(
ty::ClauseKind::Trait(tr) => tr.self_ty(),
ty::ClauseKind::Projection(proj) => proj.projection_term.self_ty(),
ty::ClauseKind::TypeOutlives(outlives) => outlives.0,
ty::ClauseKind::HostEffect(host) => host.self_ty(),
_ => return None,
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like a good candidate for an exhaustive match

@oli-obk
Copy link
Contributor

oli-obk commented Jul 14, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 14, 2025

📌 Commit 8daf98b has been approved by oli-obk

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 Jul 14, 2025
fmease added a commit to fmease/rust that referenced this pull request Jul 16, 2025
…d-host-eff, r=oli-obk

Dont collect assoc ty item bounds from trait where clause for host effect predicates

For background, we uplift `where Self::Assoc: Trait` bounds in a trait's where clauses into *item bounds* on `type Assoc;`. This is because before we *had* syntactical item bounds, users would express their item bounds like so.

Let's opt out of doing this same behavior for `HostEffect` predicates like `where Self::Assoc: [const] Trait`. I left a comment in the code:

```rust
// FIXME(const_trait_impl): We *could* uplift the
// `where Self::Assoc: [const] Trait` bounds from the parent trait
// here too, but we'd need to split `const_conditions` into two
// queries (like we do for `trait_explicit_predicates_and_bounds`)
// since we need to also filter the predicates *out* of the const
// conditions or they lead to cycles in the trait solver when
// utilizing these bounds. For now, let's do nothing.
```

As an aside, this was an ICE that was only triggerable when building libraries and not binaries because we never were calling `tcx.ensure_ok().explicit_implied_const_bounds(def_id);` on associated types like we should have been. I adjusted the calls to `ensure_ok` to make sure this happens, so we catch bugs like this in the future more easily.

As another aside, I fixed the bound uplifting logic for *always const* predicates, since those act like normal clauses and have no notion of conditional constness.

r? ``@oli-obk`` ``@fee1-dead`` or anyone really

Fixes rust-lang#133275
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 15 pull requests

Successful merges:

 - #142304 (tests: Add `RUST_BACKTRACE` and `-Cpanic` revisions to `panic-main.rs` test)
 - #143388 (Various refactors to the LTO handling code)
 - #143409 (Enable xgot feature for mips64 musl targets)
 - #143592 (UWP: link ntdll functions using raw-dylib)
 - #143595 (add `const_make_global`; err for `const_allocate` ptrs if didn't call)
 - #143678 (Added error for invalid char cast)
 - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - #143829 (Trim `BorrowedCursor` API)
 - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests)
 - #143851 (ci cleanup: rustdoc-gui-test now installs browser-ui-test)
 - #143856 (Linting public reexport of private dependencies)
 - #143895 (Dont collect assoc ty item bounds from trait where clause for host effect predicates)
 - #143922 (Improve path segment joining)
 - #143964 (Fix handling of SCRIPT_ARG in docker images)
 - #144016 (trait_sel: `MetaSized` always holds temporarily)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 15 pull requests

Successful merges:

 - #142304 (tests: Add `RUST_BACKTRACE` and `-Cpanic` revisions to `panic-main.rs` test)
 - #143388 (Various refactors to the LTO handling code)
 - #143409 (Enable xgot feature for mips64 musl targets)
 - #143592 (UWP: link ntdll functions using raw-dylib)
 - #143595 (add `const_make_global`; err for `const_allocate` ptrs if didn't call)
 - #143678 (Added error for invalid char cast)
 - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - #143829 (Trim `BorrowedCursor` API)
 - #143851 (ci cleanup: rustdoc-gui-test now installs browser-ui-test)
 - #143856 (Linting public reexport of private dependencies)
 - #143895 (Dont collect assoc ty item bounds from trait where clause for host effect predicates)
 - #143922 (Improve path segment joining)
 - #143964 (Fix handling of SCRIPT_ARG in docker images)
 - #144002 (Update poison.rs)
 - #144016 (trait_sel: `MetaSized` always holds temporarily)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7ea7435 into rust-lang:master Jul 17, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 17, 2025
rust-timer added a commit that referenced this pull request Jul 17, 2025
Rollup merge of #143895 - compiler-errors:trait-wc-item-bound-host-eff, r=oli-obk

Dont collect assoc ty item bounds from trait where clause for host effect predicates

For background, we uplift `where Self::Assoc: Trait` bounds in a trait's where clauses into *item bounds* on `type Assoc;`. This is because before we *had* syntactical item bounds, users would express their item bounds like so.

Let's opt out of doing this same behavior for `HostEffect` predicates like `where Self::Assoc: [const] Trait`. I left a comment in the code:

```rust
// FIXME(const_trait_impl): We *could* uplift the
// `where Self::Assoc: [const] Trait` bounds from the parent trait
// here too, but we'd need to split `const_conditions` into two
// queries (like we do for `trait_explicit_predicates_and_bounds`)
// since we need to also filter the predicates *out* of the const
// conditions or they lead to cycles in the trait solver when
// utilizing these bounds. For now, let's do nothing.
```

As an aside, this was an ICE that was only triggerable when building libraries and not binaries because we never were calling `tcx.ensure_ok().explicit_implied_const_bounds(def_id);` on associated types like we should have been. I adjusted the calls to `ensure_ok` to make sure this happens, so we catch bugs like this in the future more easily.

As another aside, I fixed the bound uplifting logic for *always const* predicates, since those act like normal clauses and have no notion of conditional constness.

r? ```@oli-obk``` ```@fee1-dead``` or anyone really

Fixes #133275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

ICE: converted TraitPredicate / invalid predicate filter for 'remap_gat_vars_and_recurse_into_nested_projections'
4 participants