rustc_mir_transform/remove_storage_markers.rs
1//! This pass removes storage markers if they won't be emitted during codegen.
2
3use rustc_middle::mir::*;
4use rustc_middle::ty::TyCtxt;
5use tracing::trace;
6
7pub(super) struct RemoveStorageMarkers;
8
9impl<'tcx> crate::MirPass<'tcx> for RemoveStorageMarkers {
10 fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
11 sess.mir_opt_level() > 0 && !sess.emit_lifetime_markers()
12 }
13
14 fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
15 trace!("Running RemoveStorageMarkers on {:?}", body.source);
16 for data in body.basic_blocks.as_mut_preserves_cfg() {
17 data.statements.retain(|statement| match statement.kind {
18 StatementKind::StorageLive(..)
19 | StatementKind::StorageDead(..)
20 | StatementKind::Nop => false,
21 _ => true,
22 })
23 }
24 }
25
26 fn is_required(&self) -> bool {
27 true
28 }
29}