@@ -7,6 +7,7 @@ use rustc_middle::mir::ConstraintCategory;
7
7
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeFoldable , Upcast } ;
8
8
use rustc_span:: def_id:: DefId ;
9
9
use rustc_span:: Span ;
10
+ use rustc_trait_selection:: traits:: query:: type_op:: custom:: CustomTypeOp ;
10
11
use rustc_trait_selection:: traits:: query:: type_op:: { self , TypeOpOutput } ;
11
12
use rustc_trait_selection:: traits:: ObligationCause ;
12
13
@@ -165,6 +166,52 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
165
166
result. unwrap_or ( value)
166
167
}
167
168
169
+ #[ instrument( skip( self ) , level = "debug" ) ]
170
+ pub ( super ) fn struct_tail (
171
+ & mut self ,
172
+ ty : Ty < ' tcx > ,
173
+ location : impl NormalizeLocation ,
174
+ ) -> Ty < ' tcx > {
175
+ let tcx = self . tcx ( ) ;
176
+ if self . infcx . next_trait_solver ( ) {
177
+ let body = self . body ;
178
+ let param_env = self . param_env ;
179
+ self . fully_perform_op (
180
+ location. to_locations ( ) ,
181
+ ConstraintCategory :: Boring ,
182
+ CustomTypeOp :: new (
183
+ |ocx| {
184
+ let normalize = |ty| {
185
+ ocx. structurally_normalize (
186
+ & ObligationCause :: misc (
187
+ location. to_locations ( ) . span ( body) ,
188
+ body. source . def_id ( ) . expect_local ( ) ,
189
+ ) ,
190
+ param_env,
191
+ ty,
192
+ )
193
+ . unwrap_or_else ( |_| bug ! ( "struct tail should have been computable, since we computed it in HIR" ) )
194
+ } ;
195
+
196
+ let tail = tcx. struct_tail_with_normalize (
197
+ ty,
198
+ normalize,
199
+ || { } ,
200
+ ) ;
201
+
202
+ Ok ( normalize ( tail) )
203
+ } ,
204
+ "s" ,
205
+ ) ,
206
+ )
207
+ . unwrap_or_else ( |guar| Ty :: new_error ( tcx, guar) )
208
+ } else {
209
+ let mut normalize = |ty| self . normalize ( ty, location) ;
210
+ let tail = tcx. struct_tail_with_normalize ( ty, & mut normalize, || { } ) ;
211
+ normalize ( tail)
212
+ }
213
+ }
214
+
168
215
#[ instrument( skip( self ) , level = "debug" ) ]
169
216
pub ( super ) fn ascribe_user_type (
170
217
& mut self ,
0 commit comments