Add a failing test

This commit is contained in:
Michael Goulet 2024-12-18 21:54:50 +00:00
parent a52085d9f6
commit 2e57394d80
3 changed files with 402 additions and 0 deletions

View file

@ -0,0 +1,183 @@
// MIR for `method_1` after ElaborateDrops
fn method_1(_1: Guard) -> () {
debug g => _1;
let mut _0: ();
let mut _2: std::result::Result<OtherDrop, ()>;
let mut _3: &Guard;
let _4: &Guard;
let _5: Guard;
let mut _6: &Guard;
let mut _7: isize;
let _8: OtherDrop;
let _9: ();
let mut _10: bool;
let mut _11: bool;
let mut _12: isize;
let mut _13: isize;
let mut _14: isize;
scope 1 {
debug other_drop => _8;
}
scope 2 {
debug err => _9;
}
bb0: {
_11 = const false;
_10 = const false;
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
StorageLive(_5);
StorageLive(_6);
_6 = &_1;
_5 = <Guard as Clone>::clone(move _6) -> [return: bb1, unwind: bb16];
}
bb1: {
_11 = const true;
StorageDead(_6);
_4 = &_5;
_3 = &(*_4);
_2 = method_2(move _3) -> [return: bb2, unwind: bb14];
}
bb2: {
_10 = const true;
StorageDead(_3);
PlaceMention(_2);
_7 = discriminant(_2);
switchInt(move _7) -> [0: bb5, 1: bb4, otherwise: bb3];
}
bb3: {
unreachable;
}
bb4: {
StorageLive(_9);
_9 = copy ((_2 as Err).0: ());
_0 = const ();
StorageDead(_9);
goto -> bb7;
}
bb5: {
StorageLive(_8);
_8 = move ((_2 as Ok).0: OtherDrop);
_0 = const ();
drop(_8) -> [return: bb6, unwind: bb11];
}
bb6: {
StorageDead(_8);
goto -> bb7;
}
bb7: {
backward incompatible drop(_2);
backward incompatible drop(_5);
goto -> bb24;
}
bb8: {
drop(_5) -> [return: bb9, unwind: bb16];
}
bb9: {
_11 = const false;
StorageDead(_5);
StorageDead(_4);
_10 = const false;
StorageDead(_2);
drop(_1) -> [return: bb10, unwind: bb17];
}
bb10: {
return;
}
bb11 (cleanup): {
goto -> bb28;
}
bb12 (cleanup): {
drop(_5) -> [return: bb13, unwind terminate(cleanup)];
}
bb13 (cleanup): {
goto -> bb15;
}
bb14 (cleanup): {
drop(_5) -> [return: bb15, unwind terminate(cleanup)];
}
bb15 (cleanup): {
goto -> bb30;
}
bb16 (cleanup): {
drop(_1) -> [return: bb17, unwind terminate(cleanup)];
}
bb17 (cleanup): {
resume;
}
bb18: {
goto -> bb8;
}
bb19 (cleanup): {
goto -> bb15;
}
bb20 (cleanup): {
goto -> bb15;
}
bb21: {
goto -> bb18;
}
bb22: {
goto -> bb18;
}
bb23 (cleanup): {
goto -> bb15;
}
bb24: {
_12 = discriminant(_2);
switchInt(move _12) -> [0: bb21, otherwise: bb22];
}
bb25 (cleanup): {
_13 = discriminant(_2);
switchInt(move _13) -> [0: bb19, otherwise: bb23];
}
bb26 (cleanup): {
goto -> bb12;
}
bb27 (cleanup): {
goto -> bb12;
}
bb28 (cleanup): {
_14 = discriminant(_2);
switchInt(move _14) -> [0: bb26, otherwise: bb27];
}
bb29 (cleanup): {
drop(_5) -> [return: bb16, unwind terminate(cleanup)];
}
bb30 (cleanup): {
switchInt(copy _11) -> [0: bb16, otherwise: bb29];
}
}

View file

@ -0,0 +1,183 @@
// MIR for `method_1` after ElaborateDrops
fn method_1(_1: Guard) -> () {
debug g => _1;
let mut _0: ();
let mut _2: std::result::Result<OtherDrop, ()>;
let mut _3: &Guard;
let _4: &Guard;
let _5: Guard;
let mut _6: &Guard;
let mut _7: isize;
let _8: OtherDrop;
let _9: ();
let mut _10: bool;
let mut _11: bool;
let mut _12: isize;
let mut _13: isize;
let mut _14: isize;
scope 1 {
debug other_drop => _8;
}
scope 2 {
debug err => _9;
}
bb0: {
_11 = const false;
_10 = const false;
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
StorageLive(_5);
StorageLive(_6);
_6 = &_1;
_5 = <Guard as Clone>::clone(move _6) -> [return: bb1, unwind: bb16];
}
bb1: {
_11 = const true;
StorageDead(_6);
_4 = &_5;
_3 = &(*_4);
_2 = method_2(move _3) -> [return: bb2, unwind: bb14];
}
bb2: {
_10 = const true;
StorageDead(_3);
PlaceMention(_2);
_7 = discriminant(_2);
switchInt(move _7) -> [0: bb5, 1: bb4, otherwise: bb3];
}
bb3: {
unreachable;
}
bb4: {
StorageLive(_9);
_9 = copy ((_2 as Err).0: ());
_0 = const ();
StorageDead(_9);
goto -> bb7;
}
bb5: {
StorageLive(_8);
_8 = move ((_2 as Ok).0: OtherDrop);
_0 = const ();
drop(_8) -> [return: bb6, unwind: bb11];
}
bb6: {
StorageDead(_8);
goto -> bb7;
}
bb7: {
backward incompatible drop(_2);
backward incompatible drop(_5);
goto -> bb24;
}
bb8: {
drop(_5) -> [return: bb9, unwind: bb16];
}
bb9: {
_11 = const false;
StorageDead(_5);
StorageDead(_4);
_10 = const false;
StorageDead(_2);
drop(_1) -> [return: bb10, unwind: bb17];
}
bb10: {
return;
}
bb11 (cleanup): {
goto -> bb28;
}
bb12 (cleanup): {
drop(_5) -> [return: bb13, unwind terminate(cleanup)];
}
bb13 (cleanup): {
goto -> bb15;
}
bb14 (cleanup): {
drop(_5) -> [return: bb15, unwind terminate(cleanup)];
}
bb15 (cleanup): {
goto -> bb30;
}
bb16 (cleanup): {
drop(_1) -> [return: bb17, unwind terminate(cleanup)];
}
bb17 (cleanup): {
resume;
}
bb18: {
goto -> bb8;
}
bb19 (cleanup): {
goto -> bb15;
}
bb20 (cleanup): {
goto -> bb15;
}
bb21: {
goto -> bb18;
}
bb22: {
goto -> bb18;
}
bb23 (cleanup): {
goto -> bb15;
}
bb24: {
_12 = discriminant(_2);
switchInt(move _12) -> [0: bb21, otherwise: bb22];
}
bb25 (cleanup): {
_13 = discriminant(_2);
switchInt(move _13) -> [0: bb19, otherwise: bb23];
}
bb26 (cleanup): {
goto -> bb12;
}
bb27 (cleanup): {
goto -> bb12;
}
bb28 (cleanup): {
_14 = discriminant(_2);
switchInt(move _14) -> [0: bb26, otherwise: bb27];
}
bb29 (cleanup): {
drop(_5) -> [return: bb16, unwind terminate(cleanup)];
}
bb30 (cleanup): {
switchInt(copy _11) -> [0: bb16, otherwise: bb29];
}
}

View file

@ -0,0 +1,36 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.mir
#![deny(tail_expr_drop_order)]
use std::backtrace::Backtrace;
#[derive(Clone)]
struct Guard;
impl Drop for Guard {
fn drop(&mut self) {
println!("Drop!");
}
}
#[derive(Clone)]
struct OtherDrop;
impl Drop for OtherDrop {
fn drop(&mut self) {
println!("Drop!");
}
}
fn method_1(g: Guard) {
match method_2(&g.clone()) {
Ok(other_drop) => {
// repro needs something else being dropped too.
},
Err(err) => {},
}
}
fn method_2(_: &Guard) -> Result<OtherDrop, ()> {
panic!("Method 2 panics!");
}