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
7use crate::PassPolicy;
8
9pub(super) struct RemoveStorageMarkers;
10
11impl<'tcx> crate::MirPass<'tcx> for RemoveStorageMarkers {
12 fn policy(&self, ctx: &crate::PassCtx<'_>) -> PassPolicy {
13 PassPolicy::optional(ctx.mir_opt_level() >= 1 && !ctx.emit_lifetime_markers())
14 }
15
16 fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
17 trace!("Running RemoveStorageMarkers on {:?}", body.source);
18 for data in body.basic_blocks.as_mut_preserves_cfg() {
19 data.retain_statements(|statement| match statement.kind {
20 StatementKind::StorageLive(..)
21 | StatementKind::StorageDead(..)
22 | StatementKind::Nop => false,
23 _ => true,
24 })
25 }
26 }
27}