-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add tests that use const fns.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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() {} |
13 changes: 13 additions & 0 deletions
13
src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error[E0277]: the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied | ||
--> $DIR/const-fns.rs:18:35 | ||
| | ||
LL | const ARR: [Option<Bar>; 2] = [type_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> | ||
= 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`. |