From a655438988c5f7d100a5423752b7ae0287d582fd Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 12 Jun 2019 08:46:56 +0100 Subject: [PATCH] tests: Update and add tests for RFC 2203. --- .../migrate-fail.rs | 26 +++++++++++++++++++ ...ll-borrowck.stderr => migrate-fail.stderr} | 4 +-- .../{migrate-borrowck.rs => migrate-pass.rs} | 17 +++--------- .../nll-fail.rs | 25 ++++++++++++++++++ ...igrate-borrowck.stderr => nll-fail.stderr} | 4 +-- .../{nll-borrowck.rs => nll-pass.rs} | 17 +++--------- .../run-pass.rs | 12 +++++++++ .../trait-error.rs | 10 +++++++ .../trait-error.stderr | 13 ++++++++++ 9 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-fail.rs rename src/test/ui/consts/rfc-2203-const-array-repeat-exprs/{nll-borrowck.stderr => migrate-fail.stderr} (94%) rename src/test/ui/consts/rfc-2203-const-array-repeat-exprs/{migrate-borrowck.rs => migrate-pass.rs} (85%) create mode 100644 src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-fail.rs rename src/test/ui/consts/rfc-2203-const-array-repeat-exprs/{migrate-borrowck.stderr => nll-fail.stderr} (93%) rename src/test/ui/consts/rfc-2203-const-array-repeat-exprs/{nll-borrowck.rs => nll-pass.rs} (85%) create mode 100644 src/test/ui/consts/rfc-2203-const-array-repeat-exprs/run-pass.rs create mode 100644 src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.rs create mode 100644 src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.stderr diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-fail.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-fail.rs new file mode 100644 index 000000000000..3b7d7e5b51a2 --- /dev/null +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-fail.rs @@ -0,0 +1,26 @@ +// ignore-tidy-linelength +// ignore-compare-mode-nll +// compile-flags: -Z borrowck=migrate +#![feature(const_in_array_repeat_expressions)] +#![allow(warnings)] + +// Some type that is not copyable. +struct Bar; + +mod non_constants { + use Bar; + + fn no_impl_copy_empty_value_multiple_elements() { + let x = None; + let arr: [Option; 2] = [x; 2]; + //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied [E0277] + } + + fn no_impl_copy_value_multiple_elements() { + let x = Some(Bar); + let arr: [Option; 2] = [x; 2]; + //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied [E0277] + } +} + +fn main() {} diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-borrowck.stderr b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-fail.stderr similarity index 94% rename from src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-borrowck.stderr rename to src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-fail.stderr index 0b2da5933a1c..aad6763f1509 100644 --- a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-borrowck.stderr +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-fail.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `std::option::Option: std::marker::Copy` is not satisfied - --> $DIR/nll-borrowck.rs:87:37 + --> $DIR/migrate-fail.rs:15:37 | LL | let arr: [Option; 2] = [x; 2]; | ^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option` @@ -9,7 +9,7 @@ LL | let arr: [Option; 2] = [x; 2]; = note: the `Copy` trait is required because the repeated element will be copied error[E0277]: the trait bound `std::option::Option: std::marker::Copy` is not satisfied - --> $DIR/nll-borrowck.rs:103:37 + --> $DIR/migrate-fail.rs:21:37 | LL | let arr: [Option; 2] = [x; 2]; | ^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option` diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-borrowck.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-pass.rs similarity index 85% rename from src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-borrowck.rs rename to src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-pass.rs index 5e7f11799c8a..bfa8ebcfdd32 100644 --- a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-borrowck.rs +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-pass.rs @@ -1,6 +1,7 @@ -// ignore-compile-mode-nll +// check-pass // compile-flags: -Z borrowck=migrate -#![feature(constants_in_array_repeat_expressions)] +// ignore-compare-mode-nll +#![feature(const_in_array_repeat_expressions)] #![allow(warnings)] // Some type that is not copyable. @@ -83,12 +84,6 @@ mod non_constants { let arr: [Option; 1] = [x; 1]; } - fn no_impl_copy_empty_value_multiple_elements() { - let x = None; - let arr: [Option; 2] = [x; 2]; - //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied [E0277] - } - fn no_impl_copy_value_no_elements() { let x = Some(Bar); let arr: [Option; 0] = [x; 0]; @@ -99,12 +94,6 @@ mod non_constants { let arr: [Option; 1] = [x; 1]; } - fn no_impl_copy_value_multiple_elements() { - let x = Some(Bar); - let arr: [Option; 2] = [x; 2]; - //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied [E0277] - } - fn impl_copy_empty_value_no_elements() { let x: Option = None; let arr: [Option; 0] = [x; 0]; diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-fail.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-fail.rs new file mode 100644 index 000000000000..dc1193a2fe8f --- /dev/null +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-fail.rs @@ -0,0 +1,25 @@ +// ignore-tidy-linelength +// ignore-compare-mode-nll +#![feature(const_in_array_repeat_expressions, nll)] +#![allow(warnings)] + +// Some type that is not copyable. +struct Bar; + +mod non_constants { + use Bar; + + fn no_impl_copy_empty_value_multiple_elements() { + let x = None; + let arr: [Option; 2] = [x; 2]; + //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied [E0277] + } + + fn no_impl_copy_value_multiple_elements() { + let x = Some(Bar); + let arr: [Option; 2] = [x; 2]; + //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied [E0277] + } +} + +fn main() {} diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-borrowck.stderr b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-fail.stderr similarity index 93% rename from src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-borrowck.stderr rename to src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-fail.stderr index 71f5a8ccaa22..fd32484ff92c 100644 --- a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/migrate-borrowck.stderr +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-fail.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `std::option::Option: std::marker::Copy` is not satisfied - --> $DIR/migrate-borrowck.rs:88:37 + --> $DIR/nll-fail.rs:14:37 | LL | let arr: [Option; 2] = [x; 2]; | ^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option` @@ -9,7 +9,7 @@ LL | let arr: [Option; 2] = [x; 2]; = note: the `Copy` trait is required because the repeated element will be copied error[E0277]: the trait bound `std::option::Option: std::marker::Copy` is not satisfied - --> $DIR/migrate-borrowck.rs:104:37 + --> $DIR/nll-fail.rs:20:37 | LL | let arr: [Option; 2] = [x; 2]; | ^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option` diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-borrowck.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-pass.rs similarity index 85% rename from src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-borrowck.rs rename to src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-pass.rs index 804aa6b7c6d7..a304f877ab7a 100644 --- a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-borrowck.rs +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-pass.rs @@ -1,6 +1,7 @@ -// ignore-compile-mode-nll +// check-pass +// ignore-compare-mode-nll #![allow(warnings)] -#![feature(constants_in_array_repeat_expressions, nll)] +#![feature(const_in_array_repeat_expressions, nll)] // Some type that is not copyable. struct Bar; @@ -82,12 +83,6 @@ mod non_constants { let arr: [Option; 1] = [x; 1]; } - fn no_impl_copy_empty_value_multiple_elements() { - let x = None; - let arr: [Option; 2] = [x; 2]; - //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied [E0277] - } - fn no_impl_copy_value_no_elements() { let x = Some(Bar); let arr: [Option; 0] = [x; 0]; @@ -98,12 +93,6 @@ mod non_constants { let arr: [Option; 1] = [x; 1]; } - fn no_impl_copy_value_multiple_elements() { - let x = Some(Bar); - let arr: [Option; 2] = [x; 2]; - //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied [E0277] - } - fn impl_copy_empty_value_no_elements() { let x: Option = None; let arr: [Option; 0] = [x; 0]; diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/run-pass.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/run-pass.rs new file mode 100644 index 000000000000..27bf5dabf566 --- /dev/null +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/run-pass.rs @@ -0,0 +1,12 @@ +// run-pass +#![feature(const_in_array_repeat_expressions)] + +#[derive(Debug, Eq, PartialEq)] +struct Bar; + +fn main() { + const FOO: Option = None; + const ARR: [Option; 2] = [FOO; 2]; + + assert_eq!(ARR, [None::, None::]); +} diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.rs new file mode 100644 index 000000000000..35484d265bb5 --- /dev/null +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.rs @@ -0,0 +1,10 @@ +// ignore-tidy-linelength +#![feature(const_in_array_repeat_expressions)] + +#[derive(Copy, Clone)] +struct Foo(T); + +fn main() { + [Foo(String::new()); 4]; + //~^ ERROR the trait bound `Foo: std::marker::Copy` is not satisfied [E0277] +} diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.stderr b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.stderr new file mode 100644 index 000000000000..186909e469e0 --- /dev/null +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.stderr @@ -0,0 +1,13 @@ +error[E0277]: the trait bound `Foo: std::marker::Copy` is not satisfied + --> $DIR/trait-error.rs:8:5 + | +LL | [Foo(String::new()); 4]; + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `Foo` + | + = help: the following implementations were found: + as std::marker::Copy> + = note: the `Copy` trait is required because the repeated element will be copied + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.