]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/check_const.rs
Auto merge of #28846 - Ms2ger:categorization, r=nikomatsakis
[rust.git] / src / librustc / middle / check_const.rs
index 15c56d23da203f6e995bbe888ff9f40410b3d279..76fa54317fc1123cd59df792356aac98476b7f57 100644 (file)
@@ -32,6 +32,7 @@
 use middle::expr_use_visitor as euv;
 use middle::infer;
 use middle::mem_categorization as mc;
+use middle::mem_categorization::Categorization;
 use middle::traits;
 use middle::ty::{self, Ty};
 use util::nodemap::NodeMap;
@@ -176,6 +177,7 @@ fn fn_like(&mut self,
         if mode == Mode::ConstFn {
             for arg in &fd.inputs {
                 match arg.pat.node {
+                    hir::PatWild => {}
                     hir::PatIdent(hir::BindByValue(hir::MutImmutable), _, None) => {}
                     _ => {
                         span_err!(self.tcx.sess, arg.pat.span, E0022,
@@ -472,12 +474,12 @@ fn visit_expr(&mut self, ex: &hir::Expr) {
                     ty::TyUint(_) | ty::TyInt(_) if div_or_rem => {
                         if !self.qualif.intersects(ConstQualif::NOT_CONST) {
                             match const_eval::eval_const_expr_partial(
-                                    self.tcx, ex, ExprTypeChecked) {
+                                    self.tcx, ex, ExprTypeChecked, None) {
                                 Ok(_) => {}
                                 Err(msg) => {
-                                    span_err!(self.tcx.sess, msg.span, E0020,
-                                              "{} in a constant expression",
-                                              msg.description())
+                                    self.tcx.sess.add_lint(::lint::builtin::CONST_ERR, ex.id,
+                                                           msg.span,
+                                                           msg.description().into_owned())
                                 }
                             }
                         }
@@ -854,7 +856,7 @@ fn consume(&mut self,
         let mut cur = &cmt;
         loop {
             match cur.cat {
-                mc::cat_static_item => {
+                Categorization::StaticItem => {
                     if self.mode != Mode::Var {
                         // statics cannot be consumed by value at any time, that would imply
                         // that they're an initializer (what a const is for) or kept in sync
@@ -865,13 +867,13 @@ fn consume(&mut self,
                     }
                     break;
                 }
-                mc::cat_deref(ref cmt, _, _) |
-                mc::cat_downcast(ref cmt, _) |
-                mc::cat_interior(ref cmt, _) => cur = cmt,
+                Categorization::Deref(ref cmt, _, _) |
+                Categorization::Downcast(ref cmt, _) |
+                Categorization::Interior(ref cmt, _) => cur = cmt,
 
-                mc::cat_rvalue(..) |
-                mc::cat_upvar(..) |
-                mc::cat_local(..) => break
+                Categorization::Rvalue(..) |
+                Categorization::Upvar(..) |
+                Categorization::Local(..) => break
             }
         }
     }
@@ -898,7 +900,7 @@ fn borrow(&mut self,
         let mut is_interior = false;
         loop {
             match cur.cat {
-                mc::cat_rvalue(..) => {
+                Categorization::Rvalue(..) => {
                     if loan_cause == euv::MatchDiscriminant {
                         // Ignore the dummy immutable borrow created by EUV.
                         break;
@@ -919,7 +921,7 @@ fn borrow(&mut self,
                     self.record_borrow(borrow_id, mutbl);
                     break;
                 }
-                mc::cat_static_item => {
+                Categorization::StaticItem => {
                     if is_interior && self.mode != Mode::Var {
                         // Borrowed statics can specifically *only* have their address taken,
                         // not any number of other borrows such as borrowing fields, reading
@@ -930,15 +932,15 @@ fn borrow(&mut self,
                     }
                     break;
                 }
-                mc::cat_deref(ref cmt, _, _) |
-                mc::cat_downcast(ref cmt, _) |
-                mc::cat_interior(ref cmt, _) => {
+                Categorization::Deref(ref cmt, _, _) |
+                Categorization::Downcast(ref cmt, _) |
+                Categorization::Interior(ref cmt, _) => {
                     is_interior = true;
                     cur = cmt;
                 }
 
-                mc::cat_upvar(..) |
-                mc::cat_local(..) => break
+                Categorization::Upvar(..) |
+                Categorization::Local(..) => break
             }
         }
     }