Skip to content

Commit 30d15d8

Browse files
author
mehmet-yalcinkaya_volvo
committed
feat: add is_mutable_raw_ptr and as_raw_ptr to hir::Type
1 parent 4eac290 commit 30d15d8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

crates/hir/src/lib.rs

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

5696+
pub fn is_mutable_raw_ptr(&self) -> bool {
5697+
// Used outside of rust-analyzer (e.g. by `ra_ap_hir` consumers).
5698+
matches!(self.ty.kind(), TyKind::RawPtr(.., hir_ty::next_solver::Mutability::Mut))
5699+
}
5700+
5701+
pub fn as_raw_ptr(&self) -> Option<(Type<'db>, Mutability)> {
5702+
// Used outside of rust-analyzer (e.g. by `ra_ap_hir` consumers).
5703+
let TyKind::RawPtr(ty, m) = self.ty.kind() else { return None };
5704+
let m = Mutability::from_mutable(matches!(m, hir_ty::next_solver::Mutability::Mut));
5705+
Some((self.derived(ty), m))
5706+
}
5707+
56965708
pub fn remove_raw_ptr(&self) -> Option<Type<'db>> {
56975709
if let TyKind::RawPtr(ty, _) = self.ty.kind() { Some(self.derived(ty)) } else { None }
56985710
}

0 commit comments

Comments
 (0)