diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-11-01 21:40:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-01 21:40:05 +0100 |
| commit | 2b2360abb1a2daf7b9486cb8fec85356c4574427 (patch) | |
| tree | 5ab7f35d2484fca80e4fe14d14d8010e4dce0b2f /compiler/rustc_parse/src | |
| parent | b0a07595b5ca544c499775db0987a673a96dc074 (diff) | |
| parent | ca1bcb64667410c7f59ec5745e012601eea3d65f (diff) | |
| download | rust-2b2360abb1a2daf7b9486cb8fec85356c4574427.tar.gz rust-2b2360abb1a2daf7b9486cb8fec85356c4574427.zip | |
Rollup merge of #117298 - clubby789:fn-missing-params, r=petrochenkov
Recover from missing param list in function definitions Addresses the other issue mentioned in #108109
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 10 |
2 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index e5cd91a32a7..20b4292701e 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1552,6 +1552,14 @@ pub(crate) enum AmbiguousMissingKwForItemSub { } #[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 { #[primary_span] diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 55ad3f42938..f0cf6bb58ca 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2499,6 +2499,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 snapshot = p.create_snapshot_for_diagnostic(); |
