From 41881aece2aac46b21c509dadb0b101da1f7d6bb Mon Sep 17 00:00:00 2001 From: Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> Date: Thu, 15 Jun 2023 15:40:31 +0000 Subject: [PATCH] Stop failing eagerly, and collect all opaque types even if some are erroneous. --- compiler/rustc_ty_utils/src/opaque_types.rs | 18 ++++++------------ tests/ui/type-alias-impl-trait/multi-error.rs | 1 - .../type-alias-impl-trait/multi-error.stderr | 19 +------------------ 3 files changed, 7 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index d97b74017ed..d64569db566 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -1,5 +1,4 @@ use rustc_data_structures::fx::FxHashSet; -use rustc_errors::ErrorGuaranteed; use rustc_hir::{def::DefKind, def_id::LocalDefId}; use rustc_middle::query::Providers; use rustc_middle::ty::util::{CheckRegions, NotUniqueParam}; @@ -65,10 +64,9 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { } impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { - type BreakTy = ErrorGuaranteed; - #[instrument(skip(self), ret, level = "trace")] - fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<ErrorGuaranteed> { + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<!> { + t.super_visit_with(self)?; match t.kind() { ty::Alias(ty::Opaque, alias_ty) if alias_ty.def_id.is_local() => { if !self.seen.insert(alias_ty.def_id.expect_local()) { @@ -91,24 +89,20 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { trace!(?pred); self.visit_spanned(span, pred); } - - ControlFlow::Continue(()) } Err(NotUniqueParam::NotParam(arg)) => { - let err = self.tcx.sess.emit_err(NotParam { + self.tcx.sess.emit_err(NotParam { arg, span: self.span(), opaque_span: self.tcx.def_span(alias_ty.def_id), }); - ControlFlow::Break(err) } Err(NotUniqueParam::DuplicateParam(arg)) => { - let err = self.tcx.sess.emit_err(DuplicateArg { + self.tcx.sess.emit_err(DuplicateArg { arg, span: self.span(), opaque_span: self.tcx.def_span(alias_ty.def_id), }); - ControlFlow::Break(err) } } } @@ -157,10 +151,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { } } } - t.super_visit_with(self) } - _ => t.super_visit_with(self), + _ => {} } + ControlFlow::Continue(()) } } diff --git a/tests/ui/type-alias-impl-trait/multi-error.rs b/tests/ui/type-alias-impl-trait/multi-error.rs index d10967abf9a..7cae9a12cb2 100644 --- a/tests/ui/type-alias-impl-trait/multi-error.rs +++ b/tests/ui/type-alias-impl-trait/multi-error.rs @@ -18,7 +18,6 @@ impl Foo for () { //~^ ERROR non-defining opaque type use ((), ()) //~^ ERROR mismatched types - //~| ERROR mismatched types } } diff --git a/tests/ui/type-alias-impl-trait/multi-error.stderr b/tests/ui/type-alias-impl-trait/multi-error.stderr index 17259373749..1b7b96075be 100644 --- a/tests/ui/type-alias-impl-trait/multi-error.stderr +++ b/tests/ui/type-alias-impl-trait/multi-error.stderr @@ -27,23 +27,6 @@ note: this item must have the opaque type in its signature in order to be able t LL | fn foo() -> (Self::Bar<u32>, Self::Baz) { | ^^^ -error[E0308]: mismatched types - --> $DIR/multi-error.rs:19:14 - | -LL | type Baz = impl Sized; - | ---------- the expected opaque type -... -LL | ((), ()) - | ^^ expected opaque type, found `()` - | - = note: expected opaque type `<() as Foo>::Baz` - found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/multi-error.rs:17:8 - | -LL | fn foo() -> (Self::Bar<u32>, Self::Baz) { - | ^^^ - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`.