File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -487,6 +487,32 @@ fn const_refcell() {
487487 panic ! ( "should never be called" ) ;
488488 }
489489 }
490+
491+ // Check that `borrow` is usable at compile-time
492+ const BORROW_TEST : RefCell < u32 > = {
493+ let a = RefCell :: new ( 0 ) ;
494+ {
495+ assert ! ( a. try_borrow( ) . is_ok( ) ) ;
496+ assert ! ( a. try_borrow_mut( ) . is_ok( ) ) ;
497+ let _a = a. borrow ( ) ;
498+ assert ! ( a. try_borrow( ) . is_ok( ) ) ;
499+ assert ! ( a. try_borrow_mut( ) . is_err( ) ) ;
500+ }
501+ a
502+ } ;
503+ // Check that `borrow` is usable at compile-time
504+ const BORROW_MUT_TEST : RefCell < u32 > = {
505+ let a = RefCell :: new ( 0 ) ;
506+ {
507+ assert ! ( a. try_borrow( ) . is_ok( ) ) ;
508+ assert ! ( a. try_borrow_mut( ) . is_ok( ) ) ;
509+ let _a = a. borrow_mut ( ) ;
510+ assert ! ( a. try_borrow( ) . is_err( ) ) ;
511+ assert ! ( a. try_borrow_mut( ) . is_err( ) ) ;
512+ }
513+ a
514+ } ;
515+
490516 // Check that `replace` is usable at compile-time
491517 const REPLACE_TEST : u32 = {
492518 let a = RefCell :: new ( 0 ) ;
@@ -495,6 +521,7 @@ fn const_refcell() {
495521 assert ! ( a == 10 ) ;
496522 a
497523 } ;
524+ // Check that `replace` is usable at compile-time
498525 const REPLACE_DUMMY_TEST : RefCell < Dummy > = {
499526 let a = RefCell :: new ( Dummy ) ;
500527 forget ( a. replace ( Dummy ) ) ;
Original file line number Diff line number Diff line change 1515#![ feature( cell_update) ]
1616#![ feature( char_max_len) ]
1717#![ feature( clone_to_uninit) ]
18+ #![ feature( const_destruct) ]
1819#![ feature( const_eval_select) ]
1920#![ feature( const_ref_cell) ]
2021#![ feature( const_swap_nonoverlapping) ]
You can’t perform that action at this time.
0 commit comments