Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize, bless and add tests for const control flow
This creates a new test directory, `ui/consts/control-flow` to hold tests related to control flow in a const context. It also blesses all existing tests with the new error messages, and adds new tests for the `const_if_match` feature.
- Loading branch information
1 parent
26d93f3
commit 5c377f3
Showing
49 changed files
with
1,180 additions
and
308 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
error[E0744]: `match` is not allowed in a `static` | ||
error[E0658]: `match` is not allowed in a `static` | ||
--> $DIR/issue-64453.rs:4:31 | ||
| | ||
LL | static settings_dir: String = format!(""); | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/49146 | ||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable | ||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0744`. | ||
For more information about this error, try `rustc --explain E0658`. |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/assert.rs:12:15 | ||
| | ||
LL | const _: () = assert!(false); | ||
| --------------^^^^^^^^^^^^^^- | ||
| | | ||
| the evaluated program panicked at 'assertion failed: false', $DIR/assert.rs:12:15 | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|
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,23 @@ | ||
error[E0658]: panicking in constants is unstable | ||
--> $DIR/assert.rs:8:15 | ||
| | ||
LL | const _: () = assert!(true); | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/51999 | ||
= help: add `#![feature(const_panic)]` to the crate attributes to enable | ||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) | ||
|
||
error[E0658]: panicking in constants is unstable | ||
--> $DIR/assert.rs:12:15 | ||
| | ||
LL | const _: () = assert!(false); | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/51999 | ||
= help: add `#![feature(const_panic)]` to the crate attributes to enable | ||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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,21 @@ | ||
error[E0658]: `if` is not allowed in a `const` | ||
--> $DIR/assert.rs:8:15 | ||
| | ||
LL | const _: () = assert!(true); | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/49146 | ||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable | ||
|
||
error[E0658]: `if` is not allowed in a `const` | ||
--> $DIR/assert.rs:12:15 | ||
| | ||
LL | const _: () = assert!(false); | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/49146 | ||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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,17 @@ | ||
// Test that `assert` works only when both `const_if_match` and `const_panic` are enabled. | ||
|
||
// revisions: stock if_match panic both | ||
|
||
#![cfg_attr(any(both, if_match), feature(const_if_match))] | ||
#![cfg_attr(any(both, panic), feature(const_panic))] | ||
|
||
const _: () = assert!(true); | ||
//[stock,panic]~^ ERROR `if` is not allowed in a `const` | ||
//[if_match]~^^ ERROR panicking in constants is unstable | ||
|
||
const _: () = assert!(false); | ||
//[stock,panic]~^ ERROR `if` is not allowed in a `const` | ||
//[if_match]~^^ ERROR panicking in constants is unstable | ||
//[both]~^^^ ERROR any use of this value will cause an error | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0658]: `if` is not allowed in a `const` | ||
--> $DIR/assert.rs:8:15 | ||
| | ||
LL | const _: () = assert!(true); | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/49146 | ||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable | ||
|
||
error[E0658]: `if` is not allowed in a `const` | ||
--> $DIR/assert.rs:12:15 | ||
| | ||
LL | const _: () = assert!(false); | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/49146 | ||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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,43 @@ | ||
// Test basic functionality of `if` and `match` in a const context. | ||
|
||
// run-pass | ||
|
||
#![feature(const_panic)] | ||
#![feature(const_if_match)] | ||
|
||
const X: u32 = 4; | ||
const Y: u32 = 5; | ||
|
||
const ABS_DIFF: u32 = if X < Y { | ||
Y - X | ||
} else { | ||
X - Y | ||
}; | ||
|
||
const fn abs_diff(a: u32, b: u32) -> u32 { | ||
match (a, b) { | ||
(big, little) if big > little => big - little, | ||
(little, big) => big - little, | ||
} | ||
} | ||
|
||
const fn gcd(a: u32, b: u32) -> u32 { | ||
if b == 0 { | ||
return a; | ||
} | ||
|
||
gcd(b, a % b) | ||
} | ||
|
||
fn main() { | ||
const _: () = assert!(abs_diff(4, 5) == abs_diff(5, 4)); | ||
assert_eq!(abs_diff(4, 5), abs_diff(5, 4)); | ||
|
||
const _: () = assert!(ABS_DIFF == abs_diff(5, 4)); | ||
assert_eq!(ABS_DIFF, abs_diff(5, 4)); | ||
|
||
const _: () = assert!(gcd(48, 18) == 6); | ||
const _: () = assert!(gcd(18, 48) == 6); | ||
assert_eq!(gcd(48, 18), 6); | ||
assert_eq!(gcd(18, 48), 6); | ||
} |
Oops, something went wrong.