diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-04-08 20:55:11 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-08 20:55:11 +1000 |
| commit | 24369adae727e385137e219052f0f1ae90ecdf87 (patch) | |
| tree | a2c44e9900dc43f930728829752f63fd721cd437 /compiler/rustc_parse/src | |
| parent | 056756c7c4db570f93f8586828648fe02480dcb4 (diff) | |
| parent | e177921ae9bca5d697e682551c27c5baefcfbb60 (diff) | |
| download | rust-24369adae727e385137e219052f0f1ae90ecdf87.tar.gz rust-24369adae727e385137e219052f0f1ae90ecdf87.zip | |
Rollup merge of #139464 - nnethercote:fix-139248-AND-fix-139445, r=petrochenkov
Allow for reparsing failure when reparsing a pasted metavar. Fix some metavar reparsing issues. Fixes #139248 and #139445. r? `@petrochenkov`
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 3b0861a9942..fafd1b1ae00 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -782,9 +782,16 @@ impl<'a> Parser<'a> { // Recovery is disabled when parsing macro arguments, so it must // also be disabled when reparsing pasted macro arguments, // otherwise we get inconsistent results (e.g. #137874). - let res = self.with_recovery(Recovery::Forbidden, |this| { - f(this).expect("failed to reparse {mv_kind:?}") - }); + let res = self.with_recovery(Recovery::Forbidden, |this| f(this)); + + let res = match res { + Ok(res) => res, + Err(err) => { + // This can occur in unusual error cases, e.g. #139445. + err.delay_as_bug(); + return None; + } + }; if let token::CloseDelim(delim) = self.token.kind && let Delimiter::Invisible(InvisibleOrigin::MetaVar(mv_kind)) = delim @@ -793,7 +800,12 @@ impl<'a> Parser<'a> { self.bump(); Some(res) } else { - panic!("no close delim when reparsing {mv_kind:?}"); + // This can occur when invalid syntax is passed to a decl macro. E.g. see #139248, + // where the reparse attempt of an invalid expr consumed the trailing invisible + // delimiter. + self.dcx() + .span_delayed_bug(self.token.span, "no close delim with reparsing {mv_kind:?}"); + None } } else { None |
