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

@ -714,7 +714,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
_ => None,
};
let Some(borrow_level) = borrow_level else { return false; };
let Some(borrow_level) = borrow_level else {
return false;
};
let sugg = move_sites
.iter()
.map(|move_site| {
@ -763,7 +765,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
.typeck_root_def_id(self.mir_def_id().to_def_id())
.as_local()
.and_then(|def_id| tcx.hir().get_generics(def_id))
else { return; };
else {
return;
};
// Try to find predicates on *generic params* that would allow copying `ty`
let ocx = ObligationCtxt::new(&self.infcx);
let copy_did = tcx.require_lang_item(LangItem::Copy, Some(span));
@ -1220,18 +1224,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return;
};
let inner_param_uses = find_all_local_uses::find(self.body, inner_param.local);
let Some((inner_call_loc, inner_call_term)) = inner_param_uses.into_iter().find_map(|loc| {
let Either::Right(term) = self.body.stmt_at(loc) else {
debug!("{:?} is a statement, so it can't be a call", loc);
return None;
};
let TerminatorKind::Call { args, .. } = &term.kind else {
debug!("not a call: {:?}", term);
return None;
};
debug!("checking call args for uses of inner_param: {:?}", args);
args.contains(&Operand::Move(inner_param)).then_some((loc, term))
}) else {
let Some((inner_call_loc, inner_call_term)) =
inner_param_uses.into_iter().find_map(|loc| {
let Either::Right(term) = self.body.stmt_at(loc) else {
debug!("{:?} is a statement, so it can't be a call", loc);
return None;
};
let TerminatorKind::Call { args, .. } = &term.kind else {
debug!("not a call: {:?}", term);
return None;
};
debug!("checking call args for uses of inner_param: {:?}", args);
args.contains(&Operand::Move(inner_param)).then_some((loc, term))
})
else {
debug!("no uses of inner_param found as a by-move call arg");
return;
};
@ -1442,21 +1448,24 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
// Get closure's arguments
let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else { /* hir::Closure can be a generator too */ return };
let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else {
/* hir::Closure can be a generator too */
return;
};
let sig = substs.as_closure().sig();
let tupled_params =
tcx.erase_late_bound_regions(sig.inputs().iter().next().unwrap().map_bound(|&b| b));
let ty::Tuple(params) = tupled_params.kind() else { return };
// Find the first argument with a matching type, get its name
let Some((_, this_name)) = params
.iter()
.zip(hir.body_param_names(closure.body))
.find(|(param_ty, name)|{
let Some((_, this_name)) =
params.iter().zip(hir.body_param_names(closure.body)).find(|(param_ty, name)| {
// FIXME: also support deref for stuff like `Rc` arguments
param_ty.peel_refs() == local_ty && name != &Ident::empty()
})
else { return };
else {
return;
};
let spans;
if let Some((_path_expr, qpath)) = finder.error_path
@ -2899,7 +2908,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
{
let def_id = def_id.expect_local();
for operand in operands {
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand else {
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) =
operand
else {
continue;
};
debug!(
@ -2908,7 +2919,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
// Find the local from the operand.
let Some(assigned_from_local) = assigned_from.local_or_deref_local() else {
let Some(assigned_from_local) =
assigned_from.local_or_deref_local()
else {
continue;
};
@ -2961,7 +2974,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
// Find the local from the rvalue.
let Some(assigned_from_local) = assigned_from.local_or_deref_local() else { continue };
let Some(assigned_from_local) = assigned_from.local_or_deref_local() else {
continue;
};
debug!(
"annotate_argument_and_return_for_borrow: \
assigned_from_local={:?}",
@ -3009,7 +3024,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
assigned_to, args
);
for operand in args {
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand else {
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand
else {
continue;
};
debug!(

View file

@ -847,14 +847,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
kind: TerminatorKind::Call { fn_span, call_source, .. }, ..
}) = &self.body[location.block].terminator
{
let Some((method_did, method_substs)) =
rustc_middle::util::find_self_call(
self.infcx.tcx,
&self.body,
target_temp,
location.block,
)
else {
let Some((method_did, method_substs)) = rustc_middle::util::find_self_call(
self.infcx.tcx,
&self.body,
target_temp,
location.block,
) else {
return normal_ret;
};

View file

@ -184,7 +184,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
// Error with the pattern
LookupResult::Exact(_) => {
let LookupResult::Parent(Some(mpi)) = self.move_data.rev_lookup.find(move_from.as_ref()) else {
let LookupResult::Parent(Some(mpi)) =
self.move_data.rev_lookup.find(move_from.as_ref())
else {
// move_from should be a projection from match_place.
unreachable!("Probably not unreachable...");
};
@ -494,8 +496,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if let LocalInfo::User(BindingForm::Var(VarBindingForm { pat_span, .. })) =
*bind_to.local_info()
{
let Ok(pat_snippet) =
self.infcx.tcx.sess.source_map().span_to_snippet(pat_span) else { continue; };
let Ok(pat_snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(pat_span)
else {
continue;
};
let Some(stripped) = pat_snippet.strip_prefix('&') else {
suggestions.push((
bind_to.source_info.span.shrink_to_lo(),

View file

@ -648,8 +648,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let def_id = self.body.source.def_id();
let hir_id = hir_map.local_def_id_to_hir_id(def_id.as_local().unwrap());
let node = hir_map.find(hir_id);
let Some(hir::Node::Item(item)) = node else { return; };
let hir::ItemKind::Fn(.., body_id) = item.kind else { return; };
let Some(hir::Node::Item(item)) = node else {
return;
};
let hir::ItemKind::Fn(.., body_id) = item.kind else {
return;
};
let body = self.infcx.tcx.hir().body(body_id);
let mut v = V { assign_span: span, err, ty, suggested: false };

View file

@ -224,12 +224,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let mut hrtb_bounds = vec![];
gat_id_and_generics.iter().flatten().for_each(|(gat_hir_id, generics)| {
for pred in generics.predicates {
let BoundPredicate(
WhereBoundPredicate {
bound_generic_params,
bounds,
..
}) = pred else { continue; };
let BoundPredicate(WhereBoundPredicate { bound_generic_params, bounds, .. }) = pred
else {
continue;
};
if bound_generic_params
.iter()
.rfind(|bgp| hir.local_def_id_to_hir_id(bgp.def_id) == *gat_hir_id)
@ -813,7 +811,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
return;
}
let suitable_region = self.infcx.tcx.is_suitable_region(f);
let Some(suitable_region) = suitable_region else { return; };
let Some(suitable_region) = suitable_region else {
return;
};
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.def_id);
@ -848,7 +848,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let Some((alias_tys, alias_span, lt_addition_span)) = self
.infcx
.tcx
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.def_id) else { return; };
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.def_id)
else {
return;
};
// in case the return type of the method is a type alias
let mut spans_suggs: Vec<_> = Vec::new();
@ -932,8 +935,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let mut visitor = TraitObjectVisitor(FxIndexSet::default());
visitor.visit_ty(param.param_ty);
let Some((ident, self_ty)) =
NiceRegionError::get_impl_ident_and_self_ty_from_trait(tcx, instance.def_id(), &visitor.0) else { return; };
let Some((ident, self_ty)) = NiceRegionError::get_impl_ident_and_self_ty_from_trait(
tcx,
instance.def_id(),
&visitor.0,
) else {
return;
};
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty);
}
@ -981,23 +989,25 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
sup: RegionVid,
) {
let (Some(sub), Some(sup)) = (self.to_error_region(sub), self.to_error_region(sup)) else {
return
return;
};
let Some((ty_sub, _)) = self
.infcx
.tcx
.is_suitable_region(sub)
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sub, &anon_reg.boundregion)) else {
return
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sub, &anon_reg.boundregion))
else {
return;
};
let Some((ty_sup, _)) = self
.infcx
.tcx
.is_suitable_region(sup)
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sup, &anon_reg.boundregion)) else {
return
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sup, &anon_reg.boundregion))
else {
return;
};
suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);

View file

@ -325,8 +325,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
// Can't have BrEnv in functions, constants or generators.
bug!("BrEnv outside of closure.");
};
let hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. })
= tcx.hir().expect_expr(self.mir_hir_id()).kind
let hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }) =
tcx.hir().expect_expr(self.mir_hir_id()).kind
else {
bug!("Closure is not defined by a closure expr");
};

View file

@ -2058,10 +2058,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let mut extra_info = vec![];
for constraint in path.iter() {
let outlived = constraint.sub;
let Some(origin) = self.var_infos.get(outlived) else { continue; };
let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(p)) = origin.origin else { continue; };
let Some(origin) = self.var_infos.get(outlived) else {
continue;
};
let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(p)) = origin.origin
else {
continue;
};
debug!(?constraint, ?p);
let ConstraintCategory::Predicate(span) = constraint.category else { continue; };
let ConstraintCategory::Predicate(span) = constraint.category else {
continue;
};
extra_info.push(ExtraConstraintInfo::PlaceholderFromPredicate(span));
// We only want to point to one
break;

View file

@ -2039,28 +2039,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
CastKind::PointerCoercion(PointerCoercion::MutToConstPointer) => {
let ty::RawPtr(ty::TypeAndMut {
ty: ty_from,
mutbl: hir::Mutability::Mut,
}) = op.ty(body, tcx).kind() else {
span_mirbug!(
self,
rvalue,
"unexpected base type for cast {:?}",
ty,
);
let ty::RawPtr(ty::TypeAndMut { ty: ty_from, mutbl: hir::Mutability::Mut }) =
op.ty(body, tcx).kind()
else {
span_mirbug!(self, rvalue, "unexpected base type for cast {:?}", ty,);
return;
};
let ty::RawPtr(ty::TypeAndMut {
ty: ty_to,
mutbl: hir::Mutability::Not,
}) = ty.kind() else {
span_mirbug!(
self,
rvalue,
"unexpected target type for cast {:?}",
ty,
);
let ty::RawPtr(ty::TypeAndMut { ty: ty_to, mutbl: hir::Mutability::Not }) =
ty.kind()
else {
span_mirbug!(self, rvalue, "unexpected target type for cast {:?}", ty,);
return;
};
if let Err(terr) = self.sub_types(

View file

@ -929,7 +929,9 @@ fn for_each_late_bound_region_in_item<'tcx>(
}
for bound_var in tcx.late_bound_vars(tcx.hir().local_def_id_to_hir_id(mir_def_id)) {
let ty::BoundVariableKind::Region(bound_region) = bound_var else { continue; };
let ty::BoundVariableKind::Region(bound_region) = bound_var else {
continue;
};
let liberated_region = ty::Region::new_free(tcx, mir_def_id.to_def_id(), bound_region);
f(liberated_region);
}