@@ -28,8 +28,8 @@ use rustc::dep_graph::DepNode;
2828use rustc:: ty:: cast:: { CastKind } ;
2929use rustc_const_eval:: { ConstEvalErr , lookup_const_fn_by_id, compare_lit_exprs} ;
3030use 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 } ;
3333use rustc_const_eval:: EvalHint :: ExprTypeChecked ;
3434use rustc:: hir:: def:: Def ;
3535use rustc:: hir:: def_id:: DefId ;
@@ -437,29 +437,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
437437 }
438438 intravisit:: walk_expr ( self , ex) ;
439439 }
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- }
463440 _ => intravisit:: walk_expr ( self , ex)
464441 }
465442
@@ -505,6 +482,24 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
505482 }
506483 None => { }
507484 }
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+
508503 self . tcx . const_qualif_map . borrow_mut ( ) . insert ( ex. id , self . qualif ) ;
509504 // Don't propagate certain flags.
510505 self . qualif = outer | ( self . qualif - ConstQualif :: HAS_STATIC_BORROWS ) ;
0 commit comments