X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_ty_utils%2Fsrc%2Fneeds_drop.rs;h=c5fc4e4c6610562865eb132b3cf3114eb35ad49a;hb=05d22212e89588e7c443cc6b9bc0e4e02fdfbc8d;hp=322511be817fb08e6642aa7bceb5375edfc43667;hpb=d58c69ae96c8d936a9074e9c706036242e895d9b;p=rust.git diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index 322511be817..c5fc4e4c661 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -16,7 +16,7 @@ fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx> // parameter without a `Copy` bound, then we conservatively return that it // needs drop. let adt_has_dtor = - |adt_def: &ty::AdtDef| adt_def.destructor(tcx).map(|_| DtorType::Significant); + |adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant); let res = drop_tys_helper(tcx, query.value, query.param_env, adt_has_dtor, false).next().is_some(); @@ -78,7 +78,7 @@ fn new( impl<'tcx, F, I> Iterator for NeedsDropTypes<'tcx, F> where - F: Fn(&ty::AdtDef, SubstsRef<'tcx>) -> NeedsDropResult, + F: Fn(ty::AdtDef<'tcx>, SubstsRef<'tcx>) -> NeedsDropResult, I: Iterator>, { type Item = NeedsDropResult>; @@ -181,19 +181,19 @@ enum DtorType { /// "significant" / "insignificant". Insignificant, - /// Type has a `Drop` implentation. + /// Type has a `Drop` implantation. Significant, } // This is a helper function for `adt_drop_tys` and `adt_significant_drop_tys`. -// Depending on the implentation of `adt_has_dtor`, it is used to check if the +// Depending on the implantation of `adt_has_dtor`, it is used to check if the // ADT has a destructor or if the ADT only has a significant destructor. For // understanding significant destructor look at `adt_significant_drop_tys`. fn drop_tys_helper<'tcx>( tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, param_env: rustc_middle::ty::ParamEnv<'tcx>, - adt_has_dtor: impl Fn(&ty::AdtDef) -> Option, + adt_has_dtor: impl Fn(ty::AdtDef<'tcx>) -> Option, only_significant: bool, ) -> impl Iterator>> { fn with_query_cache<'tcx>( @@ -203,7 +203,7 @@ fn with_query_cache<'tcx>( iter.into_iter().try_fold(Vec::new(), |mut vec, subty| { match subty.kind() { ty::Adt(adt_id, subst) => { - for subty in tcx.adt_drop_tys(adt_id.did)? { + for subty in tcx.adt_drop_tys(adt_id.did())? { vec.push(subty.subst(tcx, subst)); } } @@ -213,7 +213,7 @@ fn with_query_cache<'tcx>( }) } - let adt_components = move |adt_def: &ty::AdtDef, substs: SubstsRef<'tcx>| { + let adt_components = move |adt_def: ty::AdtDef<'tcx>, substs: SubstsRef<'tcx>| { if adt_def.is_manually_drop() { debug!("drop_tys_helper: `{:?}` is manually drop", adt_def); Ok(Vec::new()) @@ -260,9 +260,9 @@ fn with_query_cache<'tcx>( fn adt_consider_insignificant_dtor<'tcx>( tcx: TyCtxt<'tcx>, -) -> impl Fn(&ty::AdtDef) -> Option + 'tcx { - move |adt_def: &ty::AdtDef| { - let is_marked_insig = tcx.has_attr(adt_def.did, sym::rustc_insignificant_dtor); +) -> impl Fn(ty::AdtDef<'tcx>) -> Option + 'tcx { + move |adt_def: ty::AdtDef<'tcx>| { + let is_marked_insig = tcx.has_attr(adt_def.did(), sym::rustc_insignificant_dtor); if is_marked_insig { // In some cases like `std::collections::HashMap` where the struct is a wrapper around // a type that is a Drop type, and the wrapped type (eg: `hashbrown::HashMap`) lies @@ -281,18 +281,21 @@ fn adt_consider_insignificant_dtor<'tcx>( } } -fn adt_drop_tys(tcx: TyCtxt<'_>, def_id: DefId) -> Result<&ty::List>, AlwaysRequiresDrop> { +fn adt_drop_tys<'tcx>( + tcx: TyCtxt<'tcx>, + def_id: DefId, +) -> Result<&ty::List>, AlwaysRequiresDrop> { // This is for the "adt_drop_tys" query, that considers all `Drop` impls, therefore all dtors are // significant. let adt_has_dtor = - |adt_def: &ty::AdtDef| adt_def.destructor(tcx).map(|_| DtorType::Significant); + |adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant); // `tcx.type_of(def_id)` identical to `tcx.make_adt(def, identity_substs)` drop_tys_helper(tcx, tcx.type_of(def_id), tcx.param_env(def_id), adt_has_dtor, false) .collect::, _>>() .map(|components| tcx.intern_type_list(&components)) } // If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed -// a `tcx.make_ty(def, identity_substs)` and as such it is legal to substitue the generic parameters +// a `tcx.make_ty(def, identity_substs)` and as such it is legal to substitute the generic parameters // of the ADT into the outputted `ty`s. fn adt_significant_drop_tys( tcx: TyCtxt<'_>,