-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stop clearing box's drop flags early
- Loading branch information
1 parent
bfe5e8c
commit 73ea6ab
Showing
4 changed files
with
56 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//@ run-pass | ||
#![feature(allocator_api)] | ||
|
||
// Regression test for #131082. | ||
// Testing that the allocator of a Box is dropped in conditional drops | ||
|
||
use std::alloc::{AllocError, Allocator, Global, Layout}; | ||
use std::cell::Cell; | ||
use std::ptr::NonNull; | ||
|
||
struct DropCheckingAllocator<'a>(&'a Cell<bool>); | ||
|
||
unsafe impl Allocator for DropCheckingAllocator<'_> { | ||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { | ||
Global.allocate(layout) | ||
} | ||
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | ||
Global.deallocate(ptr, layout); | ||
} | ||
} | ||
impl Drop for DropCheckingAllocator<'_> { | ||
fn drop(&mut self) { | ||
self.0.set(true); | ||
} | ||
} | ||
|
||
struct HasDrop; | ||
impl Drop for HasDrop { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
fn main() { | ||
let dropped = Cell::new(false); | ||
{ | ||
let b = Box::new_in(HasDrop, DropCheckingAllocator(&dropped)); | ||
if true { | ||
drop(*b); | ||
} else { | ||
drop(b); | ||
} | ||
} | ||
assert!(dropped.get()); | ||
} |