1
Fork 0

Remove an unchecked_error_guaranteed call.

If we abort immediately after complaining about the obsolete `impl Trait
for ..` syntax, then we avoid reaching HIR lowering. This means we can
use `TyKind::Dummy` instead of `TyKind::Err`.
This commit is contained in:
Nicholas Nethercote 2024-02-21 14:23:46 +11:00
parent bb594538fc
commit 09ca866738
2 changed files with 8 additions and 19 deletions

View file

@ -881,9 +881,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
&item.vis, &item.vis,
errors::VisibilityNotPermittedNote::TraitImpl, errors::VisibilityNotPermittedNote::TraitImpl,
); );
// njn: use Dummy here if let TyKind::Dummy = self_ty.kind {
if let TyKind::Err(_) = self_ty.kind { // Abort immediately otherwise the `TyKind::Dummy` will reach HIR lowering,
this.dcx().emit_err(errors::ObsoleteAuto { span: item.span }); // which isn't allowed. Not a problem for this obscure, obsolete syntax.
this.dcx().emit_fatal(errors::ObsoleteAuto { span: item.span });
} }
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity) if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)
{ {

View file

@ -592,22 +592,10 @@ impl<'a> Parser<'a> {
// We need to report this error after `cfg` expansion for compatibility reasons // We need to report this error after `cfg` expansion for compatibility reasons
self.bump(); // `..`, do not add it to expected tokens self.bump(); // `..`, do not add it to expected tokens
// FIXME(nnethercote): AST validation later detects this // AST validation later detects this `TyKind::Dummy` and emits an
// `TyKind::Err` and emits an errors. So why the unchecked // error. (#121072 will hopefully remove all this special handling
// ErrorGuaranteed? // of the obsolete `impl Trait for ..` and then this can go away.)
// - A `span_delayed_bug` doesn't work here, because rustfmt can Some(self.mk_ty(self.prev_token.span, TyKind::Dummy))
// hit this path but then not hit the follow-up path in the AST
// validator that issues the error, which results in ICEs.
// - `TyKind::Dummy` doesn't work, because it ends up reaching HIR
// lowering, which results in ICEs. Changing `TyKind::Dummy` to
// `TyKind::Err` during AST validation might fix that, but that's
// not possible because AST validation doesn't allow mutability.
//
// #121072 will hopefully remove all this special handling of the
// obsolete `impl Trait for ..` and then this can go away.
#[allow(deprecated)]
let guar = rustc_errors::ErrorGuaranteed::unchecked_error_guaranteed();
Some(self.mk_ty(self.prev_token.span, TyKind::Err(guar)))
} else if has_for || self.token.can_begin_type() { } else if has_for || self.token.can_begin_type() {
Some(self.parse_ty()?) Some(self.parse_ty()?)
} else { } else {