Skip to content

Commit

Permalink
Extract copy bound check into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 29, 2022
1 parent 018f934 commit be54947
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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() {
Expand All @@ -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(
Expand Down

0 comments on commit be54947

Please sign in to comment.