Skip to content

Pattern reform. #3271

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
bblum opened this issue Aug 24, 2012 · 3 comments
Closed

Pattern reform. #3271

bblum opened this issue Aug 24, 2012 · 3 comments
Labels
A-codegen Area: Code generation A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system
Milestone

Comments

@bblum
Copy link
Contributor

bblum commented Aug 24, 2012

This is a meta-bug for the way pattern-matching is being overhauled.

The old pattern-matching rules are:

  • 'let' matches by-copy or by-move and must take irrefutable patterns.
  • 'match' matches by-implicit-reference.

This has several drawbacks. One, the implicit-ref thing is a big pain in our semantics, causes lots of "illegal borrow unless pure" errors to confuse newbies, and once implicit-ref argument modes go away, it will be the last thing of its kind. Two, moving out of multi-branch enums is impossible. I'm sure there are more.

New rules should be:

  • both 'let' and 'match' match by-copy or by-move (which one is inferred) by default.
  • moving out of enums (any patterns, really) is allowed if the matched-on expression is an rvalue or a last-use.
  • moving out of certain patterns (I think just '@') should never be allowed.
  • 'let' patterns must be irrefutable.
  • if you're not moving out (deconstructing), you can use 'ref' in bindings to create an explicit region pointer.

As a transitionary step, we are adding 'move' and 'copy' keywords that are to be used the same way as 'ref' in patterns. Once match's bind-by-implicit-ref goes away, 'copy' can become the default. Once there's a way to infer which of 'move' or 'copy' is meant, 'move' can go away too.

Here are some bugs:
#3224 - Patterning on ~ pointers. Moving out should be sometimes allowed.
#3024 - Patterning on @ pointers. Moving out should never be allowed.
#3235, #3256 - 'ref' working properly
#3097, moves into patterns always copy

@bblum
Copy link
Contributor Author

bblum commented Aug 24, 2012

Possible long-term enhancement: #2956 - allow irrefutable disjunctive patterns in let bindings

@catamorphism
Copy link
Contributor

Bumping to 0.6 because #3235 isn't done.

@pcwalton
Copy link
Contributor

Closing in favor of #3235, please reopen if there is objection.

jaisnan pushed a commit to jaisnan/rust-dev that referenced this issue Jul 29, 2024
Related changes:
- rust-lang#125910: Introduces a new
constant propagation pass which broke Kani coverage tests. For now,
disable this pass if coverage is enabled.
  - rust-lang#126410: Rename ConstOperands

Resolves rust-lang#3260
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-codegen Area: Code generation A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants