@@ -108,8 +108,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
108
108
let deferred_repeat_expr_checks = deferred_repeat_expr_checks
109
109
. drain ( ..)
110
110
. 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.
113
114
match & element. kind {
114
115
hir:: ExprKind :: ConstBlock ( ..) => return None ,
115
116
hir:: ExprKind :: Path ( qpath) => {
@@ -121,23 +122,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
121
122
_ => { }
122
123
}
123
124
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.
127
129
let count = self
128
130
. structurally_resolve_const ( element. span , self . normalize ( element. span , count) ) ;
129
131
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.
132
135
if count. references_error ( ) {
133
136
return None ;
134
137
}
135
138
136
139
Some ( ( element, element_ty, count) )
137
140
} )
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
141
145
// expr's `Copy` check.
142
146
. collect :: < Vec < _ > > ( ) ;
143
147
@@ -171,14 +175,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
171
175
172
176
for ( element, element_ty, count) in deferred_repeat_expr_checks {
173
177
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
+ }
178
185
}
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 ( _) => ( ) ,
182
186
183
187
// If the length is a generic parameter or some rigid alias then conservatively
184
188
// require `element_ty: Copy` as it may wind up being `>1` after monomorphization.
0 commit comments