Adopt let else in more places

This commit is contained in:
est31 2022-02-19 00:48:49 +01:00
parent b8c56fa8c3
commit 2ef8af6619
132 changed files with 539 additions and 881 deletions

View file

@ -243,9 +243,8 @@ pub(crate) fn on_all_inactive_variants<'tcx>(
active_variant: VariantIdx,
mut handle_inactive_variant: impl FnMut(MovePathIndex),
) {
let enum_mpi = match move_data.rev_lookup.find(enum_place.as_ref()) {
LookupResult::Exact(mpi) => mpi,
LookupResult::Parent(_) => return,
let LookupResult::Exact(enum_mpi) = move_data.rev_lookup.find(enum_place.as_ref()) else {
return;
};
let enum_path = &move_data.move_paths[enum_mpi];
@ -256,9 +255,8 @@ pub(crate) fn on_all_inactive_variants<'tcx>(
let (downcast, base_proj) = variant_path.place.projection.split_last().unwrap();
assert_eq!(enum_place.projection.len(), base_proj.len());
let variant_idx = match *downcast {
mir::ProjectionElem::Downcast(_, idx) => idx,
_ => unreachable!(),
let mir::ProjectionElem::Downcast(_, variant_idx) = *downcast else {
unreachable!();
};
if variant_idx != active_variant {

View file

@ -274,11 +274,9 @@ where
use std::io::{self, Write};
let def_id = body.source.def_id();
let attrs = match RustcMirAttrs::parse(tcx, def_id) {
Ok(attrs) => attrs,
let Ok(attrs) = RustcMirAttrs::parse(tcx, def_id) else {
// Invalid `rustc_mir` attrs are reported in `RustcMirAttrs::parse`
Err(()) => return Ok(()),
return Ok(());
};
let mut file = match attrs.output_path(A::NAME) {

View file

@ -628,9 +628,8 @@ where
ret
});
let mut html_diff = match html_diff {
Cow::Borrowed(_) => return raw_diff,
Cow::Owned(s) => s,
let Cow::Owned(mut html_diff) = html_diff else {
return raw_diff;
};
if inside_font_tag {

View file

@ -385,16 +385,14 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
switch_on_enum_discriminant(self.tcx, &self.body, &self.body[block], discr)
});
let (enum_place, enum_def) = match enum_ {
Some(x) => x,
None => return,
let Some((enum_place, enum_def)) = enum_ else {
return;
};
let mut discriminants = enum_def.discriminants(self.tcx);
edge_effects.apply(|trans, edge| {
let value = match edge.value {
Some(x) => x,
None => return,
let Some(value) = edge.value else {
return;
};
// MIR building adds discriminants to the `values` array in the same order as they
@ -507,16 +505,14 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
switch_on_enum_discriminant(self.tcx, &self.body, &self.body[block], discr)
});
let (enum_place, enum_def) = match enum_ {
Some(x) => x,
None => return,
let Some((enum_place, enum_def)) = enum_ else {
return;
};
let mut discriminants = enum_def.discriminants(self.tcx);
edge_effects.apply(|trans, edge| {
let value = match edge.value {
Some(x) => x,
None => return,
let Some(value) = edge.value else {
return;
};
// MIR building adds discriminants to the `values` array in the same order as they