Skip to content

Commit fc2c1f8

Browse files
Make Option::unwrap unstably const
`Result::unwrap` is not eligible becuase it formats the contents of the `Err` variant. `unwrap_or`, `unwrap_or_else` and friends are not eligible because they drop things or invoke closures.
1 parent 6b09c37 commit fc2c1f8

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#![feature(const_fn_union)]
8383
#![feature(const_generics)]
8484
#![feature(const_option)]
85+
#![feature(const_precise_live_drops)]
8586
#![feature(const_ptr_offset)]
8687
#![feature(const_ptr_offset_from)]
8788
#![feature(const_raw_ptr_comparison)]

library/core/src/option.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ impl<T> Option<T> {
380380
#[inline]
381381
#[track_caller]
382382
#[stable(feature = "rust1", since = "1.0.0")]
383-
pub fn unwrap(self) -> T {
383+
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
384+
pub const fn unwrap(self) -> T {
384385
match self {
385386
Some(val) => val,
386387
None => panic!("called `Option::unwrap()` on a `None` value"),

0 commit comments

Comments
 (0)