This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -277,7 +277,9 @@ pub enum BinOp {
277277impl BinOp {
278278 /// Return the type of this operation for the given input Ty.
279279 /// This function does not perform type checking, and it currently doesn't handle SIMD.
280- pub fn ty ( & self , lhs_ty : Ty , _rhs_ty : Ty ) -> Ty {
280+ pub fn ty ( & self , lhs_ty : Ty , rhs_ty : Ty ) -> Ty {
281+ assert ! ( lhs_ty. kind( ) . is_primitive( ) ) ;
282+ assert ! ( rhs_ty. kind( ) . is_primitive( ) ) ;
281283 match self {
282284 BinOp :: Add
283285 | BinOp :: AddUnchecked
@@ -289,13 +291,17 @@ impl BinOp {
289291 | BinOp :: Rem
290292 | BinOp :: BitXor
291293 | BinOp :: BitAnd
292- | BinOp :: BitOr
293- | BinOp :: Shl
294- | BinOp :: ShlUnchecked
295- | BinOp :: Shr
296- | BinOp :: ShrUnchecked
297- | BinOp :: Offset => lhs_ty,
298- BinOp :: Eq | BinOp :: Lt | BinOp :: Le | BinOp :: Ne | BinOp :: Ge | BinOp :: Gt => Ty :: bool_ty ( ) ,
294+ | BinOp :: BitOr => {
295+ assert_eq ! ( lhs_ty, rhs_ty) ;
296+ lhs_ty
297+ }
298+ BinOp :: Shl | BinOp :: ShlUnchecked | BinOp :: Shr | BinOp :: ShrUnchecked | BinOp :: Offset => {
299+ lhs_ty
300+ }
301+ BinOp :: Eq | BinOp :: Lt | BinOp :: Le | BinOp :: Ne | BinOp :: Ge | BinOp :: Gt => {
302+ assert_eq ! ( lhs_ty, rhs_ty) ;
303+ Ty :: bool_ty ( )
304+ }
299305 }
300306 }
301307}
Original file line number Diff line number Diff line change @@ -244,6 +244,19 @@ impl TyKind {
244244 matches ! ( self , TyKind :: RigidTy ( RigidTy :: FnPtr ( ..) ) )
245245 }
246246
247+ pub fn is_primitive ( & self ) -> bool {
248+ matches ! (
249+ self ,
250+ TyKind :: RigidTy (
251+ RigidTy :: Bool
252+ | RigidTy :: Char
253+ | RigidTy :: Int ( _)
254+ | RigidTy :: Uint ( _)
255+ | RigidTy :: Float ( _)
256+ )
257+ )
258+ }
259+
247260 pub fn trait_principal ( & self ) -> Option < Binder < ExistentialTraitRef > > {
248261 if let TyKind :: RigidTy ( RigidTy :: Dynamic ( predicates, _, _) ) = self {
249262 if let Some ( Binder { value : ExistentialPredicate :: Trait ( trait_ref) , bound_vars } ) =
You can’t perform that action at this time.
0 commit comments