2

Implement minimal, internal-only pattern types in the type system by oli-obk · P...

 4 weeks ago
source link: https://github.com/rust-lang/rust/pull/120131
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Conversation

Contributor

rebase of #107606

You can create pattern types with std::pat::pattern_type!(ty is pat). The feature is incomplete and will panic on you if you use any pattern other than integral range patterns. The only way to create or deconstruct a pattern type is via transmute.

This PR's implementation differs from the MCP's text. Specifically

This means you could implement different traits for different pattern types with the same base type. Thus, we just forbid implementing any traits for pattern types.

is violated in this PR. The reason is that we do need impls after all in order to make them usable as fields. constants of type std::time::Nanoseconds struct are used in patterns, so the type must be structural-eq, which it only can be if you derive several traits on it. It doesn't need to be structural-eq recursively, so we can just manually implement the relevant traits on the pattern type and use the pattern type as a private field.

Waiting on:

  • move all unrelated commits into their own PRs.
  • fix niche computation (see 2db07f9)
  • add lots more tests
  • T-types MCP Pattern types types-team#126 to finish
  • some commit cleanup
  • full self-review
  • remove 61bd325, it's not necessary anymore I think.
  • make sure we never accidentally leak pattern types to user code (add stability checks or feature gate checks and appopriate tests) we don't even do this for the new float primitives
  • get approval that the scope expansion to trait impls is ok

r? @BoxyUwU

yoshuawuyts, spastorino, Miksel12, and jdahlstrom reacted with hooray emojislanterns, RossSmyth, clubby789, y21, Nadrieril, tjallingt, juntyr, joboet, Kobzol, glou-nes, and 11 more reacted with heart emojiPatchMixolydic reacted with eyes emoji

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK