Rollup merge of #94146 - est31:let_else, r=cjgillot
Adopt let else in more places Continuation of #89933, #91018, #91481, #93046, #93590, #94011. I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
This commit is contained in:
commit
f2d6770f77
132 changed files with 539 additions and 881 deletions
|
@ -66,10 +66,7 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
|
|||
if block.is_cleanup {
|
||||
continue;
|
||||
}
|
||||
let terminator = match &block.terminator {
|
||||
Some(terminator) => terminator,
|
||||
None => continue,
|
||||
};
|
||||
let Some(terminator) = &block.terminator else { continue };
|
||||
let span = terminator.source_info.span;
|
||||
|
||||
let call_can_unwind = match &terminator.kind {
|
||||
|
|
|
@ -84,9 +84,8 @@ fn add_move_for_packed_drop<'tcx>(
|
|||
is_cleanup: bool,
|
||||
) {
|
||||
debug!("add_move_for_packed_drop({:?} @ {:?})", terminator, loc);
|
||||
let (place, target, unwind) = match terminator.kind {
|
||||
TerminatorKind::Drop { ref place, target, unwind } => (place, target, unwind),
|
||||
_ => unreachable!(),
|
||||
let TerminatorKind::Drop { ref place, target, unwind } = terminator.kind else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
let source_info = terminator.source_info;
|
||||
|
|
|
@ -410,12 +410,9 @@ fn check_unused_unsafe(
|
|||
) {
|
||||
let body_id = tcx.hir().maybe_body_owned_by(tcx.hir().local_def_id_to_hir_id(def_id));
|
||||
|
||||
let body_id = match body_id {
|
||||
Some(body) => body,
|
||||
None => {
|
||||
debug!("check_unused_unsafe({:?}) - no body found", def_id);
|
||||
return;
|
||||
}
|
||||
let Some(body_id) = body_id else {
|
||||
debug!("check_unused_unsafe({:?}) - no body found", def_id);
|
||||
return;
|
||||
};
|
||||
let body = tcx.hir().body(body_id);
|
||||
debug!("check_unused_unsafe({:?}, body={:?}, used_unsafe={:?})", def_id, body, used_unsafe);
|
||||
|
|
|
@ -26,11 +26,8 @@ impl<'tcx> MirPass<'tcx> for Deaggregator {
|
|||
|
||||
let stmt = stmt.replace_nop();
|
||||
let source_info = stmt.source_info;
|
||||
let (lhs, kind, operands) = match stmt.kind {
|
||||
StatementKind::Assign(box (lhs, Rvalue::Aggregate(kind, operands))) => {
|
||||
(lhs, kind, operands)
|
||||
}
|
||||
_ => bug!(),
|
||||
let StatementKind::Assign(box (lhs, Rvalue::Aggregate(kind, operands))) = stmt.kind else {
|
||||
bug!();
|
||||
};
|
||||
|
||||
Some(expand_aggregate(
|
||||
|
|
|
@ -98,12 +98,9 @@ fn find_dead_unwinds<'tcx>(
|
|||
|
||||
debug!("find_dead_unwinds @ {:?}: {:?}", bb, bb_data);
|
||||
|
||||
let path = match env.move_data.rev_lookup.find(place.as_ref()) {
|
||||
LookupResult::Exact(e) => e,
|
||||
LookupResult::Parent(..) => {
|
||||
debug!("find_dead_unwinds: has parent; skipping");
|
||||
continue;
|
||||
}
|
||||
let LookupResult::Exact(path) = env.move_data.rev_lookup.find(place.as_ref()) else {
|
||||
debug!("find_dead_unwinds: has parent; skipping");
|
||||
continue;
|
||||
};
|
||||
|
||||
flow_inits.seek_before_primary_effect(body.terminator_loc(bb));
|
||||
|
|
|
@ -1413,22 +1413,16 @@ impl EnsureGeneratorFieldAssignmentsNeverAlias<'_> {
|
|||
|
||||
impl<'tcx> Visitor<'tcx> for EnsureGeneratorFieldAssignmentsNeverAlias<'_> {
|
||||
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
|
||||
let lhs = match self.assigned_local {
|
||||
Some(l) => l,
|
||||
None => {
|
||||
// This visitor only invokes `visit_place` for the right-hand side of an assignment
|
||||
// and only after setting `self.assigned_local`. However, the default impl of
|
||||
// `Visitor::super_body` may call `visit_place` with a `NonUseContext` for places
|
||||
// with debuginfo. Ignore them here.
|
||||
assert!(!context.is_use());
|
||||
return;
|
||||
}
|
||||
let Some(lhs) = self.assigned_local else {
|
||||
// This visitor only invokes `visit_place` for the right-hand side of an assignment
|
||||
// and only after setting `self.assigned_local`. However, the default impl of
|
||||
// `Visitor::super_body` may call `visit_place` with a `NonUseContext` for places
|
||||
// with debuginfo. Ignore them here.
|
||||
assert!(!context.is_use());
|
||||
return;
|
||||
};
|
||||
|
||||
let rhs = match self.saved_local_for_direct_place(*place) {
|
||||
Some(l) => l,
|
||||
None => return,
|
||||
};
|
||||
let Some(rhs) = self.saved_local_for_direct_place(*place) else { return };
|
||||
|
||||
if !self.storage_conflicts.contains(lhs, rhs) {
|
||||
bug!(
|
||||
|
|
|
@ -118,9 +118,8 @@ impl<'tcx> Inliner<'tcx> {
|
|||
continue;
|
||||
}
|
||||
|
||||
let callsite = match self.resolve_callsite(caller_body, bb, bb_data) {
|
||||
None => continue,
|
||||
Some(it) => it,
|
||||
let Some(callsite) = self.resolve_callsite(caller_body, bb, bb_data) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let span = trace_span!("process_blocks", %callsite.callee, ?bb);
|
||||
|
|
|
@ -46,12 +46,9 @@ crate fn mir_callgraph_reachable<'tcx>(
|
|||
trace!(%caller);
|
||||
for &(callee, substs) in tcx.mir_inliner_callees(caller.def) {
|
||||
let substs = caller.subst_mir_and_normalize_erasing_regions(tcx, param_env, substs);
|
||||
let callee = match ty::Instance::resolve(tcx, param_env, callee, substs).unwrap() {
|
||||
Some(callee) => callee,
|
||||
None => {
|
||||
trace!(?callee, "cannot resolve, skipping");
|
||||
continue;
|
||||
}
|
||||
let Some(callee) = ty::Instance::resolve(tcx, param_env, callee, substs).unwrap() else {
|
||||
trace!(?callee, "cannot resolve, skipping");
|
||||
continue;
|
||||
};
|
||||
|
||||
// Found a path.
|
||||
|
|
|
@ -17,9 +17,8 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
|
|||
let terminator = block.terminator.as_mut().unwrap();
|
||||
if let TerminatorKind::Call { func, args, destination, .. } = &mut terminator.kind {
|
||||
let func_ty = func.ty(local_decls, tcx);
|
||||
let (intrinsic_name, substs) = match resolve_rust_intrinsic(tcx, func_ty) {
|
||||
None => continue,
|
||||
Some(it) => it,
|
||||
let Some((intrinsic_name, substs)) = resolve_rust_intrinsic(tcx, func_ty) else {
|
||||
continue;
|
||||
};
|
||||
match intrinsic_name {
|
||||
sym::unreachable => {
|
||||
|
|
|
@ -61,10 +61,7 @@ fn lower_slice_len_call<'tcx>(
|
|||
if args.len() != 1 {
|
||||
return;
|
||||
}
|
||||
let arg = match args[0].place() {
|
||||
Some(arg) => arg,
|
||||
None => return,
|
||||
};
|
||||
let Some(arg) = args[0].place() else { return };
|
||||
let func_ty = func.ty(local_decls, tcx);
|
||||
match func_ty.kind() {
|
||||
ty::FnDef(fn_def_id, _) if fn_def_id == &slice_len_fn_item_def_id => {
|
||||
|
|
|
@ -39,12 +39,9 @@ impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
|
|||
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) {
|
||||
let def_id = body.source.def_id();
|
||||
let returned_local = match local_eligible_for_nrvo(body) {
|
||||
Some(l) => l,
|
||||
None => {
|
||||
debug!("`{:?}` was ineligible for NRVO", def_id);
|
||||
return;
|
||||
}
|
||||
let Some(returned_local) = local_eligible_for_nrvo(body) else {
|
||||
debug!("`{:?}` was ineligible for NRVO", def_id);
|
||||
return;
|
||||
};
|
||||
|
||||
if !tcx.consider_optimizing(|| format!("RenameReturnPlace {:?}", def_id)) {
|
||||
|
|
|
@ -26,9 +26,8 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts {
|
|||
if !maybe_zst(place_ty) {
|
||||
continue;
|
||||
}
|
||||
let layout = match tcx.layout_of(param_env.and(place_ty)) {
|
||||
Ok(layout) => layout,
|
||||
Err(_) => continue,
|
||||
let Ok(layout) = tcx.layout_of(param_env.and(place_ty)) else {
|
||||
continue;
|
||||
};
|
||||
if !layout.is_zst() {
|
||||
continue;
|
||||
|
|
|
@ -734,9 +734,8 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
|
|||
let sig = tcx.fn_sig(ctor_id).no_bound_vars().expect("LBR in ADT constructor signature");
|
||||
let sig = tcx.normalize_erasing_regions(param_env, sig);
|
||||
|
||||
let (adt_def, substs) = match sig.output().kind() {
|
||||
ty::Adt(adt_def, substs) => (adt_def, substs),
|
||||
_ => bug!("unexpected type for ADT ctor {:?}", sig.output()),
|
||||
let ty::Adt(adt_def, substs) = sig.output().kind() else {
|
||||
bug!("unexpected type for ADT ctor {:?}", sig.output());
|
||||
};
|
||||
|
||||
debug!("build_ctor: ctor_id={:?} sig={:?}", ctor_id, sig);
|
||||
|
|
|
@ -172,9 +172,8 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
|
|||
let mut terminators: SmallVec<[_; 1]> = Default::default();
|
||||
let mut current = *start;
|
||||
while let Some(terminator) = self.take_terminator_if_simple_goto(current) {
|
||||
let target = match terminator {
|
||||
Terminator { kind: TerminatorKind::Goto { target }, .. } => target,
|
||||
_ => unreachable!(),
|
||||
let Terminator { kind: TerminatorKind::Goto { target }, .. } = terminator else {
|
||||
unreachable!();
|
||||
};
|
||||
terminators.push((current, terminator));
|
||||
current = target;
|
||||
|
@ -182,9 +181,8 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
|
|||
let last = current;
|
||||
*start = last;
|
||||
while let Some((current, mut terminator)) = terminators.pop() {
|
||||
let target = match terminator {
|
||||
Terminator { kind: TerminatorKind::Goto { ref mut target }, .. } => target,
|
||||
_ => unreachable!(),
|
||||
let Terminator { kind: TerminatorKind::Goto { ref mut target }, .. } = terminator else {
|
||||
unreachable!();
|
||||
};
|
||||
*changed |= *target != last;
|
||||
*target = last;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue