Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Update and add tests for RFC 2203.
- Loading branch information
Showing
9 changed files
with
96 additions
and
32 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/migrate-fail.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 | ||
// 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<Bar>; 2] = [x; 2]; | ||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied [E0277] | ||
} | ||
|
||
fn no_impl_copy_value_multiple_elements() { | ||
let x = Some(Bar); | ||
let arr: [Option<Bar>; 2] = [x; 2]; | ||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied [E0277] | ||
} | ||
} | ||
|
||
fn main() {} |
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
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
25 changes: 25 additions & 0 deletions
25
src/test/ui/consts/rfc-2203-const-array-repeat-exprs/nll-fail.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,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<Bar>; 2] = [x; 2]; | ||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied [E0277] | ||
} | ||
|
||
fn no_impl_copy_value_multiple_elements() { | ||
let x = Some(Bar); | ||
let arr: [Option<Bar>; 2] = [x; 2]; | ||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied [E0277] | ||
} | ||
} | ||
|
||
fn main() {} |
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
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
12 changes: 12 additions & 0 deletions
12
src/test/ui/consts/rfc-2203-const-array-repeat-exprs/run-pass.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,12 @@ | ||
// run-pass | ||
#![feature(const_in_array_repeat_expressions)] | ||
|
||
#[derive(Debug, Eq, PartialEq)] | ||
struct Bar; | ||
|
||
fn main() { | ||
const FOO: Option<Bar> = None; | ||
const ARR: [Option<Bar>; 2] = [FOO; 2]; | ||
|
||
assert_eq!(ARR, [None::<Bar>, None::<Bar>]); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.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,10 @@ | ||
// ignore-tidy-linelength | ||
#![feature(const_in_array_repeat_expressions)] | ||
|
||
#[derive(Copy, Clone)] | ||
struct Foo<T>(T); | ||
|
||
fn main() { | ||
[Foo(String::new()); 4]; | ||
//~^ ERROR the trait bound `Foo<std::string::String>: std::marker::Copy` is not satisfied [E0277] | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/ui/consts/rfc-2203-const-array-repeat-exprs/trait-error.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 `Foo<std::string::String>: 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<std::string::String>` | ||
| | ||
= help: the following implementations were found: | ||
<Foo<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`. |