@@ -7,6 +7,7 @@ use rustc_middle::mir::ConstraintCategory;
77use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeFoldable , Upcast } ;
88use rustc_span:: def_id:: DefId ;
99use rustc_span:: Span ;
10+ use rustc_trait_selection:: traits:: query:: type_op:: custom:: CustomTypeOp ;
1011use rustc_trait_selection:: traits:: query:: type_op:: { self , TypeOpOutput } ;
1112use rustc_trait_selection:: traits:: ObligationCause ;
1213
@@ -165,6 +166,52 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
165166 result. unwrap_or ( value)
166167 }
167168
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 structurally_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_raw (
197+ ty,
198+ structurally_normalize,
199+ || { } ,
200+ ) ;
201+
202+ Ok ( tail)
203+ } ,
204+ "normalizing struct tail" ,
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_raw ( ty, & mut normalize, || { } ) ;
211+ normalize ( tail)
212+ }
213+ }
214+
168215 #[ instrument( skip( self ) , level = "debug" ) ]
169216 pub ( super ) fn ascribe_user_type (
170217 & mut self ,
0 commit comments