2021-01-14 18:10:13 +00:00
|
|
|
//@ build-pass
|
2021-03-04 13:21:13 +00:00
|
|
|
//@ compile-flags: -Z mir-opt-level=4
|
2021-01-14 18:10:13 +00:00
|
|
|
|
2022-05-14 04:53:03 +00:00
|
|
|
#![crate_type = "lib"]
|
2021-01-14 18:10:13 +00:00
|
|
|
#![feature(lang_items)]
|
|
|
|
#![no_std]
|
|
|
|
|
2022-05-09 04:23:52 +00:00
|
|
|
struct NonNull<T: ?Sized>(*const T);
|
2022-05-14 04:53:03 +00:00
|
|
|
|
|
|
|
struct Unique<T: ?Sized>(NonNull<T>);
|
|
|
|
|
2021-01-14 18:10:13 +00:00
|
|
|
#[lang = "owned_box"]
|
2022-05-14 04:53:03 +00:00
|
|
|
pub struct Box<T: ?Sized>(Unique<T>);
|
2021-01-14 18:10:13 +00:00
|
|
|
|
|
|
|
impl<T: ?Sized> Drop for Box<T> {
|
2022-08-01 20:51:58 +00:00
|
|
|
#[inline(always)]
|
|
|
|
fn drop(&mut self) {
|
|
|
|
dealloc(self.0.0.0)
|
|
|
|
}
|
2021-01-14 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(never)]
|
2022-05-09 04:23:52 +00:00
|
|
|
fn dealloc<T: ?Sized>(_: *const T) {}
|
2021-01-14 18:10:13 +00:00
|
|
|
|
|
|
|
pub struct Foo<T>(T);
|
|
|
|
|
|
|
|
pub fn foo(a: Option<Box<Foo<usize>>>) -> usize {
|
|
|
|
let f = match a {
|
|
|
|
None => Foo(0),
|
|
|
|
Some(vec) => *vec,
|
|
|
|
};
|
|
|
|
f.0
|
|
|
|
}
|