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
7pub(super) struct RemovePlaceMention;
8
9impl<'tcx> crate::MirPass<'tcx> for RemovePlaceMention {
10 fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
11 !sess.opts.unstable_opts.mir_keep_place_mention
12 }
13
14 fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
15 trace!("Running RemovePlaceMention on {:?}", body.source);
16 for data in body.basic_blocks.as_mut_preserves_cfg() {
17 data.statements.retain(|statement| match statement.kind {
18 StatementKind::PlaceMention(..) | StatementKind::Nop => false,
19 _ => true,
20 })
21 }
22 }
23
24 fn is_required(&self) -> bool {
25 true
26 }
27}