File tree 4 files changed +37
-1
lines changed
4 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 81
81
#![ feature( const_fn_union) ]
82
82
#![ feature( const_generics) ]
83
83
#![ feature( const_option) ]
84
+ #![ feature( const_precise_live_drops) ]
84
85
#![ feature( const_ptr_offset) ]
85
86
#![ feature( const_ptr_offset_from) ]
86
87
#![ feature( const_raw_ptr_comparison) ]
Original file line number Diff line number Diff line change @@ -380,7 +380,8 @@ impl<T> Option<T> {
380
380
#[ inline]
381
381
#[ track_caller]
382
382
#[ 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 {
384
385
match self {
385
386
Some ( val) => val,
386
387
None => panic ! ( "called `Option::unwrap()` on a `None` value" ) ,
Original file line number Diff line number Diff line change
1
+ // check-fail
2
+
3
+ #![ feature( const_option) ]
4
+
5
+ const FOO : i32 = Some ( 42i32 ) . unwrap ( ) ;
6
+
7
+ // This causes an error, but it is attributed to the `panic` *inside* `Option::unwrap` (maybe due
8
+ // to `track_caller`?). A note points to the originating `const`.
9
+ const BAR : i32 = Option :: < i32 > :: None . unwrap ( ) ; //~ NOTE
10
+
11
+ fn main ( ) {
12
+ println ! ( "{}" , FOO ) ;
13
+ println ! ( "{}" , BAR ) ;
14
+ }
Original file line number Diff line number Diff line change
1
+ error: any use of this value will cause an error
2
+ --> $SRC_DIR/core/src/option.rs:LL:COL
3
+ |
4
+ LL | None => panic!("called `Option::unwrap()` on a `None` value"),
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
+ | |
7
+ | the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:9:38
8
+ | inside `std::option::Option::<i32>::unwrap` at $SRC_DIR/core/src/macros/mod.rs:LL:COL
9
+ | inside `BAR` at $DIR/const-unwrap.rs:9:18
10
+ |
11
+ ::: $DIR/const-unwrap.rs:9:1
12
+ |
13
+ LL | const BAR: i32 = Option::<i32>::None.unwrap();
14
+ | ----------------------------------------------
15
+ |
16
+ = note: `#[deny(const_err)]` on by default
17
+ = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
18
+
19
+ error: aborting due to previous error
20
+
You can’t perform that action at this time.
0 commit comments