Skip to content

Commit 186099c

Browse files
committed
Reviews
1 parent b27b151 commit 186099c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
122122
}
123123

124124
// We want to emit an error if the const is not structurally resolveable as otherwise
125-
// we can find up conservatively proving `Copy` which may infer the repeat expr count
125+
// we can wind up conservatively proving `Copy` which may infer the repeat expr count
126126
// to something that never required `Copy` in the first place.
127127
let count = self
128128
.structurally_resolve_const(element.span, self.normalize(element.span, count));
@@ -171,14 +171,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
171171

172172
for (element, element_ty, count) in deferred_repeat_expr_checks {
173173
match count.kind() {
174-
ty::ConstKind::Value(val)
175-
if val.try_to_target_usize(self.tcx).is_none_or(|count| count > 1) =>
176-
{
177-
enforce_copy_bound(element, element_ty)
174+
ty::ConstKind::Value(val) => {
175+
if val.try_to_target_usize(self.tcx).is_none_or(|count| count > 1) {
176+
enforce_copy_bound(element, element_ty)
177+
} else {
178+
// If the length is 0 or 1 we don't actually copy the element, we either don't create it
179+
// or we just use the one value.
180+
}
178181
}
179-
// If the length is 0 or 1 we don't actually copy the element, we either don't create it
180-
// or we just use the one value.
181-
ty::ConstKind::Value(_) => (),
182182

183183
// If the length is a generic parameter or some rigid alias then conservatively
184184
// require `element_ty: Copy` as it may wind up being `>1` after monomorphization.

compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn typeck_with_inspect<'tcx>(
202202
// fallback arbitrarily inferring something incompatible with `Copy` inference side effects.
203203
//
204204
// This should also be forwards compatible with moving repeat expr checks to a custom goal kind or using
205-
// marker traits in the future.
205+
// marker traits in the future. FIXME(#140855).
206206
fcx.check_repeat_exprs();
207207

208208
fcx.type_inference_fallback();

0 commit comments

Comments
 (0)