From fcf4bee7d3d69356a9eb702f9e0a9ddba238d33f Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 22 Nov 2019 10:45:49 -0800 Subject: [PATCH] Fix tests for RFC 2203 in a `const` The previous test was incorrect. `const fn`s are *always* promotable when inside a `const`, so it should pass. The error was caused by a bug in `promote_consts`. I've added a failing test outside a `const` alongside the existing one, which is now run-pass. --- .../const-fns.rs | 26 ------------------- .../fn-call-in-const.rs | 23 ++++++++++++++++ .../fn-call-in-non-const.rs | 18 +++++++++++++ ...fns.stderr => fn-call-in-non-const.stderr} | 6 ++--- 4 files changed, 44 insertions(+), 29 deletions(-) delete mode 100644 src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.rs create mode 100644 src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-const.rs create mode 100644 src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-non-const.rs rename src/test/ui/consts/rfc-2203-const-array-repeat-exprs/{const-fns.stderr => fn-call-in-non-const.stderr} (63%) diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.rs deleted file mode 100644 index 68a9227dea9..00000000000 --- a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.rs +++ /dev/null @@ -1,26 +0,0 @@ -// ignore-tidy-linelength -// ignore-compare-mode-nll -#![feature(const_in_array_repeat_expressions, nll)] -#![allow(warnings)] - -// Some type that is not copyable. -struct Bar; - -const fn type_no_copy() -> Option { - None -} - -const fn type_copy() -> u32 { - 3 -} - -fn no_copy() { - const ARR: [Option; 2] = [type_no_copy(); 2]; - //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied [E0277] -} - -fn copy() { - const ARR: [u32; 2] = [type_copy(); 2]; -} - -fn main() {} diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-const.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-const.rs new file mode 100644 index 00000000000..da1bae1be8d --- /dev/null +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-const.rs @@ -0,0 +1,23 @@ +// run-pass + +#![allow(unused)] +#![feature(const_in_array_repeat_expressions)] + +// Some type that is not copyable. +struct Bar; + +const fn type_no_copy() -> Option { + None +} + +const fn type_copy() -> u32 { + 3 +} + +const _: [u32; 2] = [type_copy(); 2]; + +// This is allowed because all promotion contexts use the explicit rules for promotability when +// inside an explicit const context. +const _: [Option; 2] = [type_no_copy(); 2]; + +fn main() {} diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-non-const.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-non-const.rs new file mode 100644 index 00000000000..38f744e99aa --- /dev/null +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-non-const.rs @@ -0,0 +1,18 @@ +#![feature(const_in_array_repeat_expressions)] + +// Some type that is not copyable. +struct Bar; + +const fn no_copy() -> Option { + None +} + +const fn copy() -> u32 { + 3 +} + +fn main() { + let _: [u32; 2] = [copy(); 2]; + let _: [Option; 2] = [no_copy(); 2]; + //~^ ERROR the trait bound `std::option::Option: std::marker::Copy` is not satisfied +} diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.stderr b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-non-const.stderr similarity index 63% rename from src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.stderr rename to src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-non-const.stderr index 82272af958a..8219d836a20 100644 --- a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.stderr +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-non-const.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `std::option::Option: std::marker::Copy` is not satisfied - --> $DIR/const-fns.rs:18:35 + --> $DIR/fn-call-in-non-const.rs:16:31 | -LL | const ARR: [Option; 2] = [type_no_copy(); 2]; - | ^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option` +LL | let _: [Option; 2] = [no_copy(); 2]; + | ^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option` | = help: the following implementations were found: as std::marker::Copy> -- 2.44.0