Skip to content

Commit 41881ae

Browse files
committed
Stop failing eagerly, and collect all opaque types even if some are erroneous.
1 parent 326a9fa commit 41881ae

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

compiler/rustc_ty_utils/src/opaque_types.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_data_structures::fx::FxHashSet;
2-
use rustc_errors::ErrorGuaranteed;
32
use rustc_hir::{def::DefKind, def_id::LocalDefId};
43
use rustc_middle::query::Providers;
54
use rustc_middle::ty::util::{CheckRegions, NotUniqueParam};
@@ -65,10 +64,9 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
6564
}
6665

6766
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
68-
type BreakTy = ErrorGuaranteed;
69-
7067
#[instrument(skip(self), ret, level = "trace")]
71-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<ErrorGuaranteed> {
68+
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<!> {
69+
t.super_visit_with(self)?;
7270
match t.kind() {
7371
ty::Alias(ty::Opaque, alias_ty) if alias_ty.def_id.is_local() => {
7472
if !self.seen.insert(alias_ty.def_id.expect_local()) {
@@ -91,24 +89,20 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
9189
trace!(?pred);
9290
self.visit_spanned(span, pred);
9391
}
94-
95-
ControlFlow::Continue(())
9692
}
9793
Err(NotUniqueParam::NotParam(arg)) => {
98-
let err = self.tcx.sess.emit_err(NotParam {
94+
self.tcx.sess.emit_err(NotParam {
9995
arg,
10096
span: self.span(),
10197
opaque_span: self.tcx.def_span(alias_ty.def_id),
10298
});
103-
ControlFlow::Break(err)
10499
}
105100
Err(NotUniqueParam::DuplicateParam(arg)) => {
106-
let err = self.tcx.sess.emit_err(DuplicateArg {
101+
self.tcx.sess.emit_err(DuplicateArg {
107102
arg,
108103
span: self.span(),
109104
opaque_span: self.tcx.def_span(alias_ty.def_id),
110105
});
111-
ControlFlow::Break(err)
112106
}
113107
}
114108
}
@@ -157,10 +151,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
157151
}
158152
}
159153
}
160-
t.super_visit_with(self)
161154
}
162-
_ => t.super_visit_with(self),
155+
_ => {}
163156
}
157+
ControlFlow::Continue(())
164158
}
165159
}
166160

tests/ui/type-alias-impl-trait/multi-error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ impl Foo for () {
1818
//~^ ERROR non-defining opaque type use
1919
((), ())
2020
//~^ ERROR mismatched types
21-
//~| ERROR mismatched types
2221
}
2322
}
2423

tests/ui/type-alias-impl-trait/multi-error.stderr

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,6 @@ note: this item must have the opaque type in its signature in order to be able t
2727
LL | fn foo() -> (Self::Bar<u32>, Self::Baz) {
2828
| ^^^
2929

30-
error[E0308]: mismatched types
31-
--> $DIR/multi-error.rs:19:14
32-
|
33-
LL | type Baz = impl Sized;
34-
| ---------- the expected opaque type
35-
...
36-
LL | ((), ())
37-
| ^^ expected opaque type, found `()`
38-
|
39-
= note: expected opaque type `<() as Foo>::Baz`
40-
found unit type `()`
41-
note: this item must have the opaque type in its signature in order to be able to register hidden types
42-
--> $DIR/multi-error.rs:17:8
43-
|
44-
LL | fn foo() -> (Self::Bar<u32>, Self::Baz) {
45-
| ^^^
46-
47-
error: aborting due to 3 previous errors
30+
error: aborting due to 2 previous errors
4831

4932
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)