about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-03-14 09:20:58 +0000
committerbors <bors@rust-lang.org>2023-03-14 09:20:58 +0000
commitdef4dbb520fd77e6907ca82a6bec1c91f4c19b3b (patch)
treef9c0b02d68cfeaa1429de4f6be5e5dc7a2a49193
parent57803753b0e29e1d346ece86ebc5190902e24651 (diff)
parentcfbdf62344cad34f0d6b7ffcc9c0ed90e543e84a (diff)
downloadrust-def4dbb520fd77e6907ca82a6bec1c91f4c19b3b.tar.gz
rust-def4dbb520fd77e6907ca82a6bec1c91f4c19b3b.zip
Auto merge of #14336 - swarnimarun:remove-slice, r=lnicola
internal: add `as_slice` to `hir::Type`

~`remove_slice`~ `as_slice` is same as `remove_ref` but for slices.

Though there is `as_array` which I believe was named such because it also gets the length of the array, maybe. I am still shaky on the names feel free to suggest corrections.
-rw-r--r--crates/hir/src/lib.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 6d0083c0711..27c4577d60d 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -3232,6 +3232,13 @@ impl Type {
         }
     }
 
+    pub fn as_slice(&self) -> Option<Type> {
+        match &self.ty.kind(Interner) {
+            TyKind::Slice(ty) => Some(self.derived(ty.clone())),
+            _ => None,
+        }
+    }
+
     pub fn strip_references(&self) -> Type {
         self.derived(self.ty.strip_references().clone())
     }