added a suggestion to create a const item if the fn in the array repeat expression is a const fn

This commit is contained in:
Henry Boisdequin 2021-01-29 11:54:19 +05:30
parent 368275062f
commit c2e849c022
7 changed files with 87 additions and 4 deletions

View file

@ -7,6 +7,7 @@ LL | let _: [Option<Bar>; 2] = [no_copy(); 2];
= help: the following implementations were found:
<Option<T> as Copy>
= note: the `Copy` trait is required because the repeated element will be copied
= help: create an inline `const` block, see PR #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
error: aborting due to previous error

View file

@ -0,0 +1,7 @@
fn main() {
// should hint to create an inline const block
// as all tests are on "nightly"
let strings: [String; 5] = [String::new(); 5];
//~^ ERROR the trait bound `String: Copy` is not satisfied
println!("{:?}", strings);
}

View file

@ -0,0 +1,12 @@
error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/const-fn-in-vec.rs:4:32
|
LL | let strings: [String; 5] = [String::new(); 5];
| ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
= note: the `Copy` trait is required because the repeated element will be copied
= help: create an inline `const` block, see PR #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.