@@ -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> {
8285struct 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> {
10099impl < ' 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 (
0 commit comments