From 46b623374f34c6a2a171f274f5ec6591c3fc85dc Mon Sep 17 00:00:00 2001 From: Devin Jeanpierre Date: Tue, 15 Nov 2022 13:49:20 -0800 Subject: [PATCH] Add an enum variant per review comment --- .../manually_drop_attr/manually_drop-destructor.rs | 12 +++++++----- .../manually_drop_attr/manually_drop-nodestructor.rs | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/test/ui/manually_drop_attr/manually_drop-destructor.rs b/src/test/ui/manually_drop_attr/manually_drop-destructor.rs index 33721673b5f4..a9138ebb7022 100644 --- a/src/test/ui/manually_drop_attr/manually_drop-destructor.rs +++ b/src/test/ui/manually_drop_attr/manually_drop-destructor.rs @@ -30,15 +30,17 @@ impl<'a> Drop for ManuallyDropped<'a> { #[manually_drop] enum ManuallyDroppedEnum<'a> { - A(DropCounter<'a>, DropCounter<'a>), + _A, + B(DropCounter<'a>, DropCounter<'a>), } impl<'a> Drop for ManuallyDroppedEnum<'a> { fn drop(&mut self) { // just do a LITTLE dropping. - let ManuallyDroppedEnum::A(a, _) = self; - unsafe { - core::ptr::drop_in_place(a); + if let ManuallyDroppedEnum::B(a, _) = self { + unsafe { + core::ptr::drop_in_place(a); + } } } } @@ -56,7 +58,7 @@ fn test_destruction() { assert_eq!(counter.get(), 1); assert!(core::mem::needs_drop::()); - core::mem::drop(ManuallyDroppedEnum::A(DropCounter(&counter), DropCounter(&counter))); + core::mem::drop(ManuallyDroppedEnum::B(DropCounter(&counter), DropCounter(&counter))); assert_eq!(counter.get(), 2); assert!(core::mem::needs_drop::()); diff --git a/src/test/ui/manually_drop_attr/manually_drop-nodestructor.rs b/src/test/ui/manually_drop_attr/manually_drop-nodestructor.rs index e5af4e7e1b50..da0597f39845 100644 --- a/src/test/ui/manually_drop_attr/manually_drop-nodestructor.rs +++ b/src/test/ui/manually_drop_attr/manually_drop-nodestructor.rs @@ -22,10 +22,11 @@ struct ManuallyDropped<'a> { #[manually_drop] enum ManuallyDroppedEnum<'a> { - A(DropCounter<'a>, DropCounter<'a>), + _A, + B(DropCounter<'a>, DropCounter<'a>), } -/// Dropping a `#[manually_drop]` struct does not implicitly drop its fields. +/// Dropping a `#[manually_drop]` type does not implicitly drop its fields. fn test_destruction() { let counter = Cell::new(0); core::mem::drop(ManuallyDropped { @@ -35,7 +36,7 @@ fn test_destruction() { assert_eq!(counter.get(), 0); assert!(!core::mem::needs_drop::()); - core::mem::drop(ManuallyDroppedEnum::A(DropCounter(&counter), DropCounter(&counter))); + core::mem::drop(ManuallyDroppedEnum::B(DropCounter(&counter), DropCounter(&counter))); assert_eq!(counter.get(), 0); assert!(!core::mem::needs_drop::()); }