Skip to content

Commit fac8b4e

Browse files
committed
Support building clone shims for arrays with generic size
1 parent 539402c commit fac8b4e

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

compiler/rustc_mir/src/shim.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
308308

309309
match self_ty.kind() {
310310
_ if is_copy => builder.copy_shim(),
311-
ty::Array(ty, len) => {
312-
let len = len.eval_usize(tcx, param_env);
313-
builder.array_shim(dest, src, ty, len)
314-
}
311+
ty::Array(ty, len) => builder.array_shim(dest, src, ty, len),
315312
ty::Closure(_, substs) => {
316313
builder.tuple_like_shim(dest, src, substs.as_closure().upvar_tys())
317314
}
@@ -485,7 +482,13 @@ impl CloneShimBuilder<'tcx> {
485482
}
486483
}
487484

488-
fn array_shim(&mut self, dest: Place<'tcx>, src: Place<'tcx>, ty: Ty<'tcx>, len: u64) {
485+
fn array_shim(
486+
&mut self,
487+
dest: Place<'tcx>,
488+
src: Place<'tcx>,
489+
ty: Ty<'tcx>,
490+
len: &'tcx ty::Const<'tcx>,
491+
) {
489492
let tcx = self.tcx;
490493
let span = self.span;
491494

@@ -503,7 +506,11 @@ impl CloneShimBuilder<'tcx> {
503506
))),
504507
self.make_statement(StatementKind::Assign(box (
505508
end,
506-
Rvalue::Use(Operand::Constant(self.make_usize(len))),
509+
Rvalue::Use(Operand::Constant(box Constant {
510+
span: self.span,
511+
user_ty: None,
512+
literal: len,
513+
})),
507514
))),
508515
];
509516
self.block(inits, TerminatorKind::Goto { target: BasicBlock::new(1) }, false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Checks that we can build a clone shim for array with generic size.
2+
// Regression test for issue #79269.
3+
//
4+
// build-pass
5+
// compile-flags: -Zmir-opt-level=2 -Zvalidate-mir
6+
#![feature(min_const_generics)]
7+
8+
#[derive(Clone)]
9+
struct Array<T, const N: usize>([T; N]);
10+
11+
fn main() {
12+
let _ = Array([0u32, 1u32, 2u32]).clone();
13+
}

0 commit comments

Comments
 (0)