2021-03-17 01:30:37 +00:00
|
|
|
//! Removes assignments to ZST places.
|
|
|
|
|
|
|
|
use crate::transform::MirPass;
|
|
|
|
use rustc_middle::mir::{Body, StatementKind};
|
|
|
|
use rustc_middle::ty::TyCtxt;
|
|
|
|
|
|
|
|
pub struct RemoveZsts;
|
|
|
|
|
|
|
|
impl<'tcx> MirPass<'tcx> for RemoveZsts {
|
|
|
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|
|
|
let param_env = tcx.param_env(body.source.def_id());
|
|
|
|
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
|
|
|
|
for block in basic_blocks.iter_mut() {
|
|
|
|
for statement in block.statements.iter_mut() {
|
|
|
|
match statement.kind {
|
|
|
|
StatementKind::Assign(box (place, _)) => {
|
|
|
|
let place_ty = place.ty(local_decls, tcx).ty;
|
2021-03-18 00:24:29 +00:00
|
|
|
if let Ok(layout) = tcx.layout_of(param_env.and(place_ty)) {
|
2021-03-18 00:31:00 +00:00
|
|
|
if layout.is_zst() {
|
2021-03-18 00:24:29 +00:00
|
|
|
if tcx.consider_optimizing(|| {
|
|
|
|
format!(
|
|
|
|
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
|
|
|
|
place, statement.source_info
|
|
|
|
)
|
|
|
|
}) {
|
|
|
|
statement.make_nop();
|
2021-03-17 01:30:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|