Skip to content

Commit 484a39a

Browse files
test const Ref[Mut]
1 parent 0fdc84a commit 484a39a

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

library/core/src/cell.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,8 @@ pub struct Ref<'b, T: ?Sized + 'b> {
15021502
}
15031503

15041504
#[stable(feature = "rust1", since = "1.0.0")]
1505-
impl<T: ?Sized> Deref for Ref<'_, T> {
1505+
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
1506+
impl<T: ?Sized> const Deref for Ref<'_, T> {
15061507
type Target = T;
15071508

15081509
#[inline]

library/coretests/tests/cell.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -494,22 +494,27 @@ fn const_refcell() {
494494
{
495495
assert!(a.try_borrow().is_ok());
496496
assert!(a.try_borrow_mut().is_ok());
497-
let _a = a.borrow();
497+
let a_ref = a.borrow();
498+
assert!(*a_ref == 0);
498499
assert!(a.try_borrow().is_ok());
499500
assert!(a.try_borrow_mut().is_err());
500501
}
501502
a
502503
};
503504
// Check that `borrow_mut` is usable at compile-time
504505
const BORROW_MUT_TEST: RefCell<u32> = {
505-
let a = RefCell::new(0);
506+
let mut a = RefCell::new(0);
506507
{
507508
assert!(a.try_borrow().is_ok());
508509
assert!(a.try_borrow_mut().is_ok());
509-
let _a = a.borrow_mut();
510+
let mut a_ref = a.borrow_mut();
511+
assert!(*a_ref == 0);
512+
*a_ref = 10;
513+
assert!(*a_ref == 10);
510514
assert!(a.try_borrow().is_err());
511515
assert!(a.try_borrow_mut().is_err());
512516
}
517+
assert!(*a.get_mut() == 10);
513518
a
514519
};
515520

library/coretests/tests/lib.rs

+1
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_deref)]
1819
#![feature(const_destruct)]
1920
#![feature(const_eval_select)]
2021
#![feature(const_ref_cell)]

0 commit comments

Comments
 (0)