Recover from missing param list in function definitions
This commit is contained in:
parent
10143e781b
commit
ca1bcb6466
10 changed files with 65 additions and 19 deletions
|
@ -1543,6 +1543,14 @@ pub(crate) enum AmbiguousMissingKwForItemSub {
|
|||
HelpMacro,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_missing_fn_params)]
|
||||
pub(crate) struct MissingFnParams {
|
||||
#[primary_span]
|
||||
#[suggestion(code = "()", applicability = "machine-applicable", style = "short")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_missing_trait_in_trait_impl)]
|
||||
pub(crate) struct MissingTraitInTraitImpl {
|
||||
|
|
|
@ -2492,6 +2492,16 @@ impl<'a> Parser<'a> {
|
|||
pub(super) fn parse_fn_params(&mut self, req_name: ReqName) -> PResult<'a, ThinVec<Param>> {
|
||||
let mut first_param = true;
|
||||
// Parse the arguments, starting out with `self` being allowed...
|
||||
if self.token.kind != TokenKind::OpenDelim(Delimiter::Parenthesis)
|
||||
// might be typo'd trait impl, handled elsewhere
|
||||
&& !self.token.is_keyword(kw::For)
|
||||
{
|
||||
// recover from missing argument list, e.g. `fn main -> () {}`
|
||||
self.sess
|
||||
.emit_err(errors::MissingFnParams { span: self.prev_token.span.shrink_to_hi() });
|
||||
return Ok(ThinVec::new());
|
||||
}
|
||||
|
||||
let (mut params, _) = self.parse_paren_comma_seq(|p| {
|
||||
p.recover_diff_marker();
|
||||
let param = p.parse_param_general(req_name, first_param).or_else(|mut e| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue