diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-04-11 16:38:48 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-04-28 09:19:42 +0000 |
| commit | 4e6e68e27a36f38da58dcbadd31c8f5d591f4571 (patch) | |
| tree | 84f8ff6144bbf8a8eda76939ca8994d61341b4c9 /src/test/ui/consts | |
| parent | 0e7915d11f6888f005e78c2358fcdc48ff655753 (diff) | |
| download | rust-4e6e68e27a36f38da58dcbadd31c8f5d591f4571.tar.gz rust-4e6e68e27a36f38da58dcbadd31c8f5d591f4571.zip | |
Check that repeat expression elements are Copy (ignoring lifetimes) in typeck and that they are Copy (with proper lifetime checks) in borrowck
Diffstat (limited to 'src/test/ui/consts')
| -rw-r--r-- | src/test/ui/consts/const-blocks/fn-call-in-non-const.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/consts/const-blocks/fn-call-in-non-const.stderr | 12 | ||||
| -rw-r--r-- | src/test/ui/consts/const-blocks/migrate-fail.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/consts/const-blocks/migrate-fail.stderr | 24 | ||||
| -rw-r--r-- | src/test/ui/consts/const-blocks/nll-fail.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/consts/const-blocks/nll-fail.stderr | 24 | ||||
| -rw-r--r-- | src/test/ui/consts/const-blocks/trait-error.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/consts/const-blocks/trait-error.stderr | 15 | ||||
| -rw-r--r-- | src/test/ui/consts/const-fn-in-vec.stderr | 4 |
9 files changed, 59 insertions, 32 deletions
diff --git a/src/test/ui/consts/const-blocks/fn-call-in-non-const.rs b/src/test/ui/consts/const-blocks/fn-call-in-non-const.rs index 19217843759..18b4dc714de 100644 --- a/src/test/ui/consts/const-blocks/fn-call-in-non-const.rs +++ b/src/test/ui/consts/const-blocks/fn-call-in-non-const.rs @@ -12,5 +12,5 @@ const fn copy() -> u32 { fn main() { let _: [u32; 2] = [copy(); 2]; let _: [Option<Bar>; 2] = [no_copy(); 2]; - //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied + //~^ ERROR the trait bound `Bar: Copy` is not satisfied } 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 52a1669e330..ef05f723aca 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 @@ -1,13 +1,17 @@ -error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied - --> $DIR/fn-call-in-non-const.rs:14:31 +error[E0277]: the trait bound `Bar: Copy` is not satisfied + --> $DIR/fn-call-in-non-const.rs:14:32 | LL | let _: [Option<Bar>; 2] = [no_copy(); 2]; - | ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Option<Bar>` + | ^^^^^^^^^ the trait `Copy` is not implemented for `Bar` | - = help: the trait `Copy` is implemented for `Option<T>` + = note: required because of the requirements on the impl of `Copy` for `Option<Bar>` = note: the `Copy` trait is required because the repeated element will be copied = help: consider creating a new `const` item and initializing it with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];` = help: create an inline `const` block, see RFC #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information +help: consider annotating `Bar` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to previous error diff --git a/src/test/ui/consts/const-blocks/migrate-fail.rs b/src/test/ui/consts/const-blocks/migrate-fail.rs index bb12139a7ba..d5a17249cc9 100644 --- a/src/test/ui/consts/const-blocks/migrate-fail.rs +++ b/src/test/ui/consts/const-blocks/migrate-fail.rs @@ -11,13 +11,13 @@ mod non_constants { fn no_impl_copy_empty_value_multiple_elements() { let x = None; let arr: [Option<Bar>; 2] = [x; 2]; - //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277] + //~^ ERROR the trait bound `Bar: Copy` is not satisfied [E0277] } fn no_impl_copy_value_multiple_elements() { let x = Some(Bar); let arr: [Option<Bar>; 2] = [x; 2]; - //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277] + //~^ ERROR the trait bound `Bar: Copy` is not satisfied [E0277] } } diff --git a/src/test/ui/consts/const-blocks/migrate-fail.stderr b/src/test/ui/consts/const-blocks/migrate-fail.stderr index 318fec60290..1898ab3b469 100644 --- a/src/test/ui/consts/const-blocks/migrate-fail.stderr +++ b/src/test/ui/consts/const-blocks/migrate-fail.stderr @@ -1,20 +1,28 @@ -error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied - --> $DIR/migrate-fail.rs:13:37 +error[E0277]: the trait bound `Bar: Copy` is not satisfied + --> $DIR/migrate-fail.rs:13:38 | LL | let arr: [Option<Bar>; 2] = [x; 2]; - | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>` + | ^ the trait `Copy` is not implemented for `Bar` | - = help: the trait `Copy` is implemented for `Option<T>` + = note: required because of the requirements on the impl of `Copy` for `Option<Bar>` = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Bar` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | -error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied - --> $DIR/migrate-fail.rs:19:37 +error[E0277]: the trait bound `Bar: Copy` is not satisfied + --> $DIR/migrate-fail.rs:19:38 | LL | let arr: [Option<Bar>; 2] = [x; 2]; - | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>` + | ^ the trait `Copy` is not implemented for `Bar` | - = help: the trait `Copy` is implemented for `Option<T>` + = note: required because of the requirements on the impl of `Copy` for `Option<Bar>` = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Bar` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/const-blocks/nll-fail.rs b/src/test/ui/consts/const-blocks/nll-fail.rs index 871387c1fd0..9d4aef39e54 100644 --- a/src/test/ui/consts/const-blocks/nll-fail.rs +++ b/src/test/ui/consts/const-blocks/nll-fail.rs @@ -10,13 +10,13 @@ mod non_constants { fn no_impl_copy_empty_value_multiple_elements() { let x = None; let arr: [Option<Bar>; 2] = [x; 2]; - //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277] + //~^ ERROR the trait bound `Bar: Copy` is not satisfied [E0277] } fn no_impl_copy_value_multiple_elements() { let x = Some(Bar); let arr: [Option<Bar>; 2] = [x; 2]; - //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277] + //~^ ERROR the trait bound `Bar: Copy` is not satisfied [E0277] } } diff --git a/src/test/ui/consts/const-blocks/nll-fail.stderr b/src/test/ui/consts/const-blocks/nll-fail.stderr index 5a34361aa83..3201a1e68e8 100644 --- a/src/test/ui/consts/const-blocks/nll-fail.stderr +++ b/src/test/ui/consts/const-blocks/nll-fail.stderr @@ -1,20 +1,28 @@ -error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied - --> $DIR/nll-fail.rs:12:37 +error[E0277]: the trait bound `Bar: Copy` is not satisfied + --> $DIR/nll-fail.rs:12:38 | LL | let arr: [Option<Bar>; 2] = [x; 2]; - | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>` + | ^ the trait `Copy` is not implemented for `Bar` | - = help: the trait `Copy` is implemented for `Option<T>` + = note: required because of the requirements on the impl of `Copy` for `Option<Bar>` = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Bar` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | -error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied - --> $DIR/nll-fail.rs:18:37 +error[E0277]: the trait bound `Bar: Copy` is not satisfied + --> $DIR/nll-fail.rs:18:38 | LL | let arr: [Option<Bar>; 2] = [x; 2]; - | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>` + | ^ the trait `Copy` is not implemented for `Bar` | - = help: the trait `Copy` is implemented for `Option<T>` + = note: required because of the requirements on the impl of `Copy` for `Option<Bar>` = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Bar` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/const-blocks/trait-error.rs b/src/test/ui/consts/const-blocks/trait-error.rs index 5a614cbdd15..49d1e9b9434 100644 --- a/src/test/ui/consts/const-blocks/trait-error.rs +++ b/src/test/ui/consts/const-blocks/trait-error.rs @@ -3,5 +3,5 @@ struct Foo<T>(T); fn main() { [Foo(String::new()); 4]; - //~^ ERROR the trait bound `Foo<String>: Copy` is not satisfied [E0277] + //~^ ERROR the trait bound `String: Copy` is not satisfied [E0277] } diff --git a/src/test/ui/consts/const-blocks/trait-error.stderr b/src/test/ui/consts/const-blocks/trait-error.stderr index 6979ff36176..8a6ca61e0c5 100644 --- a/src/test/ui/consts/const-blocks/trait-error.stderr +++ b/src/test/ui/consts/const-blocks/trait-error.stderr @@ -1,11 +1,18 @@ -error[E0277]: the trait bound `Foo<String>: Copy` is not satisfied - --> $DIR/trait-error.rs:5:5 +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/trait-error.rs:5:6 | LL | [Foo(String::new()); 4]; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Foo<String>` + | ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | - = help: the trait `Copy` is implemented for `Foo<T>` +note: required because of the requirements on the impl of `Copy` for `Foo<String>` + --> $DIR/trait-error.rs:1:10 + | +LL | #[derive(Copy, Clone)] + | ^^^^ = note: the `Copy` trait is required because the repeated element will be copied + = help: consider creating a new `const` item and initializing it with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];` + = help: create an inline `const` block, see RFC #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information + = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/consts/const-fn-in-vec.stderr b/src/test/ui/consts/const-fn-in-vec.stderr index f02cb4f1ff1..0572dda7470 100644 --- a/src/test/ui/consts/const-fn-in-vec.stderr +++ b/src/test/ui/consts/const-fn-in-vec.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/const-fn-in-vec.rs:4:32 + --> $DIR/const-fn-in-vec.rs:4:33 | LL | let strings: [String; 5] = [String::new(); 5]; - | ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + | ^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | = note: the `Copy` trait is required because the repeated element will be copied = help: consider creating a new `const` item and initializing it with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];` |
