diff options
| author | bors <bors@rust-lang.org> | 2023-11-01 22:37:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-01 22:37:24 +0000 |
| commit | 722b3eeb72b6bca6c38bbcbda57179f073f23431 (patch) | |
| tree | 61b1842714ca01b32a7b51d531140980bbd10433 /compiler/rustc_parse/src | |
| parent | 75b064d26970ca8e7a487072f51835ebb057d575 (diff) | |
| parent | effc27dea4c5b2710bf8e49b8c4cbb641ee05e90 (diff) | |
| download | rust-722b3eeb72b6bca6c38bbcbda57179f073f23431.tar.gz rust-722b3eeb72b6bca6c38bbcbda57179f073f23431.zip | |
Auto merge of #117498 - matthiaskrgr:rollup-z7mg4ck, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #117298 (Recover from missing param list in function definitions) - #117373 (Avoid the path trimming ICE lint in error reporting) - #117441 (Do not assert in op_to_const.) - #117488 (Update minifier-rs version to 0.3.0) r? `@ghost` `@rustbot` modify labels: rollup
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(); |
