Skip to content

Commit 1fd8d47

Browse files
mehmet-yalcinkaya_volvoChayimFriedman2
authored andcommitted
feat: add is_mutable_raw_ptr and as_raw_ptr to hir::Type
1 parent 8b96128 commit 1fd8d47

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

crates/hir/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5818,6 +5818,18 @@ impl<'db> Type<'db> {
58185818
matches!(self.ty.kind(), TyKind::RawPtr(..))
58195819
}
58205820

5821+
pub fn is_mutable_raw_ptr(&self) -> bool {
5822+
// Used outside of rust-analyzer (e.g. by `ra_ap_hir` consumers).
5823+
matches!(self.ty.kind(), TyKind::RawPtr(.., hir_ty::next_solver::Mutability::Mut))
5824+
}
5825+
5826+
pub fn as_raw_ptr(&self) -> Option<(Type<'db>, Mutability)> {
5827+
// Used outside of rust-analyzer (e.g. by `ra_ap_hir` consumers).
5828+
let TyKind::RawPtr(ty, m) = self.ty.kind() else { return None };
5829+
let m = Mutability::from_mutable(matches!(m, hir_ty::next_solver::Mutability::Mut));
5830+
Some((self.derived(ty), m))
5831+
}
5832+
58215833
pub fn remove_raw_ptr(&self) -> Option<Type<'db>> {
58225834
if let TyKind::RawPtr(ty, _) = self.ty.kind() { Some(self.derived(ty)) } else { None }
58235835
}

0 commit comments

Comments
 (0)