Skip to content

Commit fa9ba3e

Browse files
add borrow tests
1 parent c6fb9c7 commit fa9ba3e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

library/coretests/tests/cell.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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));

library/coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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)]

0 commit comments

Comments
 (0)