Skip to content

Commit c3cf598

Browse files
committed
fix all tidy lints
1 parent 7094637 commit c3cf598

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

library/core/src/mem/drop_guard.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -127,40 +127,12 @@ where
127127
F: FnOnce(T),
128128
{
129129
fn drop(&mut self) {
130-
// SAFETY: we're taking the values out of the `ManuallyDrop` with
131-
// the express intent of dropping them.
130+
// SAFETY: `DropGuard` is in the process of being dropped.
132131
let inner = unsafe { ManuallyDrop::take(&mut self.inner) };
133-
let f = unsafe { ManuallyDrop::take(&mut self.f) };
134-
f(inner);
135-
}
136-
}
137132

138-
// tests copied from https://docs.rs/scopeguard/latest/src/scopeguard/lib.rs.html#1-595
139-
#[cfg(test)]
140-
mod tests {
141-
use super::*;
142-
use crate::cell::Cell;
143-
144-
#[test]
145-
fn test_only_dropped_by_closure_when_run() {
146-
let value_drops = Cell::new(0);
147-
let value = DropGuard::new((), |()| value_drops.set(1 + value_drops.get()));
148-
let closure_drops = Cell::new(0);
149-
let guard = DropGuard::new(value, |_| closure_drops.set(1 + closure_drops.get()));
150-
assert_eq!(value_drops.get(), 0);
151-
assert_eq!(closure_drops.get(), 0);
152-
drop(guard);
153-
assert_eq!(value_drops.get(), 1);
154-
assert_eq!(closure_drops.get(), 1);
155-
}
133+
// SAFETY: `DropGuard` is in the process of being dropped.
134+
let f = unsafe { ManuallyDrop::take(&mut self.f) };
156135

157-
#[test]
158-
fn test_into_inner() {
159-
let dropped = Cell::new(false);
160-
let value = DropGuard::new(42, |_| dropped.set(true));
161-
let guard = DropGuard::new(value, |_| dropped.set(true));
162-
let inner = DropGuard::into_inner(guard);
163-
assert_eq!(dropped.get(), false);
164-
assert_eq!(*inner, 42);
136+
f(inner);
165137
}
166138
}

library/coretests/tests/mem.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use core::mem::*;
22
use core::{array, ptr};
33
#[cfg(panic = "unwind")]
44
use std::rc::Rc;
5+
use std::cell::Cell;
56

67
#[test]
78
fn size_of_basic() {
@@ -795,3 +796,26 @@ fn const_maybe_uninit_zeroed() {
795796

796797
assert_eq!(unsafe { (*UNINIT.0.cast::<[[u8; SIZE]; 1]>())[0] }, [0u8; SIZE]);
797798
}
799+
800+
#[test]
801+
fn drop_guards_only_dropped_by_closure_when_run() {
802+
let value_drops = Cell::new(0);
803+
let value = DropGuard::new((), |()| value_drops.set(1 + value_drops.get()));
804+
let closure_drops = Cell::new(0);
805+
let guard = DropGuard::new(value, |_| closure_drops.set(1 + closure_drops.get()));
806+
assert_eq!(value_drops.get(), 0);
807+
assert_eq!(closure_drops.get(), 0);
808+
drop(guard);
809+
assert_eq!(value_drops.get(), 1);
810+
assert_eq!(closure_drops.get(), 1);
811+
}
812+
813+
#[test]
814+
fn drop_guard_into_inner() {
815+
let dropped = Cell::new(false);
816+
let value = DropGuard::new(42, |_| dropped.set(true));
817+
let guard = DropGuard::new(value, |_| dropped.set(true));
818+
let inner = DropGuard::into_inner(guard);
819+
assert_eq!(dropped.get(), false);
820+
assert_eq!(*inner, 42);
821+
}

0 commit comments

Comments
 (0)