File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -1021,15 +1021,18 @@ impl<T: ?Sized> RefCell<T> {
10211021
10221022 /// Returns a mutable reference to the underlying data.
10231023 ///
1024- /// This call borrows `RefCell` mutably (at compile-time) so there is no
1025- /// need for dynamic checks.
1026- ///
1027- /// However be cautious: this method expects `self` to be mutable, which is
1028- /// generally not the case when using a `RefCell`. Take a look at the
1029- /// [`borrow_mut`] method instead if `self` isn't mutable.
1030- ///
1031- /// Also, please be aware that this method is only for special circumstances and is usually
1032- /// not what you want. In case of doubt, use [`borrow_mut`] instead.
1024+ /// Since this method borrows `RefCell` mutably, it is statically guaranteed
1025+ /// that no borrows to the underlying data exist. The dynamic checks inherent
1026+ /// in [`borrow_mut`] and most other methods of `RefCell` are therefor
1027+ /// unnecessary.
1028+ ///
1029+ /// This method can only be called if `RefCell` can be mutably borrowed,
1030+ /// which in general is only the case directly after the `RefCell` has
1031+ /// been created. In these situations, skipping the aforementioned dynamic
1032+ /// borrowing checks may yield better ergonomics and runtime-performance.
1033+ ///
1034+ /// In most situations where `RefCell` is used, it can't be borrowed mutably.
1035+ /// Use [`borrow_mut`] to get mutable access to the underlying data then.
10331036 ///
10341037 /// [`borrow_mut`]: RefCell::borrow_mut()
10351038 ///
You can’t perform that action at this time.
0 commit comments