@@ -111,7 +111,11 @@ pub trait DropElaborator<'a, 'tcx>: fmt::Debug {
111111    fn  patch ( & mut  self )  -> & mut  MirPatch < ' tcx > ; 
112112    fn  body ( & self )  -> & ' a  Body < ' tcx > ; 
113113    fn  tcx ( & self )  -> TyCtxt < ' tcx > ; 
114-     fn  param_env ( & self )  -> ty:: ParamEnv < ' tcx > ; 
114+ 
115+     // A param-env that can be used to compute drop queries (such as `Ty::needs_drop`). 
116+     // If this is `None`, then the elaborator must handle the type as if it were unknown, 
117+     // i.e. emitting full drops. 
118+     fn  param_env ( & self )  -> Option < ty:: ParamEnv < ' tcx > > ; 
115119
116120    // Drop logic 
117121
@@ -276,9 +280,11 @@ where
276280                let  subpath = self . elaborator . field_subpath ( variant_path,  field) ; 
277281                let  tcx = self . tcx ( ) ; 
278282
279-                 assert_eq ! ( self . elaborator. param_env( ) . reveal( ) ,  Reveal :: All ) ; 
280-                 let  field_ty =
281-                     tcx. normalize_erasing_regions ( self . elaborator . param_env ( ) ,  f. ty ( tcx,  args) ) ; 
283+                 let  mut  field_ty = f. ty ( tcx,  args) ; 
284+                 if  let  Some ( param_env)  = self . elaborator . param_env ( )  { 
285+                     assert_eq ! ( param_env. reveal( ) ,  Reveal :: All ) ; 
286+                     field_ty = tcx. normalize_erasing_regions ( param_env,  field_ty) ; 
287+                 } 
282288
283289                ( tcx. mk_place_field ( base_place,  field,  field_ty) ,  subpath) 
284290            } ) 
@@ -374,9 +380,9 @@ where
374380        debug ! ( "drop_ladder({:?}, {:?})" ,  self ,  fields) ; 
375381
376382        let  mut  fields = fields; 
377-         fields . retain ( | & ( place ,  _ ) |  { 
378-             self . place_ty ( place) . needs_drop ( self . tcx ( ) ,  self . elaborator . param_env ( ) ) 
379-         } ) ; 
383+         if   let   Some ( param_env )  =  self . elaborator . param_env ( )  { 
384+             fields . retain ( | & ( place ,  _ ) |  self . place_ty ( place) . needs_drop ( self . tcx ( ) ,  param_env) ) ; 
385+         } 
380386
381387        debug ! ( "drop_ladder - fields needing drop: {:?}" ,  fields) ; 
382388
@@ -548,10 +554,13 @@ where
548554                have_otherwise = true ; 
549555
550556                let  param_env = self . elaborator . param_env ( ) ; 
551-                 let  have_field_with_drop_glue = variant
552-                     . fields 
553-                     . iter ( ) 
554-                     . any ( |field| field. ty ( tcx,  args) . needs_drop ( tcx,  param_env) ) ; 
557+ 
558+                 let  have_field_with_drop_glue = param_env. is_none_or ( |param_env| { 
559+                     variant
560+                         . fields 
561+                         . iter ( ) 
562+                         . any ( |field| field. ty ( tcx,  args) . needs_drop ( tcx,  param_env) ) 
563+                 } ) ; 
555564                if  have_field_with_drop_glue { 
556565                    have_otherwise_with_drop_glue = true ; 
557566                } 
@@ -869,7 +878,10 @@ where
869878            ty:: Adt ( def,  args)  => self . open_drop_for_adt ( * def,  args) , 
870879            ty:: Dynamic ( ..)  => self . complete_drop ( self . succ ,  self . unwind ) , 
871880            ty:: Array ( ety,  size)  => { 
872-                 let  size = size. try_eval_target_usize ( self . tcx ( ) ,  self . elaborator . param_env ( ) ) ; 
881+                 let  size = self 
882+                     . elaborator 
883+                     . param_env ( ) 
884+                     . and_then ( |param_env| size. try_eval_target_usize ( self . tcx ( ) ,  param_env) ) ; 
873885                self . open_drop_for_array ( * ety,  size) 
874886            } 
875887            ty:: Slice ( ety)  => self . drop_loop_pair ( * ety) , 
0 commit comments