Skip to content

Commit 0ecf91a

Browse files
committed
Use an explicit receiver in DropGuard::dismiss
1 parent e163707 commit 0ecf91a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

library/core/src/mem/drop_guard.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,30 @@ where
7979
///
8080
/// let value = String::from("Nori likes chicken");
8181
/// let guard = DropGuard::new(value, |s| println!("{s}"));
82-
/// assert_eq!(guard.dismiss(), "Nori likes chicken");
82+
/// assert_eq!(DropGuard::dismiss(guard), "Nori likes chicken");
8383
/// ```
8484
#[unstable(feature = "drop_guard", issue = "144426")]
8585
#[rustc_const_unstable(feature = "const_drop_guard", issue = "none")]
8686
#[inline]
87-
pub const fn dismiss(self) -> T
87+
pub const fn dismiss(guard: Self) -> T
8888
where
8989
F: [const] Destruct,
9090
{
9191
// First we ensure that dropping the guard will not trigger
9292
// its destructor
93-
let mut this = ManuallyDrop::new(self);
93+
let mut guard = ManuallyDrop::new(guard);
9494

9595
// Next we manually read the stored value from the guard.
9696
//
9797
// SAFETY: this is safe because we've taken ownership of the guard.
98-
let value = unsafe { ManuallyDrop::take(&mut this.inner) };
98+
let value = unsafe { ManuallyDrop::take(&mut guard.inner) };
9999

100100
// Finally we drop the stored closure. We do this *after* having read
101101
// the value, so that even if the closure's `drop` function panics,
102102
// unwinding still tries to drop the value.
103103
//
104104
// SAFETY: this is safe because we've taken ownership of the guard.
105-
unsafe { ManuallyDrop::drop(&mut this.f) };
105+
unsafe { ManuallyDrop::drop(&mut guard.f) };
106106
value
107107
}
108108
}

library/coretests/tests/mem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ fn drop_guard_into_inner() {
815815
let dropped = Cell::new(false);
816816
let value = DropGuard::new(42, |_| dropped.set(true));
817817
let guard = DropGuard::new(value, |_| dropped.set(true));
818-
let inner = guard.dismiss();
818+
let inner = DropGuard::dismiss(guard);
819819
assert_eq!(dropped.get(), false);
820820
assert_eq!(*inner, 42);
821821
}
@@ -837,7 +837,7 @@ fn drop_guard_always_drops_value_if_closure_drop_unwinds() {
837837
// run the destructor of the value we passed, which we validate.
838838
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
839839
let guard = DropGuard::new(value_with_tracked_destruction, closure_that_panics_on_drop);
840-
guard.dismiss();
840+
DropGuard::dismiss(guard);
841841
}));
842842
assert!(value_was_dropped);
843843
}

0 commit comments

Comments
 (0)