@@ -3,6 +3,7 @@ use crate::ty::fold::{TypeFolder, TypeSuperFoldable};
3
3
use crate :: ty:: subst:: { GenericArg , GenericArgKind } ;
4
4
use crate :: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
5
5
use rustc_data_structures:: fx:: FxHashMap ;
6
+ use rustc_span:: def_id:: DefId ;
6
7
use rustc_span:: Span ;
7
8
8
9
/// Converts generic params of a TypeFoldable from one
@@ -47,6 +48,47 @@ impl<'tcx> ReverseMapper<'tcx> {
47
48
assert ! ( !self . do_not_error) ;
48
49
kind. fold_with ( self )
49
50
}
51
+
52
+ fn fold_closure_substs (
53
+ & mut self ,
54
+ def_id : DefId ,
55
+ substs : ty:: SubstsRef < ' tcx > ,
56
+ ) -> ty:: SubstsRef < ' tcx > {
57
+ // I am a horrible monster and I pray for death. When
58
+ // we encounter a closure here, it is always a closure
59
+ // from within the function that we are currently
60
+ // type-checking -- one that is now being encapsulated
61
+ // in an opaque type. Ideally, we would
62
+ // go through the types/lifetimes that it references
63
+ // and treat them just like we would any other type,
64
+ // which means we would error out if we find any
65
+ // reference to a type/region that is not in the
66
+ // "reverse map".
67
+ //
68
+ // **However,** in the case of closures, there is a
69
+ // somewhat subtle (read: hacky) consideration. The
70
+ // problem is that our closure types currently include
71
+ // all the lifetime parameters declared on the
72
+ // enclosing function, even if they are unused by the
73
+ // closure itself. We can't readily filter them out,
74
+ // so here we replace those values with `'empty`. This
75
+ // can't really make a difference to the rest of the
76
+ // compiler; those regions are ignored for the
77
+ // outlives relation, and hence don't affect trait
78
+ // selection or auto traits, and they are erased
79
+ // during codegen.
80
+
81
+ let generics = self . tcx . generics_of ( def_id) ;
82
+ self . tcx . mk_substs ( substs. iter ( ) . enumerate ( ) . map ( |( index, kind) | {
83
+ if index < generics. parent_count {
84
+ // Accommodate missing regions in the parent kinds...
85
+ self . fold_kind_no_missing_regions_error ( kind)
86
+ } else {
87
+ // ...but not elsewhere.
88
+ self . fold_kind_normally ( kind)
89
+ }
90
+ } ) )
91
+ }
50
92
}
51
93
52
94
impl < ' tcx > TypeFolder < ' tcx > for ReverseMapper < ' tcx > {
@@ -104,59 +146,20 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
104
146
fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
105
147
match * ty. kind ( ) {
106
148
ty:: Closure ( def_id, substs) => {
107
- // I am a horrible monster and I pray for death. When
108
- // we encounter a closure here, it is always a closure
109
- // from within the function that we are currently
110
- // type-checking -- one that is now being encapsulated
111
- // in an opaque type. Ideally, we would
112
- // go through the types/lifetimes that it references
113
- // and treat them just like we would any other type,
114
- // which means we would error out if we find any
115
- // reference to a type/region that is not in the
116
- // "reverse map".
117
- //
118
- // **However,** in the case of closures, there is a
119
- // somewhat subtle (read: hacky) consideration. The
120
- // problem is that our closure types currently include
121
- // all the lifetime parameters declared on the
122
- // enclosing function, even if they are unused by the
123
- // closure itself. We can't readily filter them out,
124
- // so here we replace those values with `'empty`. This
125
- // can't really make a difference to the rest of the
126
- // compiler; those regions are ignored for the
127
- // outlives relation, and hence don't affect trait
128
- // selection or auto traits, and they are erased
129
- // during codegen.
130
-
131
- let generics = self . tcx . generics_of ( def_id) ;
132
- let substs = self . tcx . mk_substs ( substs. iter ( ) . enumerate ( ) . map ( |( index, kind) | {
133
- if index < generics. parent_count {
134
- // Accommodate missing regions in the parent kinds...
135
- self . fold_kind_no_missing_regions_error ( kind)
136
- } else {
137
- // ...but not elsewhere.
138
- self . fold_kind_normally ( kind)
139
- }
140
- } ) ) ;
141
-
149
+ let substs = self . fold_closure_substs ( def_id, substs) ;
142
150
self . tcx . mk_closure ( def_id, substs)
143
151
}
144
152
145
153
ty:: Generator ( def_id, substs, movability) => {
146
- let generics = self . tcx . generics_of ( def_id) ;
147
- let substs = self . tcx . mk_substs ( substs. iter ( ) . enumerate ( ) . map ( |( index, kind) | {
148
- if index < generics. parent_count {
149
- // Accommodate missing regions in the parent kinds...
150
- self . fold_kind_no_missing_regions_error ( kind)
151
- } else {
152
- // ...but not elsewhere.
153
- self . fold_kind_normally ( kind)
154
- }
155
- } ) ) ;
156
-
154
+ let substs = self . fold_closure_substs ( def_id, substs) ;
157
155
self . tcx . mk_generator ( def_id, substs, movability)
158
156
}
159
157
158
+ ty:: GeneratorWitnessMIR ( def_id, substs) => {
159
+ let substs = self . fold_closure_substs ( def_id, substs) ;
160
+ self . tcx . mk_generator_witness_mir ( def_id, substs)
161
+ }
162
+
160
163
ty:: Param ( param) => {
161
164
// Look it up in the substitution list.
162
165
match self . map . get ( & ty. into ( ) ) . map ( |k| k. unpack ( ) ) {
0 commit comments