2024-04-20 13:19:34 +02:00
|
|
|
//@ test-mir-pass: ElaborateDrops
|
2023-10-16 18:04:10 +00:00
|
|
|
//@ needs-unwind
|
2017-11-26 10:39:16 -08:00
|
|
|
|
2025-01-02 21:22:42 +01:00
|
|
|
#![feature(rustc_attrs, liballoc_internals)]
|
2017-08-14 14:10:05 +03:00
|
|
|
|
2023-10-16 18:04:10 +00:00
|
|
|
// EMIT_MIR box_expr.main.ElaborateDrops.diff
|
2017-08-14 14:10:05 +03:00
|
|
|
fn main() {
|
2023-10-16 18:04:10 +00:00
|
|
|
// CHECK-LABEL: fn main(
|
|
|
|
// CHECK: [[box:_.*]] = ShallowInitBox(
|
2024-11-15 00:35:46 -08:00
|
|
|
// CHECK: [[ptr:_.*]] = copy (([[box]].0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
|
2023-10-16 18:04:10 +00:00
|
|
|
// CHECK: (*[[ptr]]) = S::new() -> [return: [[ret:bb.*]], unwind: [[unwind:bb.*]]];
|
|
|
|
// CHECK: [[ret]]: {
|
|
|
|
// CHECK: [[box2:_.*]] = move [[box]];
|
|
|
|
// CHECK: [[box3:_.*]] = move [[box2]];
|
|
|
|
// CHECK: std::mem::drop::<Box<S>>(move [[box3]])
|
|
|
|
// CHECK: [[unwind]] (cleanup): {
|
|
|
|
// CHECK: [[boxref:_.*]] = &mut [[box]];
|
|
|
|
// CHECK: <Box<S> as Drop>::drop(move [[boxref]])
|
|
|
|
|
2025-01-02 21:22:42 +01:00
|
|
|
let x = std::boxed::box_new(S::new());
|
2017-08-14 14:10:05 +03:00
|
|
|
drop(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S;
|
|
|
|
|
|
|
|
impl S {
|
2023-02-27 13:07:44 +00:00
|
|
|
fn new() -> Self {
|
|
|
|
S
|
|
|
|
}
|
2017-08-14 14:10:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for S {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
println!("splat!");
|
|
|
|
}
|
|
|
|
}
|