Skip to content

Commit fcf4bee

Browse files
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.
1 parent 53712f8 commit fcf4bee

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.rs

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-pass
2+
3+
#![allow(unused)]
4+
#![feature(const_in_array_repeat_expressions)]
5+
6+
// Some type that is not copyable.
7+
struct Bar;
8+
9+
const fn type_no_copy() -> Option<Bar> {
10+
None
11+
}
12+
13+
const fn type_copy() -> u32 {
14+
3
15+
}
16+
17+
const _: [u32; 2] = [type_copy(); 2];
18+
19+
// This is allowed because all promotion contexts use the explicit rules for promotability when
20+
// inside an explicit const context.
21+
const _: [Option<Bar>; 2] = [type_no_copy(); 2];
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(const_in_array_repeat_expressions)]
2+
3+
// Some type that is not copyable.
4+
struct Bar;
5+
6+
const fn no_copy() -> Option<Bar> {
7+
None
8+
}
9+
10+
const fn copy() -> u32 {
11+
3
12+
}
13+
14+
fn main() {
15+
let _: [u32; 2] = [copy(); 2];
16+
let _: [Option<Bar>; 2] = [no_copy(); 2];
17+
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied
18+
}

src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.stderr renamed to src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-non-const.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied
2-
--> $DIR/const-fns.rs:18:35
2+
--> $DIR/fn-call-in-non-const.rs:16:31
33
|
4-
LL | const ARR: [Option<Bar>; 2] = [type_no_copy(); 2];
5-
| ^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<Bar>`
4+
LL | let _: [Option<Bar>; 2] = [no_copy(); 2];
5+
| ^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<Bar>`
66
|
77
= help: the following implementations were found:
88
<std::option::Option<T> as std::marker::Copy>

0 commit comments

Comments
 (0)