1
Fork 0

Rollup merge of #139341 - nnethercote:fix-137874, r=petrochenkov

Apply `Recovery::Forbidden` when reparsing pasted macro fragments.

Fixes #137874.

The changes to the output of `tests/ui/associated-consts/issue-93835.rs`
partly undo the changes seen when `NtTy` was removed in #133436, which
is good.

r? ``@petrochenkov``
This commit is contained in:
Stuart Cook 2025-04-05 13:18:17 +11:00 committed by GitHub
commit 66ccc4fe28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 48 additions and 33 deletions

View file

@ -676,12 +676,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
let ty =
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
let safety = self.lower_safety(*safety, hir::Safety::Unsafe);
// njn: where for this?
if define_opaque.is_some() {
self.dcx().span_err(i.span, "foreign statics cannot define opaque types");
}
(ident, hir::ForeignItemKind::Static(ty, *mutability, safety))
}
ForeignItemKind::TyAlias(box TyAlias { ident, .. }) => {

View file

@ -512,6 +512,14 @@ impl<'a> Parser<'a> {
self
}
#[inline]
fn with_recovery<T>(&mut self, recovery: Recovery, f: impl FnOnce(&mut Self) -> T) -> T {
let old = mem::replace(&mut self.recovery, recovery);
let res = f(self);
self.recovery = old;
res
}
/// Whether the parser is allowed to recover from broken code.
///
/// If this returns false, recovering broken code into valid code (especially if this recovery does lookahead)
@ -770,7 +778,14 @@ impl<'a> Parser<'a> {
&& match_mv_kind(mv_kind)
{
self.bump();
let res = f(self).expect("failed to reparse {mv_kind:?}");
// 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:?}")
});
if let token::CloseDelim(delim) = self.token.kind
&& let Delimiter::Invisible(InvisibleOrigin::MetaVar(mv_kind)) = delim
&& match_mv_kind(mv_kind)