Skip to content

Replace a match with an if let #85973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace a match with an if let
Seems like a better fit here and saves one level of indentation.
  • Loading branch information
LingMan committed Jun 3, 2021
commit 63c8cbd3c94bb9c71cc7c23715a982582973fab1
47 changes: 22 additions & 25 deletions compiler/rustc_mir/src/transform/remove_zsts.rs
Original file line number Diff line number Diff line change
@@ -16,32 +16,29 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts {
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;
if !maybe_zst(place_ty) {
continue;
}
let layout = match tcx.layout_of(param_env.and(place_ty)) {
Ok(layout) => layout,
Err(_) => continue,
};
if !layout.is_zst() {
continue;
}
if involves_a_union(place, local_decls, tcx) {
continue;
}
if tcx.consider_optimizing(|| {
format!(
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
place, statement.source_info
)
}) {
statement.make_nop();
}
if let StatementKind::Assign(box (place, _)) = statement.kind {
let place_ty = place.ty(local_decls, tcx).ty;
if !maybe_zst(place_ty) {
continue;
}
let layout = match tcx.layout_of(param_env.and(place_ty)) {
Ok(layout) => layout,
Err(_) => continue,
};
if !layout.is_zst() {
continue;
}
if involves_a_union(place, local_decls, tcx) {
continue;
}
if tcx.consider_optimizing(|| {
format!(
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
place, statement.source_info
)
}) {
statement.make_nop();
}
_ => {}
}
}
}