Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/drop.rs')
-rw-r--r--crates/hir-ty/src/drop.rs59
1 files changed, 26 insertions, 33 deletions
diff --git a/crates/hir-ty/src/drop.rs b/crates/hir-ty/src/drop.rs
index b09d1fb196..9d6869eee9 100644
--- a/crates/hir-ty/src/drop.rs
+++ b/crates/hir-ty/src/drop.rs
@@ -1,39 +1,38 @@
//! Utilities for computing drop info about types.
-use hir_def::{AdtId, lang_item::LangItem, signatures::StructFlags};
+use hir_def::{AdtId, signatures::StructFlags};
use rustc_hash::FxHashSet;
-use rustc_type_ir::inherent::{AdtDef, IntoKind, SliceLike};
+use rustc_type_ir::inherent::{AdtDef, IntoKind};
use stdx::never;
-use triomphe::Arc;
use crate::{
- TraitEnvironment, consteval,
- db::HirDatabase,
- method_resolution::TyFingerprint,
+ InferenceResult, consteval,
+ method_resolution::TraitImpls,
next_solver::{
- Ty, TyKind,
+ DbInterner, ParamEnv, SimplifiedType, Ty, TyKind,
infer::{InferCtxt, traits::ObligationCause},
obligation_ctxt::ObligationCtxt,
},
};
-fn has_destructor(db: &dyn HirDatabase, adt: AdtId) -> bool {
+fn has_destructor(interner: DbInterner<'_>, adt: AdtId) -> bool {
+ let db = interner.db;
let module = match adt {
AdtId::EnumId(id) => db.lookup_intern_enum(id).container,
AdtId::StructId(id) => db.lookup_intern_struct(id).container,
AdtId::UnionId(id) => db.lookup_intern_union(id).container,
};
- let Some(drop_trait) = LangItem::Drop.resolve_trait(db, module.krate()) else {
+ let Some(drop_trait) = interner.lang_items().Drop else {
return false;
};
- let impls = match module.containing_block() {
- Some(block) => match db.trait_impls_in_block(block) {
- Some(it) => it,
+ let impls = match module.block(db) {
+ Some(block) => match TraitImpls::for_block(db, block) {
+ Some(it) => &**it,
None => return false,
},
- None => db.trait_impls_in_crate(module.krate()),
+ None => TraitImpls::for_crate(db, module.krate(db)),
};
- impls.for_trait_and_self_ty(drop_trait, TyFingerprint::Adt(adt)).next().is_some()
+ !impls.for_trait_and_self_ty(drop_trait, &SimplifiedType::Adt(adt.into())).0.is_empty()
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
@@ -47,22 +46,18 @@ pub enum DropGlue {
HasDropGlue,
}
-pub fn has_drop_glue<'db>(
- infcx: &InferCtxt<'db>,
- ty: Ty<'db>,
- env: Arc<TraitEnvironment<'db>>,
-) -> DropGlue {
+pub fn has_drop_glue<'db>(infcx: &InferCtxt<'db>, ty: Ty<'db>, env: ParamEnv<'db>) -> DropGlue {
has_drop_glue_impl(infcx, ty, env, &mut FxHashSet::default())
}
fn has_drop_glue_impl<'db>(
infcx: &InferCtxt<'db>,
ty: Ty<'db>,
- env: Arc<TraitEnvironment<'db>>,
+ env: ParamEnv<'db>,
visited: &mut FxHashSet<Ty<'db>>,
) -> DropGlue {
let mut ocx = ObligationCtxt::new(infcx);
- let ty = ocx.structurally_normalize_ty(&ObligationCause::dummy(), env.env, ty).unwrap_or(ty);
+ let ty = ocx.structurally_normalize_ty(&ObligationCause::dummy(), env, ty).unwrap_or(ty);
if !visited.insert(ty) {
// Recursive type.
@@ -73,7 +68,7 @@ fn has_drop_glue_impl<'db>(
match ty.kind() {
TyKind::Adt(adt_def, subst) => {
let adt_id = adt_def.def_id().0;
- if has_destructor(db, adt_id) {
+ if has_destructor(infcx.interner, adt_id) {
return DropGlue::HasDropGlue;
}
match adt_id {
@@ -90,8 +85,8 @@ fn has_drop_glue_impl<'db>(
.map(|(_, field_ty)| {
has_drop_glue_impl(
infcx,
- field_ty.instantiate(infcx.interner, subst),
- env.clone(),
+ field_ty.get().instantiate(infcx.interner, subst),
+ env,
visited,
)
})
@@ -110,8 +105,8 @@ fn has_drop_glue_impl<'db>(
.map(|(_, field_ty)| {
has_drop_glue_impl(
infcx,
- field_ty.instantiate(infcx.interner, subst),
- env.clone(),
+ field_ty.get().instantiate(infcx.interner, subst),
+ env,
visited,
)
})
@@ -124,7 +119,7 @@ fn has_drop_glue_impl<'db>(
}
TyKind::Tuple(tys) => tys
.iter()
- .map(|ty| has_drop_glue_impl(infcx, ty, env.clone(), visited))
+ .map(|ty| has_drop_glue_impl(infcx, ty, env, visited))
.max()
.unwrap_or(DropGlue::None),
TyKind::Array(ty, len) => {
@@ -137,14 +132,12 @@ fn has_drop_glue_impl<'db>(
TyKind::Slice(ty) => has_drop_glue_impl(infcx, ty, env, visited),
TyKind::Closure(closure_id, subst) => {
let owner = db.lookup_intern_closure(closure_id.0).0;
- let infer = db.infer(owner);
+ let infer = InferenceResult::for_body(db, owner);
let (captures, _) = infer.closure_info(closure_id.0);
let env = db.trait_environment_for_body(owner);
captures
.iter()
- .map(|capture| {
- has_drop_glue_impl(infcx, capture.ty(db, subst), env.clone(), visited)
- })
+ .map(|capture| has_drop_glue_impl(infcx, capture.ty(db, subst), env, visited))
.max()
.unwrap_or(DropGlue::None)
}
@@ -169,14 +162,14 @@ fn has_drop_glue_impl<'db>(
| TyKind::Placeholder(..) => DropGlue::None,
TyKind::Dynamic(..) => DropGlue::HasDropGlue,
TyKind::Alias(..) => {
- if infcx.type_is_copy_modulo_regions(env.env, ty) {
+ if infcx.type_is_copy_modulo_regions(env, ty) {
DropGlue::None
} else {
DropGlue::HasDropGlue
}
}
TyKind::Param(_) => {
- if infcx.type_is_copy_modulo_regions(env.env, ty) {
+ if infcx.type_is_copy_modulo_regions(env, ty) {
DropGlue::None
} else {
DropGlue::DependOnParams