2525// by borrowck::gather_loans
2626
2727use rustc:: dep_graph:: DepNode ;
28- use rustc:: ty:: cast:: { CastKind } ;
29- use rustc_const_eval:: { ConstEvalErr , lookup_const_fn_by_id , compare_lit_exprs } ;
28+ use rustc:: ty:: cast:: CastKind ;
29+ use rustc_const_eval:: { ConstEvalErr , compare_lit_exprs , lookup_const_fn_by_id } ;
3030use rustc_const_eval:: { eval_const_expr_partial, lookup_const_by_id} ;
31- use rustc_const_eval:: ErrKind :: { IndexOpFeatureGated , UnimplementedConstVal , MiscCatchAll , Math } ;
31+ use rustc_const_eval:: ErrKind :: { IndexOpFeatureGated , Math , MiscCatchAll , UnimplementedConstVal } ;
3232use rustc_const_eval:: ErrKind :: { ErroneousReferencedConstant , MiscBinaryOp , NonConstPath } ;
3333use rustc_const_eval:: ErrKind :: UnresolvedPath ;
3434use rustc_const_eval:: EvalHint :: ExprTypeChecked ;
@@ -70,12 +70,12 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> {
7070 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
7171 mode : Mode ,
7272 qualif : ConstQualif ,
73- rvalue_borrows : NodeMap < hir:: Mutability >
73+ rvalue_borrows : NodeMap < hir:: Mutability > ,
7474}
7575
7676impl < ' a , ' gcx > CheckCrateVisitor < ' a , ' gcx > {
77- fn with_mode < F , R > ( & mut self , mode : Mode , f : F ) -> R where
78- F : FnOnce ( & mut CheckCrateVisitor < ' a , ' gcx > ) -> R ,
77+ fn with_mode < F , R > ( & mut self , mode : Mode , f : F ) -> R
78+ where F : FnOnce ( & mut CheckCrateVisitor < ' a , ' gcx > ) -> R
7979 {
8080 let ( old_mode, old_qualif) = ( self . mode , self . qualif ) ;
8181 self . mode = mode;
@@ -86,17 +86,17 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
8686 r
8787 }
8888
89- fn with_euv < F , R > ( & mut self , item_id : Option < ast:: NodeId > , f : F ) -> R where
90- F : for <' b , ' tcx > FnOnce ( & mut euv:: ExprUseVisitor < ' b , ' gcx , ' tcx > ) -> R ,
89+ fn with_euv < F , R > ( & mut self , item_id : Option < ast:: NodeId > , f : F ) -> R
90+ where F : for <' b , ' tcx > FnOnce ( & mut euv:: ExprUseVisitor < ' b , ' gcx , ' tcx > ) -> R
9191 {
9292 let param_env = match item_id {
9393 Some ( item_id) => ty:: ParameterEnvironment :: for_item ( self . tcx , item_id) ,
94- None => self . tcx . empty_parameter_environment ( )
94+ None => self . tcx . empty_parameter_environment ( ) ,
9595 } ;
9696
97- self . tcx . infer_ctxt ( None , Some ( param_env ) , ProjectionMode :: AnyFinal ) . enter ( |infcx| {
98- f ( & mut euv :: ExprUseVisitor :: new ( self , & infcx ) )
99- } )
97+ self . tcx
98+ . infer_ctxt ( None , Some ( param_env ) , ProjectionMode :: AnyFinal )
99+ . enter ( |infcx| f ( & mut euv :: ExprUseVisitor :: new ( self , & infcx ) ) )
100100 }
101101
102102 fn global_expr ( & mut self , mode : Mode , expr : & hir:: Expr ) -> ConstQualif {
@@ -110,13 +110,17 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
110110 }
111111 if let Err ( err) = eval_const_expr_partial ( self . tcx , expr, ExprTypeChecked , None ) {
112112 match err. kind {
113- UnimplementedConstVal ( _) => { } ,
114- IndexOpFeatureGated => { } ,
115- ErroneousReferencedConstant ( _) => { } ,
116- _ => self . tcx . sess . add_lint ( CONST_ERR , expr. id , expr. span ,
117- format ! ( "constant evaluation error: {}. This will \
113+ UnimplementedConstVal ( _) => { }
114+ IndexOpFeatureGated => { }
115+ ErroneousReferencedConstant ( _) => { }
116+ _ => {
117+ self . tcx . sess . add_lint ( CONST_ERR ,
118+ expr. id ,
119+ expr. span ,
120+ format ! ( "constant evaluation error: {}. This will \
118121 become a HARD ERROR in the future",
119- err. description( ) ) ) ,
122+ err. description( ) ) )
123+ }
120124 }
121125 }
122126 self . with_mode ( mode, |this| {
@@ -142,17 +146,15 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
142146 }
143147
144148 let mode = match fk {
145- FnKind :: ItemFn ( _, _, _, hir:: Constness :: Const , _, _, _) => {
146- Mode :: ConstFn
147- }
149+ FnKind :: ItemFn ( _, _, _, hir:: Constness :: Const , _, _, _) => Mode :: ConstFn ,
148150 FnKind :: Method ( _, m, _, _) => {
149151 if m. constness == hir:: Constness :: Const {
150152 Mode :: ConstFn
151153 } else {
152154 Mode :: Var
153155 }
154156 }
155- _ => Mode :: Var
157+ _ => Mode :: Var ,
156158 } ;
157159
158160 let qualif = self . with_mode ( mode, |this| {
@@ -174,11 +176,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
174176 }
175177
176178 /// Returns true if the call is to a const fn or method.
177- fn handle_const_fn_call ( & mut self ,
178- _expr : & hir:: Expr ,
179- def_id : DefId ,
180- ret_ty : Ty < ' gcx > )
181- -> bool {
179+ fn handle_const_fn_call ( & mut self , _expr : & hir:: Expr , def_id : DefId , ret_ty : Ty < ' gcx > ) -> bool {
182180 if let Some ( fn_like) = lookup_const_fn_by_id ( self . tcx , def_id) {
183181 let qualif = self . fn_like ( fn_like. kind ( ) ,
184182 fn_like. decl ( ) ,
@@ -293,17 +291,21 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
293291 Some ( Ordering :: Less ) |
294292 Some ( Ordering :: Equal ) => { }
295293 Some ( Ordering :: Greater ) => {
296- span_err ! ( self . tcx. sess, start. span, E0030 ,
297- "lower range bound must be less than or equal to upper" ) ;
294+ span_err ! ( self . tcx. sess,
295+ start. span,
296+ E0030 ,
297+ "lower range bound must be less than or equal to upper" ) ;
298298 }
299299 None => {
300- span_err ! ( self . tcx. sess, p. span, E0014 ,
300+ span_err ! ( self . tcx. sess,
301+ p. span,
302+ E0014 ,
301303 "paths in {}s may only refer to constants" ,
302304 self . msg( ) ) ;
303305 }
304306 }
305307 }
306- _ => intravisit:: walk_pat ( self , p)
308+ _ => intravisit:: walk_pat ( self , p) ,
307309 }
308310 }
309311
@@ -313,13 +315,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
313315 match stmt. node {
314316 hir:: StmtDecl ( ref decl, _) => {
315317 match decl. node {
316- hir:: DeclLocal ( _) => { } ,
318+ hir:: DeclLocal ( _) => { }
317319 // Item statements are allowed
318- hir:: DeclItem ( _) => continue
320+ hir:: DeclItem ( _) => continue ,
319321 }
320322 }
321- hir:: StmtExpr ( _, _) => { } ,
322- hir:: StmtSemi ( _, _) => { } ,
323+ hir:: StmtExpr ( _, _) => { }
324+ hir:: StmtSemi ( _, _) => { }
323325 }
324326 self . add_qualif ( ConstQualif :: NOT_CONST ) ;
325327 }
@@ -352,7 +354,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
352354 // The count is checked elsewhere (typeck).
353355 let count = match node_ty. sty {
354356 ty:: TyArray ( _, n) => n,
355- _ => bug ! ( )
357+ _ => bug ! ( ) ,
356358 } ;
357359 // [element; 0] is always zero-sized.
358360 if count == 0 {
@@ -377,7 +379,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
377379 }
378380 intravisit:: walk_expr ( self , ex) ;
379381 }
380- _ => intravisit:: walk_expr ( self , ex)
382+ _ => intravisit:: walk_expr ( self , ex) ,
381383 }
382384
383385 // Handle borrows on (or inside the autorefs of) this expression.
@@ -417,19 +419,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
417419 if self . mode == Mode :: Var && !self . qualif . intersects ( ConstQualif :: NOT_CONST ) {
418420 match eval_const_expr_partial ( self . tcx , ex, ExprTypeChecked , None ) {
419421 Ok ( _) => { }
420- Err ( ConstEvalErr { kind : UnimplementedConstVal ( _) , ..} ) |
421- Err ( ConstEvalErr { kind : MiscCatchAll , ..} ) |
422- Err ( ConstEvalErr { kind : MiscBinaryOp , ..} ) |
423- Err ( ConstEvalErr { kind : NonConstPath , ..} ) |
424- Err ( ConstEvalErr { kind : UnresolvedPath , ..} ) |
425- Err ( ConstEvalErr { kind : ErroneousReferencedConstant ( _) , ..} ) |
426- Err ( ConstEvalErr { kind : Math ( ConstMathErr :: Overflow ( Op :: Shr ) ) , ..} ) |
427- Err ( ConstEvalErr { kind : Math ( ConstMathErr :: Overflow ( Op :: Shl ) ) , ..} ) |
428- Err ( ConstEvalErr { kind : IndexOpFeatureGated , ..} ) => { } ,
422+ Err ( ConstEvalErr { kind : UnimplementedConstVal ( _) , .. } ) |
423+ Err ( ConstEvalErr { kind : MiscCatchAll , .. } ) |
424+ Err ( ConstEvalErr { kind : MiscBinaryOp , .. } ) |
425+ Err ( ConstEvalErr { kind : NonConstPath , .. } ) |
426+ Err ( ConstEvalErr { kind : UnresolvedPath , .. } ) |
427+ Err ( ConstEvalErr { kind : ErroneousReferencedConstant ( _) , .. } ) |
428+ Err ( ConstEvalErr { kind : Math ( ConstMathErr :: Overflow ( Op :: Shr ) ) , .. } ) |
429+ Err ( ConstEvalErr { kind : Math ( ConstMathErr :: Overflow ( Op :: Shl ) ) , .. } ) |
430+ Err ( ConstEvalErr { kind : IndexOpFeatureGated , .. } ) => { }
429431 Err ( msg) => {
430- self . tcx . sess . add_lint ( CONST_ERR , ex . id ,
431- msg . span ,
432- msg. description ( ) . into_owned ( ) )
432+ self . tcx
433+ . sess
434+ . add_lint ( CONST_ERR , ex . id , msg . span , msg. description ( ) . into_owned ( ) )
433435 }
434436 }
435437 }
@@ -446,8 +448,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
446448/// every nested expression. If the expression is not part
447449/// of a const/static item, it is qualified for promotion
448450/// instead of producing errors.
449- fn check_expr < ' a , ' tcx > ( v : & mut CheckCrateVisitor < ' a , ' tcx > ,
450- e : & hir:: Expr , node_ty : Ty < ' tcx > ) {
451+ fn check_expr < ' a , ' tcx > ( v : & mut CheckCrateVisitor < ' a , ' tcx > , e : & hir:: Expr , node_ty : Ty < ' tcx > ) {
451452 match node_ty. sty {
452453 ty:: TyStruct ( def, _) |
453454 ty:: TyEnum ( def, _) if def. has_dtor ( ) => {
@@ -649,25 +650,23 @@ fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Exp
649650 Some ( & ty:: adjustment:: AdjustUnsafeFnPointer ) |
650651 Some ( & ty:: adjustment:: AdjustMutToConstPointer ) => { }
651652
652- Some ( & ty:: adjustment:: AdjustDerefRef (
653- ty:: adjustment:: AutoDerefRef { autoderefs, .. }
654- ) ) => {
655- if ( 0 ..autoderefs as u32 ) . any ( |autoderef| {
656- v. tcx . is_overloaded_autoderef ( e. id , autoderef)
657- } ) {
653+ Some ( & ty:: adjustment:: AdjustDerefRef ( ty:: adjustment:: AutoDerefRef { autoderefs, .. } ) ) => {
654+ if ( 0 ..autoderefs as u32 )
655+ . any ( |autoderef| v. tcx . is_overloaded_autoderef ( e. id , autoderef) ) {
658656 v. add_qualif ( ConstQualif :: NOT_CONST ) ;
659657 }
660658 }
661659 }
662660}
663661
664662pub fn check_crate < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) {
665- tcx. visit_all_items_in_krate ( DepNode :: CheckConst , & mut CheckCrateVisitor {
666- tcx : tcx,
667- mode : Mode :: Var ,
668- qualif : ConstQualif :: NOT_CONST ,
669- rvalue_borrows : NodeMap ( )
670- } ) ;
663+ tcx. visit_all_items_in_krate ( DepNode :: CheckConst ,
664+ & mut CheckCrateVisitor {
665+ tcx : tcx,
666+ mode : Mode :: Var ,
667+ qualif : ConstQualif :: NOT_CONST ,
668+ rvalue_borrows : NodeMap ( ) ,
669+ } ) ;
671670 tcx. sess . abort_if_errors ( ) ;
672671}
673672
@@ -689,7 +688,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
689688
690689 Categorization :: Rvalue ( ..) |
691690 Categorization :: Upvar ( ..) |
692- Categorization :: Local ( ..) => break
691+ Categorization :: Local ( ..) => break ,
693692 }
694693 }
695694 }
@@ -699,8 +698,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
699698 cmt : mc:: cmt < ' tcx > ,
700699 _loan_region : ty:: Region ,
701700 bk : ty:: BorrowKind ,
702- loan_cause : euv:: LoanCause )
703- {
701+ loan_cause : euv:: LoanCause ) {
704702 // Kind of hacky, but we allow Unsafe coercions in constants.
705703 // These occur when we convert a &T or *T to a *U, as well as
706704 // when making a thin pointer (e.g., `*T`) into a fat pointer
@@ -709,7 +707,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
709707 euv:: LoanCause :: AutoUnsafe => {
710708 return ;
711709 }
712- _ => { }
710+ _ => { }
713711 }
714712
715713 let mut cur = & cmt;
@@ -746,27 +744,20 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
746744 }
747745
748746 Categorization :: Upvar ( ..) |
749- Categorization :: Local ( ..) => break
747+ Categorization :: Local ( ..) => break ,
750748 }
751749 }
752750 }
753751
754- fn decl_without_init ( & mut self ,
755- _id : ast:: NodeId ,
756- _span : Span ) { }
752+ fn decl_without_init ( & mut self , _id : ast:: NodeId , _span : Span ) { }
757753 fn mutate ( & mut self ,
758754 _assignment_id : ast:: NodeId ,
759755 _assignment_span : Span ,
760756 _assignee_cmt : mc:: cmt ,
761- _mode : euv:: MutateMode ) { }
757+ _mode : euv:: MutateMode ) {
758+ }
762759
763- fn matched_pat ( & mut self ,
764- _: & hir:: Pat ,
765- _: mc:: cmt ,
766- _: euv:: MatchMode ) { }
760+ fn matched_pat ( & mut self , _: & hir:: Pat , _: mc:: cmt , _: euv:: MatchMode ) { }
767761
768- fn consume_pat ( & mut self ,
769- _consume_pat : & hir:: Pat ,
770- _cmt : mc:: cmt ,
771- _mode : euv:: ConsumeMode ) { }
762+ fn consume_pat ( & mut self , _consume_pat : & hir:: Pat , _cmt : mc:: cmt , _mode : euv:: ConsumeMode ) { }
772763}
0 commit comments