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

Deny capturing late-bound non-lifetime param in anon const #108553

Merged

Conversation

compiler-errors
Copy link
Member

Introduce a new AnonConstBoundary so we can detect when we capture a late-bound non-lifetime param with non_lifetime_binders enabled.

In the future, we could technically do something like introduce an early-bound parameter on the anon const, and stick the late-bound param in its substs (kinda like how we turn late-bound lifetimes in opaques into early-bound ones). But for now, just deny it so we don't ICE.

Fixes #108191

@rustbot
Copy link
Collaborator

rustbot commented Feb 28, 2023

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@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 Feb 28, 2023
@petrochenkov
Copy link
Contributor

petrochenkov commented Feb 28, 2023

I strongly suspect that this is better done in rustc_resolve, which should already have an appropriate "barrier" LifetimeRibKind for this.
cc @cjgillot

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 28, 2023
@cjgillot
Copy link
Contributor

rustc_resolve doesn't track whether the const param was introduced by proper generics or by a for<> binding, it just records a DefKind::ConstParam. Additionally, the AnonConst check in rustc_resolve is very strict: it bans any non-'static lifetime in AnonConst.

Here, we should only ban late-bound types and const params. That's resolve_bound_vars's point to give the proper meaning to bound variables, so I agree with @compiler-errors putting that check here.

@compiler-errors
Copy link
Member Author

I could move the logic to rustc_resolve by adding a new (non-lifetime) ribs -- 4b05b4a -- not sure if it's better to leave it where this PR is doing it, though.

@compiler-errors
Copy link
Member Author

compiler-errors commented Mar 1, 2023

@rustbot ready

Advice would be appreciated whether the current strategy in the PR, or something like 4b05b4ae7e2721cd6d265e8e2b858c745f97f957, is preferable.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 1, 2023
@petrochenkov
Copy link
Contributor

Ok, let's land this as is for now.
@bors r+

@bors
Copy link
Contributor

bors commented Mar 3, 2023

📌 Commit cbf4d4e has been approved by petrochenkov

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Mar 3, 2023

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@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 Mar 3, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 3, 2023
…in-anon-ct, r=petrochenkov

Deny capturing late-bound non-lifetime param in anon const

Introduce a new AnonConstBoundary so we can detect when we capture a late-bound non-lifetime param with `non_lifetime_binders` enabled.

In the future, we could technically do something like introduce an early-bound parameter on the anon const, and stick the late-bound param in its substs (kinda like how we turn late-bound lifetimes in opaques into early-bound ones). But for now, just deny it so we don't ICE.

Fixes rust-lang#108191
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#107981 (new solver: implement canonicalization and region constraints)
 - rust-lang#108553 (Deny capturing late-bound non-lifetime param in anon const)
 - rust-lang#108599 (Remove legacy PM leftovers)
 - rust-lang#108667 (Fix another ICE in `point_at_expr_source_of_inferred_type`)
 - rust-lang#108674 (Clippy Fix array-size-threshold config deserialization error)
 - rust-lang#108685 (Match unmatched backticks in compiler/)
 - rust-lang#108694 (Match unmatched backticks in compiler/ comments)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 44e794f into rust-lang:master Mar 3, 2023
@rustbot rustbot added this to the 1.69.0 milestone Mar 3, 2023
@compiler-errors compiler-errors added the F-non_lifetime_binders `#![feature(non_lifetime_binders)]` label Mar 10, 2023
@compiler-errors compiler-errors deleted the non-lt-late-bound-in-anon-ct branch August 11, 2023 20:11
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 11, 2023
…s, r=cjgillot

Correctly deny late-bound lifetimes from parent in anon consts and TAITs

Reuse the `AnonConstBoundary` scope (introduced in rust-lang#108553, renamed in this PR to `LateBoundary`) to deny late-bound vars of *all* kinds (ty/const/lifetime) in anon consts and TAITs.

Side-note, but I would like to consolidate this with the error reporting for RPITs (E0657):
https://github.com/rust-lang/rust/blob/c4f25777a08cd64b710e8a9a6159e67cbb35e6f5/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs#L733-L754 but the semantics about what we're allowed to capture there are slightly different, so I'm leaving that untouched.

Fixes rust-lang#115474
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 19, 2023
…s, r=cjgillot

Correctly deny late-bound lifetimes from parent in anon consts and TAITs

Reuse the `AnonConstBoundary` scope (introduced in rust-lang#108553, renamed in this PR to `LateBoundary`) to deny late-bound vars of *all* kinds (ty/const/lifetime) in anon consts and TAITs.

Side-note, but I would like to consolidate this with the error reporting for RPITs (E0657):
https://github.com/rust-lang/rust/blob/c4f25777a08cd64b710e8a9a6159e67cbb35e6f5/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs#L733-L754 but the semantics about what we're allowed to capture there are slightly different, so I'm leaving that untouched.

Fixes rust-lang#115474
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 20, 2023
…s, r=cjgillot

Correctly deny late-bound lifetimes from parent in anon consts and TAITs

Reuse the `AnonConstBoundary` scope (introduced in rust-lang#108553, renamed in this PR to `LateBoundary`) to deny late-bound vars of *all* kinds (ty/const/lifetime) in anon consts and TAITs.

Side-note, but I would like to consolidate this with the error reporting for RPITs (E0657):
https://github.com/rust-lang/rust/blob/c4f25777a08cd64b710e8a9a6159e67cbb35e6f5/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs#L733-L754 but the semantics about what we're allowed to capture there are slightly different, so I'm leaving that untouched.

Fixes rust-lang#115474
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-non_lifetime_binders `#![feature(non_lifetime_binders)]` 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: WellFormed(T) has escaping bound vars, so it cannot be wrapped in a dummy binder.
5 participants