1
Fork 0

Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errors

never_patterns: Parse match arms with no body

Never patterns are meant to signal unreachable cases, and thus don't take bodies:
```rust
let ptr: *const Option<!> = ...;
match *ptr {
    None => { foo(); }
    Some(!),
}
```
This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser).

~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit

r? `@compiler-errors`
This commit is contained in:
bors 2023-12-08 17:08:52 +00:00
commit 2b399b5275
47 changed files with 777 additions and 241 deletions

View file

@ -1000,8 +1000,10 @@ impl EarlyLintPass for UnusedDocComment {
}
fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {
let arm_span = arm.pat.span.with_hi(arm.body.span.hi());
warn_if_doc(cx, arm_span, "match arms", &arm.attrs);
if let Some(body) = &arm.body {
let arm_span = arm.pat.span.with_hi(body.span.hi());
warn_if_doc(cx, arm_span, "match arms", &arm.attrs);
}
}
fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &ast::Pat) {

View file

@ -1113,15 +1113,17 @@ impl EarlyLintPass for UnusedParens {
}
ExprKind::Match(ref _expr, ref arm) => {
for a in arm {
self.check_unused_delims_expr(
cx,
&a.body,
UnusedDelimsCtx::MatchArmExpr,
false,
None,
None,
true,
);
if let Some(body) = &a.body {
self.check_unused_delims_expr(
cx,
body,
UnusedDelimsCtx::MatchArmExpr,
false,
None,
None,
true,
);
}
}
}
_ => {}