Skip to content

Commit 9a89ef0

Browse files
committed
Add Drop terminator to SMIR
1 parent 2f50334 commit 9a89ef0

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ fn rustc_terminator_to_terminator(
162162
Terminate => Terminator::Abort,
163163
Return => Terminator::Return,
164164
Unreachable => Terminator::Unreachable,
165-
Drop { .. } => todo!(),
165+
Drop { place, target, unwind } => Terminator::Drop {
166+
place: rustc_place_to_place(place),
167+
target: target.as_usize(),
168+
unwind: rustc_unwind_to_unwind(unwind),
169+
},
166170
Call { func, args, destination, target, unwind, from_hir_call: _, fn_span: _ } => {
167171
Terminator::Call {
168172
func: rustc_op_to_op(func),

compiler/rustc_smir/src/stable_mir/mir/body.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub enum Terminator {
2626
Drop {
2727
place: Place,
2828
target: usize,
29-
unwind: Option<usize>,
29+
unwind: UnwindAction,
3030
},
3131
Call {
3232
func: Operand,

tests/ui-fulldeps/stable-mir/crate-info.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
6060
stable_mir::mir::Terminator::Call { .. } => {}
6161
other => panic!("{other:?}"),
6262
}
63+
64+
let drop = get_item(tcx, &items, (DefKind::Fn, "drop")).unwrap();
65+
let body = drop.body();
66+
assert_eq!(body.blocks.len(), 2);
67+
let block = &body.blocks[0];
68+
match &block.terminator {
69+
stable_mir::mir::Terminator::Drop { .. } => {}
70+
other => panic!("{other:?}"),
71+
}
6372
}
6473

6574
// Use internal API to find a function in a crate.
@@ -131,7 +140,9 @@ fn generate_input(path: &str) -> std::io::Result<()> {
131140
let x_64 = foo::bar(x);
132141
let y_64 = foo::bar(y);
133142
x_64.wrapping_add(y_64)
134-
}}"#
143+
}}
144+
145+
pub fn drop(_: String) {{}}"#
135146
)?;
136147
Ok(())
137148
}

0 commit comments

Comments
 (0)