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