Skip to content

Commit e0f5df0

Browse files
committedMar 15, 2020
Auto merge of #70024 - Centril:rollup-cppmaxr, r=Centril
Rollup of 8 pull requests Successful merges: - #69528 (Add undo_leak to reset RefCell borrow state) - #69589 (ast: `Mac`/`Macro` -> `MacCall`) - #69661 (Implement From<&mut str> for String) - #69988 (rustc_metadata: Remove `rmeta::MacroDef`) - #70006 (resolve: Fix two issues in fresh binding disambiguation) - #70011 (def_collector: Fully visit async functions) - #70013 (Return feature gate as a `Symbol` ) - #70018 (Fix "since" field for `Once::is_complete`'s `#[stable]` attribute) Failed merges: r? @ghost
2 parents 5da2e53 + bde77af commit e0f5df0

File tree

65 files changed

+459
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+459
-377
lines changed
 

‎src/liballoc/string.rs

+11
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,17 @@ impl From<&str> for String {
22252225
}
22262226
}
22272227

2228+
#[stable(feature = "from_mut_str_for_string", since = "1.44.0")]
2229+
impl From<&mut str> for String {
2230+
/// Converts a `&mut str` into a `String`.
2231+
///
2232+
/// The result is allocated on the heap.
2233+
#[inline]
2234+
fn from(s: &mut str) -> String {
2235+
s.to_owned()
2236+
}
2237+
}
2238+
22282239
#[stable(feature = "from_ref_string", since = "1.35.0")]
22292240
impl From<&String> for String {
22302241
#[inline]

‎src/libcore/cell.rs

+36-5
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,33 @@ impl<T: ?Sized> RefCell<T> {
958958
unsafe { &mut *self.value.get() }
959959
}
960960

961+
/// Undo the effect of leaked guards on the borrow state of the `RefCell`.
962+
///
963+
/// This call is similar to [`get_mut`] but more specialized. It borrows `RefCell` mutably to
964+
/// ensure no borrows exist and then resets the state tracking shared borrows. This is relevant
965+
/// if some `Ref` or `RefMut` borrows have been leaked.
966+
///
967+
/// [`get_mut`]: #method.get_mut
968+
///
969+
/// # Examples
970+
///
971+
/// ```
972+
/// #![feature(cell_leak)]
973+
/// use std::cell::RefCell;
974+
///
975+
/// let mut c = RefCell::new(0);
976+
/// std::mem::forget(c.borrow_mut());
977+
///
978+
/// assert!(c.try_borrow().is_err());
979+
/// c.undo_leak();
980+
/// assert!(c.try_borrow().is_ok());
981+
/// ```
982+
#[unstable(feature = "cell_leak", issue = "69099")]
983+
pub fn undo_leak(&mut self) -> &mut T {
984+
*self.borrow.get_mut() = UNUSED;
985+
self.get_mut()
986+
}
987+
961988
/// Immutably borrows the wrapped value, returning an error if the value is
962989
/// currently mutably borrowed.
963990
///
@@ -1272,8 +1299,10 @@ impl<'b, T: ?Sized> Ref<'b, T> {
12721299
/// ```
12731300
#[unstable(feature = "cell_leak", issue = "69099")]
12741301
pub fn leak(orig: Ref<'b, T>) -> &'b T {
1275-
// By forgetting this Ref we ensure that the borrow counter in the RefCell never goes back
1276-
// to UNUSED again. No further mutable references can be created from the original cell.
1302+
// By forgetting this Ref we ensure that the borrow counter in the RefCell can't go back to
1303+
// UNUSED within the lifetime `'b`. Resetting the reference tracking state would require a
1304+
// unique reference to the borrowed RefCell. No further mutable references can be created
1305+
// from the original cell.
12771306
mem::forget(orig.borrow);
12781307
orig.value
12791308
}
@@ -1387,9 +1416,11 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
13871416
/// ```
13881417
#[unstable(feature = "cell_leak", issue = "69099")]
13891418
pub fn leak(orig: RefMut<'b, T>) -> &'b mut T {
1390-
// By forgetting this BorrowRefMut we ensure that the borrow counter in the RefCell never
1391-
// goes back to UNUSED again. No further references can be created from the original cell,
1392-
// making the current borrow the only reference for the remaining lifetime.
1419+
// By forgetting this BorrowRefMut we ensure that the borrow counter in the RefCell can't
1420+
// go back to UNUSED within the lifetime `'b`. Resetting the reference tracking state would
1421+
// require a unique reference to the borrowed RefCell. No further references can be created
1422+
// from the original cell within that lifetime, making the current borrow the only
1423+
// reference for the remaining lifetime.
13931424
mem::forget(orig.borrow);
13941425
orig.value
13951426
}

0 commit comments

Comments
 (0)