Skip to content

remove feature(inline_const_pat)#138492

Merged
bors merged 4 commits intorust-lang:masterfrom
lcnr:rm-inline_const_pat
Apr 1, 2025
Merged

remove feature(inline_const_pat)#138492
bors merged 4 commits intorust-lang:masterfrom
lcnr:rm-inline_const_pat

Conversation

@lcnr
Copy link
Contributor

@lcnr lcnr commented Mar 14, 2025

Summarizing https://rust-lang.zulipchat.com/#narrow/channel/144729-t-types/topic/remove.20feature.28inline_const_pat.29.20and.20shared.20borrowck.

With rust-lang/types-team#129 we will start to borrowck items together with their typeck parent. This is necessary to correctly support opaque types, blocking the new solver and TAIT/ATPIT stabilization with the old one. This means that we cannot really support inline_const_pat as they are implemented right now:

  • we want to typeck inline consts together with their parent body to allow inference to flow both ways and to allow the const to refer to local regions of its parent.This means we also need to borrowck the inline const together with its parent as that's necessary to properly support opaque types
  • we want the inline const pattern to participate in exhaustiveness checking
  • to participate in exhaustiveness checking we need to evaluate it, which requires borrowck, which now relies on borrowck of the typeck root, which ends up checking exhaustiveness again. This is a query cycle.

There are 4 possible ways to handle this:

  • stop typechecking inline const patterns together with their parent
    • causes inline const patterns to be different than inline const exprs
    • prevents bidirectional inference, we need to either fail to compile if let const { 1 } = 1u32 or if let const { 1u32 } = 1
    • region inference for inline consts will be harder, it feels non-trivial to support inline consts referencing local regions from the parent fn
  • inline consts no longer participate in exhaustiveness checking. Treat them like pat if pat == const { .. } instead. We then only evaluate them after borrowck
    • difference between const { 1 } and const FOO: usize = 1; match x { FOO => () }. This is confusing
    • do they carry their weight if they are now just equivalent to using an if-guard
  • delay exhaustiveness checking until after borrowck
    • should be possible in theory, but is a quite involved change and may have some unexpected challenges
  • remove this feature for now

I believe we should either delay exhaustiveness checking or remove the feature entirely. As moving exhaustiveness checking to after borrow checking is quite complex I think the right course of action is to fully remove the feature for now and to add it again once/if we've got that implementation figured out.

const { .. }-expressions remain stable. These seem to have been the main motivation for rust-lang/rfcs#2920.

r? types

cc @rust-lang/types @rust-lang/lang #76001

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tidy Area: The tidy tool merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.