Skip to content
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

Resolve anon const's parent predicates to direct parent instead of opaque's parent #125501

Merged
merged 1 commit into from
May 24, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented May 24, 2024

When an anon const is inside of an opaque, #99801 added a hack to resolve the anon const's parent predicates not to the opaque's predicates, but to the opaque's parent's predicates. This is insufficient when considering nested opaques.

This means that the predicates_of an anon const might reference duplicated lifetimes (installed by compute_bidirectional_outlives_predicates) when computing known outlives in MIR borrowck, leading to these ICEs:
Fixes #121574
Fixes #118403

Instead, we should be using the OpaqueTypeOrigin to acquire the owner item (fn/type alias/etc) of the opaque, whose predicates we're fine to mention.

I think it's a bit sketchy that we're doing this at all, tbh; I think it should be fine for the anon const to inherit the predicates of the opaque it's located inside. However, that would also mean that we need to make sure the generics_of that anon const line up in the same way.

None of this is important to solve right now; I just want to fix these ICEs so we can land #125468, which accidentally fixes these issues in a different and unrelated way.

edit: We don't need this special case anyways because we install the right parent item in generics_of anyways:

Some(parent_def_id.to_def_id())

r? @BoxyUwU

@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 24, 2024
@compiler-errors compiler-errors changed the title Resolve anon const's parent generics to opaque's parent Resolve anon const's parent predicates to opaque's origin, not direct parent May 24, 2024
@compiler-errors compiler-errors force-pushed the opaque-opaque-anon-ct branch from 0c46d8c to de517b7 Compare May 24, 2024 17:16
@BoxyUwU
Copy link
Member

BoxyUwU commented May 24, 2024

@bors r+

@bors
Copy link
Contributor

bors commented May 24, 2024

📌 Commit de517b7 has been approved by BoxyUwU

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 24, 2024
@BoxyUwU BoxyUwU changed the title Resolve anon const's parent predicates to opaque's origin, not direct parent Resolve anon const's parent predicates to direct parent instead of opaque's parent May 24, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request May 24, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#125467 (Only suppress binop error in favor of semicolon suggestion if we're in an assignment statement)
 - rust-lang#125483 (compiler: validate.rs belongs next to what it validates)
 - rust-lang#125485 (Migrate `run-make/rustdoc-with-output-dir-option` to `rmake.rs`)
 - rust-lang#125497 (Fix some SIMD intrinsics documentation)
 - rust-lang#125501 (Resolve anon const's parent predicates to direct parent instead of opaque's parent)
 - rust-lang#125503 (rustdoc-json: Add test for keywords with `--document-private-items`)
 - rust-lang#125519 (tag more stuff with `WG-trait-system-refactor`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 104e1a4 into rust-lang:master May 24, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 24, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 24, 2024
Rollup merge of rust-lang#125501 - compiler-errors:opaque-opaque-anon-ct, r=BoxyUwU

Resolve anon const's parent predicates to direct parent instead of opaque's parent

When an anon const is inside of an opaque, rust-lang#99801 added a hack to resolve the anon const's parent predicates *not* to the opaque's predicates, but to the opaque's *parent's* predicates. This is insufficient when considering nested opaques.

This means that the `predicates_of` an anon const might reference duplicated lifetimes (installed by `compute_bidirectional_outlives_predicates`) when computing known outlives in MIR borrowck, leading to these ICEs:
Fixes rust-lang#121574
Fixes rust-lang#118403

~~Instead, we should be using the `OpaqueTypeOrigin` to acquire the owner item (fn/type alias/etc) of the opaque, whose predicates we're fine to mention.~~

~~I think it's a bit sketchy that we're doing this at all, tbh; I think it *should* be fine for the anon const to inherit the predicates of the opaque it's located inside. However, that would also mean that we need to make sure the `generics_of` that anon const line up in the same way.~~

~~None of this is important to solve right now; I just want to fix these ICEs so we can land rust-lang#125468, which accidentally fixes these issues in a different and unrelated way.~~

edit: We don't need this special case anyways because we install the right parent item in `generics_of` anyways:
https://github.com/rust-lang/rust/blob/213ad10c8f0fc275648552366275dc4e07f97462/compiler/rustc_hir_analysis/src/collect/generics_of.rs#L150

r? `@BoxyUwU`
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
4 participants