File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed 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