]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check/mod.rs
Auto merge of #30470 - petrochenkov:owned5, r=nrc
[rust.git] / src / librustc_typeck / check / mod.rs
index 515a7706b829668d80ed2466505135d020036edb..e8eb479a1c36fd618ae90cada3b07bf61dfd5378 100644 (file)
 pub mod demand;
 pub mod method;
 mod upvar;
-mod wf;
 mod wfcheck;
 mod cast;
 mod closure;
@@ -382,21 +381,6 @@ fn visit_item(&mut self, i: &'tcx hir::Item) {
     }
 }
 
-pub fn check_wf_old(ccx: &CrateCtxt) {
-    // If types are not well-formed, it leads to all manner of errors
-    // downstream, so stop reporting errors at this point.
-    ccx.tcx.sess.abort_if_new_errors(|| {
-        // FIXME(#25759). The new code below is much more reliable but (for now)
-        // only generates warnings. So as to ensure that we continue
-        // getting errors where we used to get errors, we run the old wf
-        // code first and abort if it encounters any errors. If no abort
-        // comes, we run the new code and issue warnings.
-        let krate = ccx.tcx.map.krate();
-        let mut visit = wf::CheckTypeWellFormedVisitor::new(ccx);
-        krate.visit_all_items(&mut visit);
-    });
-}
-
 pub fn check_wf_new(ccx: &CrateCtxt) {
     ccx.tcx.sess.abort_if_new_errors(|| {
         let krate = ccx.tcx.map.krate();
@@ -2664,6 +2648,14 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
     }
 }
 
+fn check_expr_eq_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
+                                expr: &'tcx hir::Expr,
+                                expected: Ty<'tcx>) {
+    check_expr_with_unifier(
+        fcx, expr, ExpectHasType(expected), NoPreference,
+        || demand::eqtype(fcx, expr.span, expected, fcx.expr_ty(expr)));
+}
+
 pub fn check_expr_has_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                                      expr: &'tcx hir::Expr,
                                      expected: Ty<'tcx>) {
@@ -3526,6 +3518,11 @@ fn check_expr_struct<'a, 'tcx>(fcx: &FnCtxt<'a,'tcx>,
             deferred_cast_checks.push(cast_check);
         }
       }
+      hir::ExprType(ref e, ref t) => {
+        let typ = fcx.to_ty(&**t);
+        check_expr_eq_type(fcx, &**e, typ);
+        fcx.write_ty(id, typ);
+      }
       hir::ExprVec(ref args) => {
         let uty = expected.to_option(fcx).and_then(|uty| {
             match uty.sty {