about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-02-27 10:45:29 +0000
committerbors <bors@rust-lang.org>2023-02-27 10:45:29 +0000
commitb38fcde3ba6010d64d22138fa82dccb852fa8b23 (patch)
tree2490338d1a750d8873f4d509b85cfd79536837b0
parent2e479158bbd89f191dfc86a93c27063b064be25f (diff)
parent832f8bfe2ba4fcd8ac36e01a8a99d84cbcf6c762 (diff)
downloadrust-b38fcde3ba6010d64d22138fa82dccb852fa8b23.tar.gz
rust-b38fcde3ba6010d64d22138fa82dccb852fa8b23.zip
Auto merge of #14213 - swarnimarun:raw-ptr-ty, r=Veykril
add: clean api to get `raw_ptr` type

There doesn't seem to be an API to fetch the type of `raw_ptr`, which is helpful for a project I work on.

Notes:

- I am unsure about the function name, do let me know if I should use something else.
- Also unsure about where to add tests, for hir changes. Will fix it as needed.
-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..163a3194435 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 remove_raw_ptr(&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`.