Skip to content

Commit

Permalink
Add an enum variant per review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbr committed Nov 15, 2022
1 parent 13bc9c9 commit 46b6233
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/test/ui/manually_drop_attr/manually_drop-destructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand All @@ -56,7 +58,7 @@ fn test_destruction() {
assert_eq!(counter.get(), 1);
assert!(core::mem::needs_drop::<ManuallyDropped>());

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::<ManuallyDroppedEnum>());

Expand Down
7 changes: 4 additions & 3 deletions src/test/ui/manually_drop_attr/manually_drop-nodestructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -35,7 +36,7 @@ fn test_destruction() {
assert_eq!(counter.get(), 0);
assert!(!core::mem::needs_drop::<ManuallyDropped>());

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::<ManuallyDroppedEnum>());
}
Expand Down

0 comments on commit 46b6233

Please sign in to comment.