-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test
Option::unwrap
in a const context
- Loading branch information
1 parent
fc2c1f8
commit 96c84ac
Showing
2 changed files
with
34 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// check-fail | ||
|
||
#![feature(const_option)] | ||
|
||
const FOO: i32 = Some(42i32).unwrap(); | ||
|
||
// This causes an error, but it is attributed to the `panic` *inside* `Option::unwrap` (maybe due | ||
// to `track_caller`?). A note points to the originating `const`. | ||
const BAR: i32 = Option::<i32>::None.unwrap(); //~ NOTE | ||
|
||
fn main() { | ||
println!("{}", FOO); | ||
println!("{}", BAR); | ||
} |
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,20 @@ | ||
error: any use of this value will cause an error | ||
--> $SRC_DIR/core/src/option.rs:LL:COL | ||
| | ||
LL | None => panic!("called `Option::unwrap()` on a `None` value"), | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:9:38 | ||
| inside `std::option::Option::<i32>::unwrap` at $SRC_DIR/core/src/macros/mod.rs:LL:COL | ||
| inside `BAR` at $DIR/const-unwrap.rs:9:18 | ||
| | ||
::: $DIR/const-unwrap.rs:9:1 | ||
| | ||
LL | const BAR: i32 = Option::<i32>::None.unwrap(); | ||
| ---------------------------------------------- | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|