about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSwarnim Arun <swarnimarun11@gmail.com>2023-02-27 10:59:20 +0530
committerSwarnim Arun <swarnimarun11@gmail.com>2023-02-27 10:59:20 +0530
commit9a481d1ecf0f11b4a5bd0220eec3fd93c997b033 (patch)
tree83360a84cbd4a2818b9c0d51942b52e924ba3646
parent4e29820f6d9880606a403e7bec6e91312e7f0575 (diff)
downloadrust-9a481d1ecf0f11b4a5bd0220eec3fd93c997b033.tar.gz
rust-9a481d1ecf0f11b4a5bd0220eec3fd93c997b033.zip
add: clean api to get `raw_ptr` type
-rw-r--r--crates/hir/src/lib.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 2cb4ed2c335..fba61a2d5b5 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -3190,6 +3190,14 @@ impl Type {
         matches!(self.ty.kind(Interner), TyKind::Raw(..))
     }
 
+    pub fn as_raw_ptr_ty(&self) -> Option<Type> {
+        if let TyKind::Raw(_, ty) = self.ty.kind(Interner) {
+            Some(self.derived(ty.clone()))
+        } else {
+            None
+        }
+    }
+
     pub fn contains_unknown(&self) -> bool {
         // FIXME: When we get rid of `ConstScalar::Unknown`, we can just look at precomputed
         // `TypeFlags` in `TyData`.