1
Fork 0

Re-format let-else per rustfmt update

This commit is contained in:
Mark Rousskov 2023-07-12 21:49:27 -04:00
parent 67b0cfc761
commit cc907f80b9
162 changed files with 1404 additions and 947 deletions

View file

@ -76,9 +76,11 @@ fn fully_moved_locals(ssa: &SsaLocals, body: &Body<'_>) -> BitSet<Local> {
let mut fully_moved = BitSet::new_filled(body.local_decls.len());
for (_, rvalue, _) in ssa.assignments(body) {
let (Rvalue::Use(Operand::Copy(place) | Operand::Move(place)) | Rvalue::CopyForDeref(place))
= rvalue
else { continue };
let (Rvalue::Use(Operand::Copy(place) | Operand::Move(place))
| Rvalue::CopyForDeref(place)) = rvalue
else {
continue;
};
let Some(rhs) = place.as_local() else { continue };
if !ssa.is_ssa(rhs) {

View file

@ -281,7 +281,7 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
let FlatSet::Elem(choice) = discr_value else {
// Do nothing if we don't know which branch will be taken.
return
return;
};
if target.value.map(|n| n == choice).unwrap_or(!handled) {

View file

@ -218,9 +218,9 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
if merged_locals.contains(*src) {
continue;
}
let Some(dest) =
candidates.iter().find(|dest| !merged_locals.contains(**dest)) else {
continue;
let Some(dest) = candidates.iter().find(|dest| !merged_locals.contains(**dest))
else {
continue;
};
if !tcx.consider_optimizing(|| {
format!("{} round {}", tcx.def_path_str(def_id), round_count)
@ -601,9 +601,7 @@ impl WriteInfo {
rhs: &Operand<'tcx>,
body: &Body<'tcx>,
) {
let Some(rhs) = rhs.place() else {
return
};
let Some(rhs) = rhs.place() else { return };
if let Some(pair) = places_to_candidate_pair(lhs, rhs, body) {
self.skip_pair = Some(pair);
}

View file

@ -107,9 +107,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
for i in 0..body.basic_blocks.len() {
let bbs = &*body.basic_blocks;
let parent = BasicBlock::from_usize(i);
let Some(opt_data) = evaluate_candidate(tcx, body, parent) else {
continue
};
let Some(opt_data) = evaluate_candidate(tcx, body, parent) else { continue };
if !tcx.consider_optimizing(|| format!("EarlyOtherwiseBranch {:?}", &opt_data)) {
break;
@ -119,10 +117,9 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
should_cleanup = true;
let TerminatorKind::SwitchInt {
discr: parent_op,
targets: parent_targets
} = &bbs[parent].terminator().kind else {
let TerminatorKind::SwitchInt { discr: parent_op, targets: parent_targets } =
&bbs[parent].terminator().kind
else {
unreachable!()
};
// Always correct since we can only switch on `Copy` types
@ -168,7 +165,8 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
);
let eq_new_targets = parent_targets.iter().map(|(value, child)| {
let TerminatorKind::SwitchInt{ targets, .. } = &bbs[child].terminator().kind else {
let TerminatorKind::SwitchInt { targets, .. } = &bbs[child].terminator().kind
else {
unreachable!()
};
(value, targets.target_for_value(value))
@ -311,11 +309,9 @@ fn evaluate_candidate<'tcx>(
parent: BasicBlock,
) -> Option<OptimizationData<'tcx>> {
let bbs = &body.basic_blocks;
let TerminatorKind::SwitchInt {
targets,
discr: parent_discr,
} = &bbs[parent].terminator().kind else {
return None
let TerminatorKind::SwitchInt { targets, discr: parent_discr } = &bbs[parent].terminator().kind
else {
return None;
};
let parent_ty = parent_discr.ty(body.local_decls(), tcx);
let parent_dest = {
@ -332,18 +328,16 @@ fn evaluate_candidate<'tcx>(
};
let (_, child) = targets.iter().next()?;
let child_terminator = &bbs[child].terminator();
let TerminatorKind::SwitchInt {
targets: child_targets,
discr: child_discr,
} = &child_terminator.kind else {
return None
let TerminatorKind::SwitchInt { targets: child_targets, discr: child_discr } =
&child_terminator.kind
else {
return None;
};
let child_ty = child_discr.ty(body.local_decls(), tcx);
if child_ty != parent_ty {
return None;
}
let Some(StatementKind::Assign(boxed))
= &bbs[child].statements.first().map(|x| &x.kind) else {
let Some(StatementKind::Assign(boxed)) = &bbs[child].statements.first().map(|x| &x.kind) else {
return None;
};
let (_, Rvalue::Discriminant(child_place)) = &**boxed else {
@ -383,12 +377,8 @@ fn verify_candidate_branch<'tcx>(
return false;
}
// ...assign the discriminant of `place` in that statement
let StatementKind::Assign(boxed) = &branch.statements[0].kind else {
return false
};
let (discr_place, Rvalue::Discriminant(from_place)) = &**boxed else {
return false
};
let StatementKind::Assign(boxed) = &branch.statements[0].kind else { return false };
let (discr_place, Rvalue::Discriminant(from_place)) = &**boxed else { return false };
if *from_place != place {
return false;
}
@ -397,8 +387,9 @@ fn verify_candidate_branch<'tcx>(
return false;
}
// ...terminate on a `SwitchInt` that invalidates that local
let TerminatorKind::SwitchInt{ discr: switch_op, targets, .. } = &branch.terminator().kind else {
return false
let TerminatorKind::SwitchInt { discr: switch_op, targets, .. } = &branch.terminator().kind
else {
return false;
};
if *switch_op != Operand::Move(*discr_place) {
return false;

View file

@ -1763,7 +1763,9 @@ fn check_suspend_tys<'tcx>(tcx: TyCtxt<'tcx>, layout: &GeneratorLayout<'tcx>, bo
debug!(?decl);
if !decl.ignore_for_traits && linted_tys.insert(decl.ty) {
let Some(hir_id) = decl.source_info.scope.lint_root(&body.source_scopes) else { continue };
let Some(hir_id) = decl.source_info.scope.lint_root(&body.source_scopes) else {
continue;
};
check_must_not_suspend_ty(
tcx,

View file

@ -189,19 +189,19 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
statements: &mut Vec<Statement<'tcx>>,
) {
let TerminatorKind::Call { func, args, destination, target, .. } = &mut terminator.kind
else { return };
else {
return;
};
// It's definitely not a clone if there are multiple arguments
if args.len() != 1 {
return;
}
let Some(destination_block) = *target
else { return };
let Some(destination_block) = *target else { return };
// Only bother looking more if it's easy to know what we're calling
let Some((fn_def_id, fn_substs)) = func.const_fn_def()
else { return };
let Some((fn_def_id, fn_substs)) = func.const_fn_def() else { return };
// Clone needs one subst, so we can cheaply rule out other stuff
if fn_substs.len() != 1 {
@ -212,8 +212,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
// doing DefId lookups to figure out what we're actually calling.
let arg_ty = args[0].ty(self.local_decls, self.tcx);
let ty::Ref(_region, inner_ty, Mutability::Not) = *arg_ty.kind()
else { return };
let ty::Ref(_region, inner_ty, Mutability::Not) = *arg_ty.kind() else { return };
if !inner_ty.is_trivially_pure_clone_copy() {
return;
@ -234,8 +233,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
return;
}
let Some(arg_place) = args.pop().unwrap().place()
else { return };
let Some(arg_place) = args.pop().unwrap().place() else { return };
statements.push(Statement {
source_info: terminator.source_info,
@ -254,8 +252,12 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
terminator: &mut Terminator<'tcx>,
_statements: &mut Vec<Statement<'tcx>>,
) {
let TerminatorKind::Call { func, target, .. } = &mut terminator.kind else { return; };
let Some(target_block) = target else { return; };
let TerminatorKind::Call { func, target, .. } = &mut terminator.kind else {
return;
};
let Some(target_block) = target else {
return;
};
let func_ty = func.ty(self.local_decls, self.tcx);
let Some((intrinsic_name, substs)) = resolve_rust_intrinsic(self.tcx, func_ty) else {
return;

View file

@ -251,7 +251,9 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
if let (Some(target), Some(arg)) = (*target, args[0].place()) {
let ty::RawPtr(ty::TypeAndMut { ty: dest_ty, .. }) =
destination.ty(local_decls, tcx).ty.kind()
else { bug!(); };
else {
bug!();
};
block.statements.push(Statement {
source_info: terminator.source_info,

View file

@ -38,8 +38,7 @@ impl<'tcx> MirPass<'tcx> for RemoveUninitDrops {
let mut to_remove = vec![];
for (bb, block) in body.basic_blocks.iter_enumerated() {
let terminator = block.terminator();
let TerminatorKind::Drop { place, .. } = &terminator.kind
else { continue };
let TerminatorKind::Drop { place, .. } = &terminator.kind else { continue };
maybe_inits.seek_before_primary_effect(body.terminator_loc(bb));
@ -64,9 +63,9 @@ impl<'tcx> MirPass<'tcx> for RemoveUninitDrops {
for bb in to_remove {
let block = &mut body.basic_blocks_mut()[bb];
let TerminatorKind::Drop { target, .. }
= &block.terminator().kind
else { unreachable!() };
let TerminatorKind::Drop { target, .. } = &block.terminator().kind else {
unreachable!()
};
// Replace block terminator with `Goto`.
block.terminator_mut().kind = TerminatorKind::Goto { target: *target };

View file

@ -199,7 +199,8 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
let last = current;
*start = last;
while let Some((current, mut terminator)) = terminators.pop() {
let Terminator { kind: TerminatorKind::Goto { ref mut target }, .. } = terminator else {
let Terminator { kind: TerminatorKind::Goto { ref mut target }, .. } = terminator
else {
unreachable!();
};
*changed |= *target != last;

View file

@ -161,7 +161,9 @@ struct ReplacementMap<'tcx> {
impl<'tcx> ReplacementMap<'tcx> {
fn replace_place(&self, tcx: TyCtxt<'tcx>, place: PlaceRef<'tcx>) -> Option<Place<'tcx>> {
let &[PlaceElem::Field(f, _), ref rest @ ..] = place.projection else { return None; };
let &[PlaceElem::Field(f, _), ref rest @ ..] = place.projection else {
return None;
};
let fields = self.fragments[place.local].as_ref()?;
let (_, new_local) = fields[f]?;
Some(Place { local: new_local, projection: tcx.mk_place_elems(&rest) })

View file

@ -266,9 +266,11 @@ fn compute_copy_classes(ssa: &mut SsaLocals, body: &Body<'_>) {
let mut copies = IndexVec::from_fn_n(|l| l, body.local_decls.len());
for (local, rvalue, _) in ssa.assignments(body) {
let (Rvalue::Use(Operand::Copy(place) | Operand::Move(place)) | Rvalue::CopyForDeref(place))
= rvalue
else { continue };
let (Rvalue::Use(Operand::Copy(place) | Operand::Move(place))
| Rvalue::CopyForDeref(place)) = rvalue
else {
continue;
};
let Some(rhs) = place.as_local() else { continue };
let local_ty = body.local_decls()[local].ty;

View file

@ -105,7 +105,8 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
for bb in body.basic_blocks.indices() {
trace!("processing block {:?}", bb);
let Some(discriminant_ty) = get_switched_on_type(&body.basic_blocks[bb], tcx, body) else {
let Some(discriminant_ty) = get_switched_on_type(&body.basic_blocks[bb], tcx, body)
else {
continue;
};