diff options
| author | bors <bors@rust-lang.org> | 2020-07-31 08:26:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-07-31 08:26:33 +0000 |
| commit | 3a92b9987abd01c4b7e59c870e85beb9dd4d4aa2 (patch) | |
| tree | 7899dba3d40d3347bf27278f4ed655c0ab63078b /src | |
| parent | ac91673d895a0c578ed773e1280bdde8adb87b8c (diff) | |
| parent | 96c84ac3cbc4f2c81580893dacf263d00306649c (diff) | |
| download | rust-3a92b9987abd01c4b7e59c870e85beb9dd4d4aa2.tar.gz rust-3a92b9987abd01c4b7e59c870e85beb9dd4d4aa2.zip | |
Auto merge of #74956 - ecstatic-morse:const-option-unwrap, r=oli-obk
Make `Option::unwrap` unstably const This is lumped into the `const_option` feature gate (#67441), which enables a potpourri of `Option` methods. cc @rust-lang/wg-const-eval r? @oli-obk
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/consts/const-unwrap.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/consts/const-unwrap.stderr | 20 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-unwrap.rs b/src/test/ui/consts/const-unwrap.rs new file mode 100644 index 00000000000..6ed60ed87bf --- /dev/null +++ b/src/test/ui/consts/const-unwrap.rs @@ -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); +} diff --git a/src/test/ui/consts/const-unwrap.stderr b/src/test/ui/consts/const-unwrap.stderr new file mode 100644 index 00000000000..7f2c1f41510 --- /dev/null +++ b/src/test/ui/consts/const-unwrap.stderr @@ -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 + |
