about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-04-29 18:49:02 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-04-29 18:49:02 +0000
commitbe54947315b6d2892ed09281a7770e1f09c673e7 (patch)
treed5c5de6a9d1f3ff961dd0e0bbd119294d6c46923
parent018f9347fcc265b21e5269254c50b73ac8c2a3de (diff)
downloadrust-be54947315b6d2892ed09281a7770e1f09c673e7.tar.gz
rust-be54947315b6d2892ed09281a7770e1f09c673e7.zip
Extract copy bound check into a function
-rw-r--r--compiler/rustc_typeck/src/check/expr.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs
index 7111bbaa3cd..8dd288e5555 100644
--- a/compiler/rustc_typeck/src/check/expr.rs
+++ b/compiler/rustc_typeck/src/check/expr.rs
@@ -1292,6 +1292,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             return tcx.ty_error();
         }
 
+        self.check_repeat_element_needs_copy_bound(element, count, element_ty);
+
+        tcx.mk_ty(ty::Array(t, count))
+    }
+
+    fn check_repeat_element_needs_copy_bound(
+        &self,
+        element: &hir::Expr<'_>,
+        count: ty::Const<'tcx>,
+        element_ty: Ty<'tcx>,
+    ) {
+        let tcx = self.tcx;
         let is_const = match &element.kind {
             hir::ExprKind::ConstBlock(..) => true,
             hir::ExprKind::Path(qpath) => {
@@ -1303,7 +1315,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             }
             _ => false,
         };
-
         if !is_const {
             let is_const_fn = match element.kind {
                 hir::ExprKind::Call(func, _args) => match *self.node_ty(func.hir_id).kind() {
@@ -1319,8 +1330,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 self.require_type_meets(element_ty, element.span, code, lang_item);
             }
         }
-
-        tcx.mk_ty(ty::Array(t, count))
     }
 
     fn check_expr_tuple(