@@ -291,7 +291,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
291
291
ty:: Array ( ..) | ty:: Slice ( ..)
292
292
) ;
293
293
}
294
- Rvalue :: BinaryOp ( op, vals) | Rvalue :: CheckedBinaryOp ( op , vals ) => {
294
+ Rvalue :: BinaryOp ( op, vals) => {
295
295
use BinOp :: * ;
296
296
let a = vals. 0 . ty ( & self . body . local_decls , self . tcx ) ;
297
297
let b = vals. 1 . ty ( & self . body . local_decls , self . tcx ) ;
@@ -355,17 +355,55 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
355
355
for x in [ a, b] {
356
356
check_kinds ! (
357
357
x,
358
- "Cannot perform op on type {:?}" ,
358
+ "Cannot perform arithmetic on type {:?}" ,
359
359
ty:: Uint ( ..) | ty:: Int ( ..) | ty:: Float ( ..)
360
360
)
361
361
}
362
362
if a != b {
363
363
self . fail (
364
364
location,
365
- format ! ( "Cannot perform op on unequal types {:?} and {:?}" , a, b) ,
365
+ format ! (
366
+ "Cannot perform arithmetic on unequal types {:?} and {:?}" ,
367
+ a, b
368
+ ) ,
369
+ ) ;
370
+ }
371
+ }
372
+ }
373
+ }
374
+ Rvalue :: CheckedBinaryOp ( op, vals) => {
375
+ use BinOp :: * ;
376
+ let a = vals. 0 . ty ( & self . body . local_decls , self . tcx ) ;
377
+ let b = vals. 1 . ty ( & self . body . local_decls , self . tcx ) ;
378
+ match op {
379
+ Add | Sub | Mul => {
380
+ for x in [ a, b] {
381
+ check_kinds ! (
382
+ x,
383
+ "Cannot perform checked arithmetic on type {:?}" ,
384
+ ty:: Uint ( ..) | ty:: Int ( ..)
385
+ )
386
+ }
387
+ if a != b {
388
+ self . fail (
389
+ location,
390
+ format ! (
391
+ "Cannot perform checked arithmetic on unequal types {:?} and {:?}" ,
392
+ a, b
393
+ ) ,
366
394
) ;
367
395
}
368
396
}
397
+ Shl | Shr => {
398
+ for x in [ a, b] {
399
+ check_kinds ! (
400
+ x,
401
+ "Cannot perform checked shift on non-integer type {:?}" ,
402
+ ty:: Uint ( ..) | ty:: Int ( ..)
403
+ )
404
+ }
405
+ }
406
+ _ => self . fail ( location, format ! ( "There is no checked version of {:?}" , op) ) ,
369
407
}
370
408
}
371
409
Rvalue :: UnaryOp ( op, operand) => {
0 commit comments