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() {
487
487
panic ! ( "should never be called" ) ;
488
488
}
489
489
}
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
+
490
516
// Check that `replace` is usable at compile-time
491
517
const REPLACE_TEST : u32 = {
492
518
let a = RefCell :: new ( 0 ) ;
@@ -495,6 +521,7 @@ fn const_refcell() {
495
521
assert ! ( a == 10 ) ;
496
522
a
497
523
} ;
524
+ // Check that `replace` is usable at compile-time
498
525
const REPLACE_DUMMY_TEST : RefCell < Dummy > = {
499
526
let a = RefCell :: new ( Dummy ) ;
500
527
forget ( a. replace ( Dummy ) ) ;
Original file line number Diff line number Diff line change 15
15
#![ feature( cell_update) ]
16
16
#![ feature( char_max_len) ]
17
17
#![ feature( clone_to_uninit) ]
18
+ #![ feature( const_destruct) ]
18
19
#![ feature( const_eval_select) ]
19
20
#![ feature( const_ref_cell) ]
20
21
#![ feature( const_swap_nonoverlapping) ]
You can’t perform that action at this time.
0 commit comments