Skip to content

Add core::mem::DropGuard #144236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix CI for drop_guard
  • Loading branch information
yoshuawuyts committed Jul 21, 2025
commit dc5f4539af88266b2d984851bb403bc93fa2ed73
14 changes: 6 additions & 8 deletions library/core/src/mem/drop_guard.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::mem::ManuallyDrop;
use core::ops::{Deref, DerefMut};
use core::ptr;
use crate::mem::ManuallyDrop;
use crate::ops::{Deref, DerefMut};
use crate::ptr;

/// Wrap a value and run a closure when dropped.
///
Expand Down Expand Up @@ -52,10 +52,7 @@ where
/// ```
#[unstable(feature = "drop_guard", issue = "none")]
pub fn new(inner: T, f: F) -> Self {
Self {
inner: ManuallyDrop::new(inner),
f: ManuallyDrop::new(f),
}
Self { inner: ManuallyDrop::new(inner), f: ManuallyDrop::new(f) }
}

/// Consumes the `Guard`, returning the wrapped value.
Expand Down Expand Up @@ -141,8 +138,9 @@ where
// tests copied from https://docs.rs/scopeguard/latest/src/scopeguard/lib.rs.html#1-595
#[cfg(test)]
mod tests {
use crate::cell::Cell;

use super::*;
use std::cell::Cell;

#[test]
fn test_only_dropped_by_closure_when_run() {
Expand Down
Loading