-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Bodiless match arms not being unconditionally syntactically legal is surprising and unprincipled #153134
Copy link
Copy link
Open
Labels
A-grammarArea: The grammar of RustArea: The grammar of RustA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-never_patterns`#![feature(never_patterns)]``#![feature(never_patterns)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-grammarArea: The grammar of RustArea: The grammar of RustA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-never_patterns`#![feature(never_patterns)]``#![feature(never_patterns)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
AFAICT the open RFC 3719 doesn't specify if bodiless match arms are unconditionally legal or not (A never pattern is accepted as an arm in a match expression, and that arm takes no body nor guards. doesn't tell us that esp. since that sentence talks about the semantics, not the syntax). I'm opening this discussion here instead of over there because this concerns rustc's current behavior I'm strongly disagreeing with and which I consider to be a blocker for
never_patterns(I know that bodiless arms in general are contested & might not make it into the final version of the RFC).Currently rustc only syntactically accepts a bodiless match arm (i.e., one that "doesn't end in
=> $expr") under featurenever_patternsif}instead of e.g.,,) orif).I find this partly rule partly heuristic incredibly complex and unprincipled. I would just make all bodiless match syntactically legal. I know that we currently have a nice parser diagnostic + recovery for
match $expr { $pat, $pat, … … }→match $expr { $pat | $pat | … … }(i.e., helping users who confused,with|). That would indeed no longer be possible. Still, we can provide a similar structured suggestion in a later, semantic analysis pass.Concretely, it means we currently syntactically accept
match(){ x }, rejectmatch(){ x, }, acceptmatch(){ x if(), }, rejectmatch(){ X(), Y() => {} }, acceptmatch(){ X!(), Y!() => {} }.