diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-21 17:39:49 +0000 |
|---|---|---|
| committer | León Orell Valerian Liehr <me@fmease.dev> | 2025-08-22 21:45:28 +0200 |
| commit | 6caa586f572429fd08a5df7283a97666d898d043 (patch) | |
| tree | 2b926be382956e9f894edb18eb0177ddc311380c /compiler/rustc_parse | |
| parent | 831e291d3be4cacc4fe178424c4d6baa264d8b5a (diff) | |
| download | rust-6caa586f572429fd08a5df7283a97666d898d043.tar.gz rust-6caa586f572429fd08a5df7283a97666d898d043.zip | |
Recover param: Ty = EXPR
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 899a43955ab..94f381ee051 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -137,14 +137,37 @@ impl<'a> Parser<'a> { /// The difference from `parse_ty` is that this version allows `...` /// (`CVarArgs`) at the top level of the type. pub(super) fn parse_ty_for_param(&mut self) -> PResult<'a, Box<Ty>> { - self.parse_ty_common( + let ty = self.parse_ty_common( AllowPlus::Yes, AllowCVariadic::Yes, RecoverQPath::Yes, RecoverReturnSign::Yes, None, RecoverQuestionMark::Yes, - ) + )?; + + // Recover a trailing `= EXPR` if present. + if self.may_recover() + && self.check_noexpect(&token::Eq) + && self.look_ahead(1, |tok| tok.can_begin_expr()) + { + let snapshot = self.create_snapshot_for_diagnostic(); + self.bump(); + let eq_span = self.prev_token.span; + match self.parse_expr() { + Ok(e) => { + self.dcx() + .struct_span_err(eq_span.to(e.span), "parameter defaults are not supported") + .emit(); + } + Err(diag) => { + diag.cancel(); + self.restore_snapshot(snapshot); + } + } + } + + Ok(ty) } /// Parses a type in restricted contexts where `+` is not permitted. |
