Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/next_solver/region.rs')
-rw-r--r--crates/hir-ty/src/next_solver/region.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/crates/hir-ty/src/next_solver/region.rs b/crates/hir-ty/src/next_solver/region.rs
index 0bfd2b8003..5e7eb7532b 100644
--- a/crates/hir-ty/src/next_solver/region.rs
+++ b/crates/hir-ty/src/next_solver/region.rs
@@ -3,7 +3,8 @@
use hir_def::LifetimeParamId;
use intern::{Interned, Symbol};
use rustc_type_ir::{
- BoundVar, Flags, INNERMOST, RegionVid, TypeFlags, TypeFoldable, TypeVisitable, VisitorResult,
+ BoundVar, DebruijnIndex, Flags, INNERMOST, RegionVid, TypeFlags, TypeFoldable, TypeVisitable,
+ VisitorResult,
inherent::{IntoKind, PlaceholderLike, SliceLike},
relate::Relate,
};
@@ -17,25 +18,30 @@ use super::{
pub type RegionKind<'db> = rustc_type_ir::RegionKind<DbInterner<'db>>;
-#[salsa::interned(constructor = new_, debug)]
+#[salsa::interned(constructor = new_)]
pub struct Region<'db> {
#[returns(ref)]
kind_: RegionKind<'db>,
}
+impl std::fmt::Debug for Region<'_> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ self.kind().fmt(f)
+ }
+}
+
impl<'db> Region<'db> {
pub fn new(interner: DbInterner<'db>, kind: RegionKind<'db>) -> Self {
Region::new_(interner.db(), kind)
}
pub fn inner(&self) -> &RegionKind<'db> {
- salsa::with_attached_database(|db| {
+ crate::with_attached_db(|db| {
let inner = self.kind_(db);
// SAFETY: The caller already has access to a `Region<'db>`, so borrowchecking will
// make sure that our returned value is valid for the lifetime `'db`.
unsafe { std::mem::transmute::<&RegionKind<'_>, &RegionKind<'db>>(inner) }
})
- .unwrap()
}
pub fn new_early_param(
@@ -57,6 +63,14 @@ impl<'db> Region<'db> {
Region::new(interner, RegionKind::ReErased)
}
+ pub fn new_bound(
+ interner: DbInterner<'db>,
+ index: DebruijnIndex,
+ bound: BoundRegion,
+ ) -> Region<'db> {
+ Region::new(interner, RegionKind::ReBound(index, bound))
+ }
+
pub fn is_placeholder(&self) -> bool {
matches!(self.inner(), RegionKind::RePlaceholder(..))
}
@@ -69,6 +83,10 @@ impl<'db> Region<'db> {
matches!(self.inner(), RegionKind::ReVar(_))
}
+ pub fn is_error(&self) -> bool {
+ matches!(self.inner(), RegionKind::ReError(_))
+ }
+
pub fn error(interner: DbInterner<'db>) -> Self {
Region::new(interner, RegionKind::ReError(ErrorGuaranteed))
}