rust-lang / types-team

Home of the "types team", affiliated with the compiler and lang teams.
https://rust-lang.github.io/types-team/
Apache License 2.0
94 stars 19 forks source link

Pattern types #126

Closed oli-obk closed 7 months ago

oli-obk commented 7 months ago

Proposal

I would like to add minimal pattern types (TyKind::Pat(Ty<'tcx>, Pat<'tcx>) for some definition of Pat<'tcx>). I solely want to add integer range patterns and replace the existing rustc_scalar_layout_start/end attributes with them.

A pattern type is a distinct type from its base type. There is no subtyping relation between pattern types themselves or their base type.

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.

Creating pattern types will only possible via transmute from the base type. In the future this may become possible via pattern matching, but that needs some care in order to not affect stable code.

Converting pattern types to their base type will only be possible via transmute. In the future this will become possible safely via as casts.

Going beyond this simple new type variant requires an additional MCP. Any additional attempts at adding complexity to this feature may be halted by just referring to this MCP's text.

Mentors or Reviewers

If you have a reviewer or mentor in mind for this work, mention then here. You can put your own name here if you are planning to mentor the work.

Process

The main points of the Major Change Process are as follows:

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

rustbot commented 7 months ago

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

Concerns or objections to the proposal should be discussed on Zulip and formally registered here by adding a comment with the following syntax:

 @rustbot concern reason-for-concern 
 <description of the concern> 

Concerns can be lifted with:

 @rustbot resolve reason-for-concern 

See documentation at https://forge.rust-lang.org

cc @rust-lang/types

BoxyUwU commented 7 months ago

@rustbot second on basically the following conditions:

If we run into additional scope required in order to remove the rustc_* attrs this should also come with an understanding that it might feel like "too much" and scrap this idea for now.

I can probably review this