Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #14334 - swarnimarun:is-float-char, r=lnicola
feat: add `is_float` & `is_char` to `hir::Type` Some useful functions we didn't have on `Type` (were present on `BuiltinType`). Also, I am considering exposing `TyKind` with `get_kind`, let me know if that's a better idea than implementing these API extensions incrementally.
bors 2023-03-14
parent 3ba7501 · parent fe82649 · commit 057857e
-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 25c07a2fbd..6d0083c071 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -3210,6 +3210,14 @@ impl Type {
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize)))
}
+ pub fn is_float(&self) -> bool {
+ matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Float(_)))
+ }
+
+ pub fn is_char(&self) -> bool {
+ matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Char))
+ }
+
pub fn is_int_or_uint(&self) -> bool {
match self.ty.kind(Interner) {
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_)) => true,