From 30d15d8a37b486e7cb445b8630e2300854829ded Mon Sep 17 00:00:00 2001 From: mehmet-yalcinkaya_volvo Date: Wed, 18 Mar 2026 16:31:36 +0100 Subject: [PATCH] feat: add is_mutable_raw_ptr and as_raw_ptr to hir::Type --- crates/hir/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 0b3515fd0498..fdac31feb6ea 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -5693,6 +5693,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> { if let TyKind::RawPtr(ty, _) = self.ty.kind() { Some(self.derived(ty)) } else { None } }