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.
This commit is contained in:
parent
53712f8637
commit
fcf4bee7d3
4 changed files with 44 additions and 29 deletions
|
@ -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<Bar> {
|
||||
None
|
||||
}
|
||||
|
||||
const fn type_copy() -> u32 {
|
||||
3
|
||||
}
|
||||
|
||||
fn no_copy() {
|
||||
const ARR: [Option<Bar>; 2] = [type_no_copy(); 2];
|
||||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied [E0277]
|
||||
}
|
||||
|
||||
fn copy() {
|
||||
const ARR: [u32; 2] = [type_copy(); 2];
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -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<Bar> {
|
||||
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<Bar>; 2] = [type_no_copy(); 2];
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,18 @@
|
|||
#![feature(const_in_array_repeat_expressions)]
|
||||
|
||||
// Some type that is not copyable.
|
||||
struct Bar;
|
||||
|
||||
const fn no_copy() -> Option<Bar> {
|
||||
None
|
||||
}
|
||||
|
||||
const fn copy() -> u32 {
|
||||
3
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _: [u32; 2] = [copy(); 2];
|
||||
let _: [Option<Bar>; 2] = [no_copy(); 2];
|
||||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
error[E0277]: the trait bound `std::option::Option<Bar>: 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<Bar>; 2] = [type_no_copy(); 2];
|
||||
| ^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<Bar>`
|
||||
LL | let _: [Option<Bar>; 2] = [no_copy(); 2];
|
||||
| ^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<Bar>`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<std::option::Option<T> as std::marker::Copy>
|
Loading…
Add table
Add a link
Reference in a new issue