Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leak when early returning out of box syntax #62331

Merged
merged 1 commit into from
Jul 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
expr_span,
scope,
result,
value.ty,
expr.ty,
);
}

Expand Down
91 changes: 91 additions & 0 deletions src/test/mir-opt/issue-62289.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// check that we don't forget to drop the Box if we early return before
// initializing it
// ignore-tidy-linelength
// ignore-wasm32-bare compiled with panic=abort by default

#![feature(box_syntax)]

fn test() -> Option<Box<u32>> {
Some(box (None?))
}

fn main() {
test();
}

// END RUST SOURCE
// START rustc.test.ElaborateDrops.before.mir
// fn test() -> std::option::Option<std::boxed::Box<u32>> {
// ...
// bb0: {
// StorageLive(_1);
// StorageLive(_2);
// _2 = Box(u32);
// StorageLive(_3);
// StorageLive(_4);
// _4 = std::option::Option::<u32>::None;
// _3 = const <std::option::Option<u32> as std::ops::Try>::into_result(move _4) -> [return: bb2, unwind: bb3];
// }
// bb1 (cleanup): {
// resume;
// }
// bb2: {
// StorageDead(_4);
// _5 = discriminant(_3);
// switchInt(move _5) -> [0isize: bb10, 1isize: bb5, otherwise: bb4];
// }
// bb3 (cleanup): {
// drop(_2) -> bb1;
// }
// bb4: {
// unreachable;
// }
// bb5: {
// StorageLive(_6);
// _6 = ((_3 as Err).0: std::option::NoneError);
// StorageLive(_8);
// StorageLive(_9);
// _9 = _6;
// _8 = const <std::option::NoneError as std::convert::From<std::option::NoneError>>::from(move _9) -> [return: bb7, unwind: bb3];
// }
// bb6: {
// return;
// }
// bb7: {
// StorageDead(_9);
// _0 = const <std::option::Option<std::boxed::Box<u32>> as std::ops::Try>::from_error(move _8) -> [return: bb8, unwind: bb3];
// }
// bb8: {
// StorageDead(_8);
// StorageDead(_6);
// drop(_2) -> bb9;
// }
// bb9: {
// StorageDead(_2);
// StorageDead(_1);
// StorageDead(_3);
// goto -> bb6;
// }
// bb10: {
// StorageLive(_10);
// _10 = ((_3 as Ok).0: u32);
// (*_2) = _10;
// StorageDead(_10);
// _1 = move _2;
// drop(_2) -> [return: bb12, unwind: bb11];
// }
// bb11 (cleanup): {
// drop(_1) -> bb1;
// }
// bb12: {
// StorageDead(_2);
// _0 = std::option::Option::<std::boxed::Box<u32>>::Some(move _1,);
// drop(_1) -> bb13;
// }
// bb13: {
// StorageDead(_1);
// StorageDead(_3);
// goto -> bb6;
// }
// }
// END rustc.test.ElaborateDrops.before.mir