Unnamed repository; edit this file 'description' to name the repository.
feat: add is_mutable_raw_ptr and as_raw_ptr to hir::Type
| -rw-r--r-- | crates/hir/src/lib.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 2829902035..7a4085c474 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -5818,6 +5818,18 @@ impl<'db> Type<'db> { matches!(self.ty.kind(), TyKind::RawPtr(..)) } + pub fn is_mutable_raw_ptr(&self) -> bool { + // Used outside of rust-analyzer (e.g. by `ra_ap_hir` consumers). + matches!(self.ty.kind(), TyKind::RawPtr(.., hir_ty::next_solver::Mutability::Mut)) + } + + pub fn as_raw_ptr(&self) -> Option<(Type<'db>, Mutability)> { + // Used outside of rust-analyzer (e.g. by `ra_ap_hir` consumers). + let TyKind::RawPtr(ty, m) = self.ty.kind() else { return None }; + let m = Mutability::from_mutable(matches!(m, hir_ty::next_solver::Mutability::Mut)); + Some((self.derived(ty), m)) + } + pub fn remove_raw_ptr(&self) -> Option<Type<'db>> { if let TyKind::RawPtr(ty, _) = self.ty.kind() { Some(self.derived(ty)) } else { None } } |