Skip to content

Migration for or patterns #83318

Closed
Closed
@nikomatsakis

Description

@nikomatsakis

As part of the | patterns work (tracking issue), we plan to change the meaning of the $x:pat matcher in macros within the 2021 Edition. The current plan of record is:

  • The pat2015 matcher will match legacy patterns, which exclude the | character.
  • The pat2021 matcher will match new patterns, which include the | character.
  • The pat matcher will be equivalent to pat2021 from Rust 2021 forward, and equivalent to pat2015 on older editions, since past crater runs (e.g., 1 and 2) found significant and complex breakage from just changing pat to pat2021 uniformly.

The goal of this issue is to issue a useful lint that suggests that converting $x:pat to $x:pat2015 if converting to Rust 2021 could cause breakage. We don't want to do this for all $x:pat usages, however, because the vast majority would benefit from being $x:pat2021.

Examples where lint should trigger

Here is an example of a macro that we DO want to convert (source):

#[macro_export]
macro_rules! match_any {
    ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
        match $expr {
            $(
                $( $pat => $expr_arm, )+
            )+
        }
    };
}

Here is another example (source):

/// Helper macro for declaring byte-handler functions with correlating constants.
/// This becomes handy due to a lookup table present below.
macro_rules! define_handlers {
    { $(const $static_name:ident: $name:ident |$tok:pat, $byte:pat| $code:block)* } => {
        $(
            fn $name($tok: &mut Tokenizer, $byte: u8) -> Result<Token> $code

            const $static_name: fn(&mut Tokenizer, u8) -> Result<Token> = $name;
        )*
    }
}

Metadata

Metadata

Assignees

Labels

E-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-or_patterns`#![feature(or_patterns)]`T-compilerRelevant to the compiler 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