]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_hir_analysis/src/check/expr.rs
Auto merge of #102543 - daym:patch-1, r=joshtriplett
[rust.git] / compiler / rustc_hir_analysis / src / check / expr.rs
index 375c13d922bc7386677f182094c415cf49281019..71c6da862c94b6907a4ede11f7c9050a4cc46cfe 100644 (file)
@@ -3,7 +3,7 @@
 //! See `mod.rs` for more context on type checking in general.
 
 use crate::astconv::AstConv as _;
-use crate::check::cast::{self, CastCheckResult};
+use crate::check::cast;
 use crate::check::coercion::CoerceMany;
 use crate::check::fatally_break_rust;
 use crate::check::method::SelfSource;
@@ -1051,8 +1051,20 @@ fn check_expr_assign(
                 rhs_expr,
             ) = lhs.kind
             {
+                // if x == 1 && y == 2 { .. }
+                //                 +
                 let actual_lhs_ty = self.check_expr(&rhs_expr);
                 (Applicability::MaybeIncorrect, self.can_coerce(rhs_ty, actual_lhs_ty))
+            } else if let ExprKind::Binary(
+                Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. },
+                lhs_expr,
+                _,
+            ) = rhs.kind
+            {
+                // if x == 1 && y == 2 { .. }
+                //       +
+                let actual_rhs_ty = self.check_expr(&lhs_expr);
+                (Applicability::MaybeIncorrect, self.can_coerce(actual_rhs_ty, lhs_ty))
             } else {
                 (Applicability::MaybeIncorrect, false)
             };
@@ -1258,9 +1270,8 @@ fn check_expr_cast(
         } else {
             // Defer other checks until we're done type checking.
             let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
-            match cast::check_cast(self, e, t_expr, t_cast, t.span, expr.span) {
-                CastCheckResult::Ok => t_cast,
-                CastCheckResult::Deferred(cast_check) => {
+            match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) {
+                Ok(cast_check) => {
                     debug!(
                         "check_expr_cast: deferring cast from {:?} to {:?}: {:?}",
                         t_cast, t_expr, cast_check,
@@ -1268,7 +1279,7 @@ fn check_expr_cast(
                     deferred_cast_checks.push(cast_check);
                     t_cast
                 }
-                CastCheckResult::Err(ErrorGuaranteed { .. }) => self.tcx.ty_error(),
+                Err(_) => self.tcx.ty_error(),
             }
         }
     }