@@ -28,8 +28,8 @@ use rustc::dep_graph::DepNode;
28
28
use rustc:: ty:: cast:: { CastKind } ;
29
29
use rustc_const_eval:: { ConstEvalErr , lookup_const_fn_by_id, compare_lit_exprs} ;
30
30
use rustc_const_eval:: { eval_const_expr_partial, lookup_const_by_id} ;
31
- use rustc_const_eval:: ErrKind :: { IndexOpFeatureGated , UnimplementedConstVal } ;
32
- use rustc_const_eval:: ErrKind :: ErroneousReferencedConstant ;
31
+ use rustc_const_eval:: ErrKind :: { IndexOpFeatureGated , UnimplementedConstVal , MiscCatchAll } ;
32
+ use rustc_const_eval:: ErrKind :: { ErroneousReferencedConstant , MiscBinaryOp } ;
33
33
use rustc_const_eval:: EvalHint :: ExprTypeChecked ;
34
34
use rustc:: hir:: def:: Def ;
35
35
use rustc:: hir:: def_id:: DefId ;
@@ -437,29 +437,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
437
437
}
438
438
intravisit:: walk_expr ( self , ex) ;
439
439
}
440
- // Division by zero and overflow checking.
441
- hir:: ExprBinary ( op, _, _) => {
442
- intravisit:: walk_expr ( self , ex) ;
443
- let div_or_rem = op. node == hir:: BiDiv || op. node == hir:: BiRem ;
444
- match node_ty. sty {
445
- ty:: TyUint ( _) | ty:: TyInt ( _) if div_or_rem => {
446
- if !self . qualif . intersects ( ConstQualif :: NOT_CONST ) {
447
- match eval_const_expr_partial (
448
- self . tcx , ex, ExprTypeChecked , None ) {
449
- Ok ( _) => { }
450
- Err ( ConstEvalErr { kind : UnimplementedConstVal ( _) , ..} ) |
451
- Err ( ConstEvalErr { kind : IndexOpFeatureGated , ..} ) => { } ,
452
- Err ( msg) => {
453
- self . tcx . sess . add_lint ( CONST_ERR , ex. id ,
454
- msg. span ,
455
- msg. description ( ) . into_owned ( ) )
456
- }
457
- }
458
- }
459
- }
460
- _ => { }
461
- }
462
- }
463
440
_ => intravisit:: walk_expr ( self , ex)
464
441
}
465
442
@@ -505,6 +482,24 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
505
482
}
506
483
None => { }
507
484
}
485
+
486
+ if self . mode == Mode :: Var && !self . qualif . intersects ( ConstQualif :: NOT_CONST ) {
487
+ match eval_const_expr_partial ( self . tcx , ex, ExprTypeChecked , None ) {
488
+ Ok ( _) => { }
489
+ Err ( ConstEvalErr { kind : UnimplementedConstVal ( _) , ..} ) |
490
+ Err ( ConstEvalErr { kind : MiscCatchAll , ..} ) |
491
+ Err ( ConstEvalErr { kind : MiscBinaryOp , ..} ) |
492
+ Err ( ConstEvalErr { kind : ErroneousReferencedConstant ( _) , ..} ) |
493
+ Err ( ConstEvalErr { kind : IndexOpFeatureGated , ..} ) => { } ,
494
+ Err ( msg) => {
495
+ self . qualif = self . qualif | ConstQualif :: NOT_CONST ;
496
+ self . tcx . sess . add_lint ( CONST_ERR , ex. id ,
497
+ msg. span ,
498
+ msg. description ( ) . into_owned ( ) )
499
+ }
500
+ }
501
+ }
502
+
508
503
self . tcx . const_qualif_map . borrow_mut ( ) . insert ( ex. id , self . qualif ) ;
509
504
// Don't propagate certain flags.
510
505
self . qualif = outer | ( self . qualif - ConstQualif :: HAS_STATIC_BORROWS ) ;
0 commit comments