33use rustc_data_structures:: fx:: FxHashSet ;
44use rustc_hir:: def_id:: DefId ;
55use rustc_middle:: ty:: subst:: Subst ;
6+ use rustc_middle:: ty:: subst:: SubstsRef ;
67use rustc_middle:: ty:: util:: { needs_drop_components, AlwaysRequiresDrop } ;
78use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
89use rustc_session:: Limit ;
@@ -12,7 +13,7 @@ type NeedsDropResult<T> = Result<T, AlwaysRequiresDrop>;
1213
1314fn needs_drop_raw < ' tcx > ( tcx : TyCtxt < ' tcx > , query : ty:: ParamEnvAnd < ' tcx , Ty < ' tcx > > ) -> bool {
1415 let adt_components =
15- move |adt_def : & ty:: AdtDef | tcx. adt_drop_tys ( adt_def. did ) . map ( |tys| tys. iter ( ) ) ;
16+ move |adt_def : & ty:: AdtDef , _ | tcx. adt_drop_tys ( adt_def. did ) . map ( |tys| tys. iter ( ) ) ;
1617
1718 // If we don't know a type doesn't need drop, for example if it's a type
1819 // parameter without a `Copy` bound, then we conservatively return that it
@@ -28,8 +29,9 @@ fn has_significant_drop_raw<'tcx>(
2829 tcx : TyCtxt < ' tcx > ,
2930 query : ty:: ParamEnvAnd < ' tcx , Ty < ' tcx > > ,
3031) -> bool {
31- let significant_drop_fields =
32- move |adt_def : & ty:: AdtDef | tcx. adt_significant_drop_tys ( adt_def. did ) . map ( |tys| tys. iter ( ) ) ;
32+ let significant_drop_fields = move |adt_def : & ty:: AdtDef , _| {
33+ tcx. adt_significant_drop_tys ( adt_def. did ) . map ( |tys| tys. iter ( ) )
34+ } ;
3335 let res = NeedsDropTypes :: new ( tcx, query. param_env , query. value , significant_drop_fields)
3436 . next ( )
3537 . is_some ( ) ;
@@ -74,7 +76,7 @@ impl<'tcx, F> NeedsDropTypes<'tcx, F> {
7476
7577impl < ' tcx , F , I > Iterator for NeedsDropTypes < ' tcx , F >
7678where
77- F : Fn ( & ty:: AdtDef ) -> NeedsDropResult < I > ,
79+ F : Fn ( & ty:: AdtDef , SubstsRef < ' tcx > ) -> NeedsDropResult < I > ,
7880 I : Iterator < Item = Ty < ' tcx > > ,
7981{
8082 type Item = NeedsDropResult < Ty < ' tcx > > ;
@@ -138,7 +140,7 @@ where
138140 // `ManuallyDrop`. If it's a struct or enum without a `Drop`
139141 // impl then check whether the field types need `Drop`.
140142 ty:: Adt ( adt_def, substs) => {
141- let tys = match ( self . adt_components ) ( adt_def) {
143+ let tys = match ( self . adt_components ) ( adt_def, substs ) {
142144 Err ( e) => return Some ( Err ( e) ) ,
143145 Ok ( tys) => tys,
144146 } ;
@@ -185,12 +187,12 @@ enum DtorType {
185187// Depending on the implentation of `adt_has_dtor`, it is used to check if the
186188// ADT has a destructor or if the ADT only has a significant destructor. For
187189// understanding significant destructor look at `adt_significant_drop_tys`.
188- fn adt_drop_tys_helper (
189- tcx : TyCtxt < ' _ > ,
190+ fn adt_drop_tys_helper < ' tcx > (
191+ tcx : TyCtxt < ' tcx > ,
190192 def_id : DefId ,
191193 adt_has_dtor : impl Fn ( & ty:: AdtDef ) -> Option < DtorType > ,
192- ) -> Result < & ty:: List < Ty < ' _ > > , AlwaysRequiresDrop > {
193- let adt_components = move |adt_def : & ty:: AdtDef | {
194+ ) -> Result < & ty:: List < Ty < ' tcx > > , AlwaysRequiresDrop > {
195+ let adt_components = move |adt_def : & ty:: AdtDef , substs : SubstsRef < ' tcx > | {
194196 if adt_def. is_manually_drop ( ) {
195197 debug ! ( "adt_drop_tys: `{:?}` is manually drop" , adt_def) ;
196198 return Ok ( Vec :: new ( ) . into_iter ( ) ) ;
@@ -202,7 +204,11 @@ fn adt_drop_tys_helper(
202204 }
203205 DtorType :: Insignificant => {
204206 debug ! ( "adt_drop_tys: `{:?}` drop is insignificant" , adt_def) ;
205- return Ok ( Vec :: new ( ) . into_iter ( ) ) ;
207+
208+ // Since the destructor is insignificant, we just want to make sure all of
209+ // the passed in type parameters are also insignificant.
210+ // Eg: Vec<T> dtor is insignificant when T=i32 but significant when T=Mutex.
211+ return Ok ( substs. types ( ) . collect :: < Vec < Ty < ' _ > > > ( ) . into_iter ( ) ) ;
206212 }
207213 }
208214 } else if adt_def. is_union ( ) {
0 commit comments