Skip to main content

rustc_mir_transform/
remove_place_mention.rs

1//! This pass removes `PlaceMention` statement, which has no effect at codegen.
2
3use rustc_middle::mir::*;
4use rustc_middle::ty::TyCtxt;
5use tracing::trace;
6
7use crate::PassPolicy;
8
9pub(super) struct RemovePlaceMention;
10
11impl<'tcx> crate::MirPass<'tcx> for RemovePlaceMention {
12    fn policy(&self, sess: &rustc_session::Session) -> PassPolicy {
13        PassPolicy::optional_non_optimization(!sess.opts.unstable_opts.mir_preserve_ub)
14    }
15
16    fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
17        trace!("Running RemovePlaceMention on {:?}", body.source);
18        for data in body.basic_blocks.as_mut_preserves_cfg() {
19            data.retain_statements(|statement| match statement.kind {
20                StatementKind::PlaceMention(..) | StatementKind::Nop => false,
21                _ => true,
22            })
23        }
24    }
25}