Skip to content

Commit 6560d77

Browse files
committed
Bail out early if there already were errors
1 parent 29c8732 commit 6560d77

File tree

3 files changed

+7
-45
lines changed

3 files changed

+7
-45
lines changed

compiler/rustc_trait_selection/src/opaque_types.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
4848
instantiated_ty: Ty<'tcx>,
4949
span: Span,
5050
) -> Ty<'tcx> {
51+
if self.is_tainted_by_errors() {
52+
return self.tcx.ty_error();
53+
}
54+
5155
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
5256

5357
// Use substs to build up a reverse map from regions to their
@@ -67,7 +71,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
6771
// after producing an error for each of them.
6872
let definition_ty = instantiated_ty.fold_with(&mut ReverseMapper::new(
6973
self.tcx,
70-
self.is_tainted_by_errors(),
7174
def_id,
7275
map,
7376
instantiated_ty,
@@ -82,10 +85,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
8285
struct ReverseMapper<'tcx> {
8386
tcx: TyCtxt<'tcx>,
8487

85-
/// If errors have already been reported in this fn, we suppress
86-
/// our own errors because they are sometimes derivative.
87-
tainted_by_errors: bool,
88-
8988
opaque_type_def_id: DefId,
9089
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
9190
map_missing_regions_to_empty: bool,
@@ -100,15 +99,13 @@ struct ReverseMapper<'tcx> {
10099
impl<'tcx> ReverseMapper<'tcx> {
101100
fn new(
102101
tcx: TyCtxt<'tcx>,
103-
tainted_by_errors: bool,
104102
opaque_type_def_id: DefId,
105103
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
106104
hidden_ty: Ty<'tcx>,
107105
span: Span,
108106
) -> Self {
109107
Self {
110108
tcx,
111-
tainted_by_errors,
112109
opaque_type_def_id,
113110
map,
114111
map_missing_regions_to_empty: false,
@@ -167,9 +164,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
167164
match self.map.get(&r.into()).map(|k| k.unpack()) {
168165
Some(GenericArgKind::Lifetime(r1)) => r1,
169166
Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
170-
None if self.map_missing_regions_to_empty || self.tainted_by_errors => {
171-
self.tcx.lifetimes.re_root_empty
172-
}
167+
None if self.map_missing_regions_to_empty => self.tcx.lifetimes.re_root_empty,
173168
None if generics.parent.is_some() => {
174169
if let Some(hidden_ty) = self.hidden_ty.take() {
175170
unexpected_hidden_region_diagnostic(

src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ LL | t
2424
|
2525
= help: consider adding an explicit lifetime bound `T: 'static`...
2626

27-
error[E0310]: the parameter type `T` may not live long enough
28-
--> $DIR/generic_type_does_not_live_long_enough.rs:10:24
29-
|
30-
LL | type WrongGeneric<T> = impl 'static;
31-
| ^^^^^^^^^^^^
32-
|
33-
= help: consider adding an explicit lifetime bound `T: 'static`...
34-
= note: ...so that the type `T` will meet its required lifetime bounds
35-
36-
error: aborting due to 4 previous errors
27+
error: aborting due to 3 previous errors
3728

3829
For more information about this error, try `rustc --explain E0310`.

src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.nll.stderr

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,5 @@ error: higher-ranked subtype error
1010
LL | |x| x
1111
| ^^^^^
1212

13-
error[E0308]: mismatched types
14-
--> $DIR/issue-57611-trait-alias.rs:17:16
15-
|
16-
LL | type Bar = impl Baz<Self, Self>;
17-
| ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
18-
|
19-
= note: expected type `for<'r> Fn<(&'r X,)>`
20-
found type `Fn<(&'static X,)>`
21-
note: this closure does not fulfill the lifetime requirements
22-
--> $DIR/issue-57611-trait-alias.rs:20:9
23-
|
24-
LL | |x| x
25-
| ^^^^^
26-
27-
error: implementation of `FnOnce` is not general enough
28-
--> $DIR/issue-57611-trait-alias.rs:17:16
29-
|
30-
LL | type Bar = impl Baz<Self, Self>;
31-
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
32-
|
33-
= note: closure with signature `fn(&'static X) -> &'static X` must implement `FnOnce<(&'0 X,)>`, for any lifetime `'0`...
34-
= note: ...but it actually implements `FnOnce<(&'static X,)>`
35-
36-
error: aborting due to 4 previous errors
13+
error: aborting due to 2 previous errors
3714

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

0 commit comments

Comments
 (0)