@@ -229,49 +229,38 @@ fn layout_of<'tcx>(
229229 tcx : TyCtxt < ' tcx > ,
230230 query : ty:: ParamEnvAnd < ' tcx , Ty < ' tcx > > ,
231231) -> Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > {
232- ty:: tls:: with_related_context ( tcx, move |icx| {
233- let ( param_env, ty) = query. into_parts ( ) ;
234- debug ! ( ?ty) ;
235-
236- if !tcx. recursion_limit ( ) . value_within_limit ( icx. layout_depth ) {
237- tcx. sess . fatal ( & format ! ( "overflow representing the type `{}`" , ty) ) ;
232+ let ( param_env, ty) = query. into_parts ( ) ;
233+ debug ! ( ?ty) ;
234+
235+ let param_env = param_env. with_reveal_all_normalized ( tcx) ;
236+ let unnormalized_ty = ty;
237+
238+ // FIXME: We might want to have two different versions of `layout_of`:
239+ // One that can be called after typecheck has completed and can use
240+ // `normalize_erasing_regions` here and another one that can be called
241+ // before typecheck has completed and uses `try_normalize_erasing_regions`.
242+ let ty = match tcx. try_normalize_erasing_regions ( param_env, ty) {
243+ Ok ( t) => t,
244+ Err ( normalization_error) => {
245+ return Err ( LayoutError :: NormalizationFailure ( ty, normalization_error) ) ;
238246 }
247+ } ;
239248
240- // Update the ImplicitCtxt to increase the layout_depth
241- let icx = ty:: tls:: ImplicitCtxt { layout_depth : icx. layout_depth + 1 , ..icx. clone ( ) } ;
242-
243- ty:: tls:: enter_context ( & icx, |_| {
244- let param_env = param_env. with_reveal_all_normalized ( tcx) ;
245- let unnormalized_ty = ty;
246-
247- // FIXME: We might want to have two different versions of `layout_of`:
248- // One that can be called after typecheck has completed and can use
249- // `normalize_erasing_regions` here and another one that can be called
250- // before typecheck has completed and uses `try_normalize_erasing_regions`.
251- let ty = match tcx. try_normalize_erasing_regions ( param_env, ty) {
252- Ok ( t) => t,
253- Err ( normalization_error) => {
254- return Err ( LayoutError :: NormalizationFailure ( ty, normalization_error) ) ;
255- }
256- } ;
257-
258- if ty != unnormalized_ty {
259- // Ensure this layout is also cached for the normalized type.
260- return tcx. layout_of ( param_env. and ( ty) ) ;
261- }
249+ if ty != unnormalized_ty {
250+ // Ensure this layout is also cached for the normalized type.
251+ return tcx. layout_of ( param_env. and ( ty) ) ;
252+ }
262253
263- let cx = LayoutCx { tcx, param_env } ;
254+ let cx = LayoutCx { tcx, param_env } ;
264255
265- let layout = cx. layout_of_uncached ( ty) ?;
266- let layout = TyAndLayout { ty, layout } ;
256+ let layout = cx. layout_of_uncached ( ty) ?;
257+ let layout = TyAndLayout { ty, layout } ;
267258
268- cx. record_layout_for_printing ( layout) ;
259+ cx. record_layout_for_printing ( layout) ;
269260
270- sanity_check_layout ( & cx, & layout) ;
261+ sanity_check_layout ( & cx, & layout) ;
271262
272- Ok ( layout)
273- } )
274- } )
263+ Ok ( layout)
275264}
276265
277266pub struct LayoutCx < ' tcx , C > {
0 commit comments