@@ -111,7 +111,11 @@ pub trait DropElaborator<'a, 'tcx>: fmt::Debug {
111
111
fn patch ( & mut self ) -> & mut MirPatch < ' tcx > ;
112
112
fn body ( & self ) -> & ' a Body < ' tcx > ;
113
113
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 > > ;
115
119
116
120
// Drop logic
117
121
@@ -276,9 +280,11 @@ where
276
280
let subpath = self . elaborator . field_subpath ( variant_path, field) ;
277
281
let tcx = self . tcx ( ) ;
278
282
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
+ }
282
288
283
289
( tcx. mk_place_field ( base_place, field, field_ty) , subpath)
284
290
} )
@@ -374,9 +380,9 @@ where
374
380
debug ! ( "drop_ladder({:?}, {:?})" , self , fields) ;
375
381
376
382
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
+ }
380
386
381
387
debug ! ( "drop_ladder - fields needing drop: {:?}" , fields) ;
382
388
@@ -548,10 +554,13 @@ where
548
554
have_otherwise = true ;
549
555
550
556
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
+ } ) ;
555
564
if have_field_with_drop_glue {
556
565
have_otherwise_with_drop_glue = true ;
557
566
}
@@ -869,7 +878,10 @@ where
869
878
ty:: Adt ( def, args) => self . open_drop_for_adt ( * def, args) ,
870
879
ty:: Dynamic ( ..) => self . complete_drop ( self . succ , self . unwind ) ,
871
880
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) ) ;
873
885
self . open_drop_for_array ( * ety, size)
874
886
}
875
887
ty:: Slice ( ety) => self . drop_loop_pair ( * ety) ,
0 commit comments