diff options
| author | Henry Boisdequin <65845077+henryboisdequin@users.noreply.github.com> | 2021-01-29 11:54:19 +0530 |
|---|---|---|
| committer | Henry Boisdequin <65845077+henryboisdequin@users.noreply.github.com> | 2021-02-03 10:18:08 +0530 |
| commit | c2e849c0221bbaf1106884cd776e375168a95323 (patch) | |
| tree | 2817749464cf18a0471f6333e0457576889aa433 /src | |
| parent | 368275062fb655c1f36e0398f88b15379a1f3c93 (diff) | |
added a suggestion to create a `const` item if the `fn` in the array repeat expression is a `const fn`
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr | 1 | ||||
| -rw-r--r-- | src/test/ui/consts/const-fn-in-vec.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/consts/const-fn-in-vec.stderr | 12 |
3 files changed, 20 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr b/src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr index b75452cd217..661f279e6be 100644 --- a/src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr +++ b/src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr @@ -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 diff --git a/src/test/ui/consts/const-fn-in-vec.rs b/src/test/ui/consts/const-fn-in-vec.rs new file mode 100644 index 00000000000..edf29015200 --- /dev/null +++ b/src/test/ui/consts/const-fn-in-vec.rs @@ -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); +} diff --git a/src/test/ui/consts/const-fn-in-vec.stderr b/src/test/ui/consts/const-fn-in-vec.stderr new file mode 100644 index 00000000000..c477605842d --- /dev/null +++ b/src/test/ui/consts/const-fn-in-vec.stderr @@ -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`. |
