Skip to content

Tracking issue for bindings in sub-patterns after @s (feature(bindings_after_at)) #65490

Closed
@pnkfelix

Description

@pnkfelix

This is the tracking issue for #![feature(bindings_after_at)], which allows patterns of form binding @ pat to have bindings in pat, for example ref x @ Some(y).

Implementation history

Old description

Pre-1.0 Rust used to support writing code like:

match x {
    y @ z => { ... }
}

match a {
    b @ Some(c) => { ... }
}

PR #16053 disabled the ability to write such code. More precisely, it disabled the ability to introduce any kind of binding in subpattern P in the context of any binding-pattern ident @ P

The reason we did this was because it was too hard to handle them soundly in the AST-borrowck.

However, now that we have migrated 100% to NLL and thus MIR-borrowck, we should be able to soundly re-enable this feature, without too much effort (I hope).

  • Back when the feature was removed, we made an explicit note that the long term intention was to reenable it.
  • And this is a useful coding pattern at times. (The whole reason I went looking for this issue, and then decided to file it after discovering it did not seem to exist, was because I wanted to write code that required this feature, namely a pattern like: ty::Ref(_, adt_ty @ ty::TyS { kind: ty::Adt(adt_def, _), .. }, _))

Note that any attempt to re-enable the feature should do a careful survey of the various cases that can arise (copying, moving, mixing ref and non-ref, match ergonomics, ...)

Also, any attempt to re-enable the feature should also attempt to re-add all the tests that were removed with PR #16053

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-NLLArea: Non-lexical lifetimes (NLL)A-codegenArea: Code generationA-patternsRelating to patterns and pattern matchingB-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-bindings_after_at`#![feature(bindings_after_at)]`T-langRelevant to the language team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions