Closed
Description
For this snippet (playground):
fn foo() -> String { String::new() }
fn main() {
let string_arr = [foo(); 64];
}
rustc gives:
error[E0277]: the trait bound `String: Copy` is not satisfied
--> src/main.rs:3:23
|
3 | let string_arr = [foo(); 64];
| ^^^^^ the trait `Copy` is not implemented for `String`
|
= note: the `Copy` trait is required because this value will be copied for each element of the array
Since #113912, for const-able values, rustc suggests the creation of a constant binding. Here this is not possible because foo
is not const fn. However, we can suggest array::from_fn
instead.