@@ -108,8 +108,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
108108 let deferred_repeat_expr_checks = deferred_repeat_expr_checks
109109 . drain ( ..)
110110 . flat_map ( |( element, element_ty, count) | {
111- // Actual constants as the repeat element get inserted repeatedly instead of getting copied via Copy
112- // so we don't need to attempt to structurally resolve the repeat count which may unnecessarily error.
111+ // Actual constants as the repeat element are inserted repeatedly instead
112+ // of being copied via `Copy`, so we don't need to attempt to structurally
113+ // resolve the repeat count which may unnecessarily error.
113114 match & element. kind {
114115 hir:: ExprKind :: ConstBlock ( ..) => return None ,
115116 hir:: ExprKind :: Path ( qpath) => {
@@ -121,23 +122,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
121122 _ => { }
122123 }
123124
124- // 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
126- // to something that never required `Copy` in the first place.
125+ // We want to emit an error if the const is not structurally resolveable
126+ // as otherwise we can wind up conservatively proving `Copy` which may
127+ // infer the repeat expr count to something that never required `Copy` in
128+ // the first place.
127129 let count = self
128130 . structurally_resolve_const ( element. span , self . normalize ( element. span , count) ) ;
129131
130- // Avoid run on "`NotCopy: Copy` is not implemented" errors when the repeat expr count
131- // is erroneous/unknown. The user might wind up specifying a repeat count of 0/1.
132+ // Avoid run on "`NotCopy: Copy` is not implemented" errors when the
133+ // repeat expr count is erroneous/unknown. The user might wind up
134+ // specifying a repeat count of 0/1.
132135 if count. references_error ( ) {
133136 return None ;
134137 }
135138
136139 Some ( ( element, element_ty, count) )
137140 } )
138- // We collect to force the side effects of structurally resolving the repeat count to happen in one
139- // go, to avoid side effects from proving `Copy` affecting whether repeat counts are known or not.
140- // If we did not do this we would get results that depend on the order that we evaluate each repeat
141+ // We collect to force the side effects of structurally resolving the repeat
142+ // count to happen in one go, to avoid side effects from proving `Copy`
143+ // affecting whether repeat counts are known or not. If we did not do this we
144+ // would get results that depend on the order that we evaluate each repeat
141145 // expr's `Copy` check.
142146 . collect :: < Vec < _ > > ( ) ;
143147
@@ -171,14 +175,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
171175
172176 for ( element, element_ty, count) in deferred_repeat_expr_checks {
173177 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)
178+ ty:: ConstKind :: Value ( val) => {
179+ if val. try_to_target_usize ( self . tcx ) . is_none_or ( |count| count > 1 ) {
180+ enforce_copy_bound ( element, element_ty)
181+ } else {
182+ // If the length is 0 or 1 we don't actually copy the element, we either don't create it
183+ // or we just use the one value.
184+ }
178185 }
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 ( _) => ( ) ,
182186
183187 // If the length is a generic parameter or some rigid alias then conservatively
184188 // require `element_ty: Copy` as it may wind up being `>1` after monomorphization.
0 commit comments