Enforce builtin binop expectations on single references

Also don't enforce them on non-builtin types
This commit is contained in:
Ryo Yoshida 2023-01-17 19:48:25 +09:00
parent fa874627f0
commit 461435adab
No known key found for this signature in database
GPG key ID: E25698A930586171
3 changed files with 243 additions and 33 deletions

View file

@ -1,6 +1,6 @@
//! Various extensions traits for Chalk types.
use chalk_ir::{FloatTy, IntTy, Mutability, Scalar, UintTy};
use chalk_ir::{FloatTy, IntTy, Mutability, Scalar, TyVariableKind, UintTy};
use hir_def::{
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType, BuiltinUint},
generics::TypeOrConstParamData,
@ -18,6 +18,8 @@ use crate::{
pub trait TyExt {
fn is_unit(&self) -> bool;
fn is_integral(&self) -> bool;
fn is_floating_point(&self) -> bool;
fn is_never(&self) -> bool;
fn is_unknown(&self) -> bool;
fn is_ty_var(&self) -> bool;
@ -51,6 +53,21 @@ impl TyExt for Ty {
matches!(self.kind(Interner), TyKind::Tuple(0, _))
}
fn is_integral(&self) -> bool {
matches!(
self.kind(Interner),
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_))
| TyKind::InferenceVar(_, TyVariableKind::Integer)
)
}
fn is_floating_point(&self) -> bool {
matches!(
self.kind(Interner),
TyKind::Scalar(Scalar::Float(_)) | TyKind::InferenceVar(_, TyVariableKind::Float)
)
}
fn is_never(&self) -> bool {
matches!(self.kind(Interner), TyKind::Never)
}