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:
commit
2b399b5275
47 changed files with 777 additions and 241 deletions
|
@ -505,7 +505,7 @@ impl<'a> ExtCtxt<'a> {
|
|||
attrs: AttrVec::new(),
|
||||
pat,
|
||||
guard: None,
|
||||
body: expr,
|
||||
body: Some(expr),
|
||||
span,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
is_placeholder: false,
|
||||
|
|
|
@ -304,6 +304,8 @@ pub(crate) struct IncompleteParse<'a> {
|
|||
pub label_span: Span,
|
||||
pub macro_path: &'a ast::Path,
|
||||
pub kind_name: &'a str,
|
||||
#[note(expand_macro_expands_to_match_arm)]
|
||||
pub expands_to_match_arm: Option<()>,
|
||||
|
||||
#[suggestion(
|
||||
expand_suggestion_add_semi,
|
||||
|
|
|
@ -955,12 +955,15 @@ pub fn ensure_complete_parse<'a>(
|
|||
_ => None,
|
||||
};
|
||||
|
||||
let expands_to_match_arm = kind_name == "pattern" && parser.token == token::FatArrow;
|
||||
|
||||
parser.sess.emit_err(IncompleteParse {
|
||||
span: def_site_span,
|
||||
token,
|
||||
label_span: span,
|
||||
macro_path,
|
||||
kind_name,
|
||||
expands_to_match_arm: expands_to_match_arm.then_some(()),
|
||||
add_semicolon,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ pub fn placeholder(
|
|||
}]),
|
||||
AstFragmentKind::Arms => AstFragment::Arms(smallvec![ast::Arm {
|
||||
attrs: Default::default(),
|
||||
body: expr_placeholder(),
|
||||
body: Some(expr_placeholder()),
|
||||
guard: None,
|
||||
id,
|
||||
pat: pat(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue