Skip to content

Commit 057857e

Browse files
committed
Auto merge of rust-lang#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.
2 parents 3ba7501 + fe82649 commit 057857e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

crates/hir/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -3210,6 +3210,14 @@ impl Type {
32103210
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize)))
32113211
}
32123212

3213+
pub fn is_float(&self) -> bool {
3214+
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Float(_)))
3215+
}
3216+
3217+
pub fn is_char(&self) -> bool {
3218+
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Char))
3219+
}
3220+
32133221
pub fn is_int_or_uint(&self) -> bool {
32143222
match self.ty.kind(Interner) {
32153223
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_)) => true,

0 commit comments

Comments
 (0)