File tree 2 files changed +27
-8
lines changed
2 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -277,7 +277,9 @@ pub enum BinOp {
277
277
impl BinOp {
278
278
/// Return the type of this operation for the given input Ty.
279
279
/// 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( ) ) ;
281
283
match self {
282
284
BinOp :: Add
283
285
| BinOp :: AddUnchecked
@@ -289,13 +291,17 @@ impl BinOp {
289
291
| BinOp :: Rem
290
292
| BinOp :: BitXor
291
293
| 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
+ }
299
305
}
300
306
}
301
307
}
Original file line number Diff line number Diff line change @@ -244,6 +244,19 @@ impl TyKind {
244
244
matches ! ( self , TyKind :: RigidTy ( RigidTy :: FnPtr ( ..) ) )
245
245
}
246
246
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
+
247
260
pub fn trait_principal ( & self ) -> Option < Binder < ExistentialTraitRef > > {
248
261
if let TyKind :: RigidTy ( RigidTy :: Dynamic ( predicates, _, _) ) = self {
249
262
if let Some ( Binder { value : ExistentialPredicate :: Trait ( trait_ref) , bound_vars } ) =
You can’t perform that action at this time.
0 commit comments