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

@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
let adjustments = cx.typeck_results().expr_adjustments(receiver_arg);
let Some(Adjustment { kind: Adjust::Borrow(_), target }) = adjustments.last() else {
return
return;
};
let types =

View file

@ -793,9 +793,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
_ => return,
}
let Some(debug) = cx.tcx.get_diagnostic_item(sym::Debug) else {
return
};
let Some(debug) = cx.tcx.get_diagnostic_item(sym::Debug) else { return };
if self.impling_types.is_none() {
let mut impls = LocalDefIdSet::default();
@ -1458,9 +1456,7 @@ impl TypeAliasBounds {
impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
let hir::ItemKind::TyAlias(ty, type_alias_generics) = &item.kind else {
return
};
let hir::ItemKind::TyAlias(ty, type_alias_generics) = &item.kind else { return };
if cx.tcx.type_of(item.owner_id.def_id).skip_binder().has_opaque_types() {
// Bounds are respected for `type X = impl Trait` and `type X = (impl Trait, Y);`
return;
@ -2147,8 +2143,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
match predicate.bounded_ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => {
let Res::Def(DefKind::TyParam, def_id) = path.res else {
continue;
};
continue;
};
let index = ty_generics.param_def_id_to_index[&def_id];
(
Self::lifetimes_outliving_type(inferred_outlives, index),
@ -2570,7 +2566,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
Some((variant, definitely_inhabited))
});
let Some(first_variant) = potential_variants.next() else {
return Some(InitError::from("enums with no inhabited variants have no valid value").spanned(span));
return Some(
InitError::from("enums with no inhabited variants have no valid value")
.spanned(span),
);
};
// So we have at least one potentially inhabited variant. Might we have two?
let Some(second_variant) = potential_variants.next() else {
@ -3181,7 +3180,7 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
let mut chars = possible_label.chars();
let Some(c) = chars.next() else {
// Empty string means a leading ':' in this section, which is not a label
break
break;
};
// A label starts with an alphabetic character or . or _ and continues with alphanumeric characters, _, or $
if (c.is_alphabetic() || matches!(c, '.' | '_'))

View file

@ -37,7 +37,9 @@ declare_lint_pass!(CastRefToMut => [CAST_REF_TO_MUT]);
impl<'tcx> LateLintPass<'tcx> for CastRefToMut {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
let ExprKind::Unary(UnOp::Deref, e) = &expr.kind else { return; };
let ExprKind::Unary(UnOp::Deref, e) = &expr.kind else {
return;
};
let e = e.peel_blocks();
let e = if let ExprKind::Cast(e, t) = e.kind

View file

@ -119,7 +119,9 @@ fn suggest_question_mark<'tcx>(
span: Span,
) -> bool {
let Some(body_id) = cx.enclosing_body else { return false };
let Some(into_iterator_did) = cx.tcx.get_diagnostic_item(sym::IntoIterator) else { return false };
let Some(into_iterator_did) = cx.tcx.get_diagnostic_item(sym::IntoIterator) else {
return false;
};
if !cx.tcx.is_diagnostic_item(sym::Result, adt.did()) {
return false;

View file

@ -265,7 +265,10 @@ impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
self.specs.lint_level_id_at_node(self.tcx, LintId::of(lint), self.cur)
}
fn push_expectation(&mut self, id: LintExpectationId, expectation: LintExpectation) {
let LintExpectationId::Stable { attr_id: Some(attr_id), hir_id, attr_index, .. } = id else { bug!("unstable expectation id should already be mapped") };
let LintExpectationId::Stable { attr_id: Some(attr_id), hir_id, attr_index, .. } = id
else {
bug!("unstable expectation id should already be mapped")
};
let key = LintExpectationId::Unstable { attr_id, lint_index: None };
self.unstable_to_stable_ids.entry(key).or_insert(LintExpectationId::Stable {
@ -542,7 +545,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
let Ok(ids) = self.store.find_lints(&lint_name) else {
// errors handled in check_lint_name_cmdline above
continue
continue;
};
for id in ids {
// ForceWarn and Forbid cannot be overridden
@ -685,9 +688,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
Some(lvl) => lvl,
};
let Some(mut metas) = attr.meta_item_list() else {
continue
};
let Some(mut metas) = attr.meta_item_list() else { continue };
if metas.is_empty() {
// This emits the unused_attributes lint for `#[level()]`
@ -956,8 +957,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
continue;
}
let LintLevelSource::Node { name: lint_attr_name, span: lint_attr_span, .. } = *src else {
continue
let LintLevelSource::Node { name: lint_attr_name, span: lint_attr_span, .. } = *src
else {
continue;
};
self.emit_spanned_lint(

View file

@ -79,8 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
// We only care about method calls corresponding to the `Clone`, `Deref` and `Borrow`
// traits and ignore any other method call.
let Some((DefKind::AssocFn, did)) =
cx.typeck_results().type_dependent_def(expr.hir_id)
let Some((DefKind::AssocFn, did)) = cx.typeck_results().type_dependent_def(expr.hir_id)
else {
return;
};
@ -98,9 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
.tcx
.normalize_erasing_regions(cx.param_env, cx.typeck_results().node_substs(expr.hir_id));
// Resolve the trait method instance.
let Ok(Some(i)) = ty::Instance::resolve(cx.tcx, cx.param_env, did, substs) else {
return
};
let Ok(Some(i)) = ty::Instance::resolve(cx.tcx, cx.param_env, did, substs) else { return };
// (Re)check that it implements the noop diagnostic.
let Some(name) = cx.tcx.get_diagnostic_name(i.def_id()) else { return };

View file

@ -68,7 +68,9 @@ declare_lint_pass!(OpaqueHiddenInferredBound => [OPAQUE_HIDDEN_INFERRED_BOUND]);
impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
let hir::ItemKind::OpaqueTy(opaque) = &item.kind else { return; };
let hir::ItemKind::OpaqueTy(opaque) = &item.kind else {
return;
};
let def_id = item.owner_id.def_id.to_def_id();
let infcx = &cx.tcx.infer_ctxt().build();
// For every projection predicate in the opaque type's explicit bounds,
@ -116,7 +118,12 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
.subst_iter_copied(cx.tcx, &proj.projection_ty.substs)
{
let assoc_pred = assoc_pred.fold_with(proj_replacer);
let Ok(assoc_pred) = traits::fully_normalize(infcx, traits::ObligationCause::dummy(), cx.param_env, assoc_pred) else {
let Ok(assoc_pred) = traits::fully_normalize(
infcx,
traits::ObligationCause::dummy(),
cx.param_env,
assoc_pred,
) else {
continue;
};
// If that predicate doesn't hold modulo regions (but passed during type-check),

View file

@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
let predicates = cx.tcx.explicit_predicates_of(item.owner_id);
for &(predicate, span) in predicates.predicates {
let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() else {
continue
continue;
};
let def_id = trait_predicate.trait_ref.def_id;
if cx.tcx.lang_items().drop_trait() == Some(def_id) {
@ -100,9 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
if trait_predicate.trait_ref.self_ty().is_impl_trait() {
continue;
}
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else {
return
};
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
cx.emit_spanned_lint(
DROP_BOUNDS,
span,
@ -113,15 +111,11 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
}
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx hir::Ty<'tcx>) {
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else {
return
};
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
for bound in &bounds[..] {
let def_id = bound.trait_ref.trait_def_id();
if cx.tcx.lang_items().drop_trait() == def_id {
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else {
return
};
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
cx.emit_spanned_lint(DYN_DROP, bound.span, DropGlue { tcx: cx.tcx, def_id });
}
}

View file

@ -560,7 +560,10 @@ fn lint_nan<'tcx>(
let expr = expr.peel_blocks().peel_borrows();
match expr.kind {
ExprKind::Path(qpath) => {
let Some(def_id) = cx.typeck_results().qpath_res(&qpath, expr.hir_id).opt_def_id() else { return false; };
let Some(def_id) = cx.typeck_results().qpath_res(&qpath, expr.hir_id).opt_def_id()
else {
return false;
};
matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::f32_nan | sym::f64_nan))
}
@ -1584,10 +1587,10 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
let t = cx.tcx.type_of(it.owner_id).subst_identity();
let ty = cx.tcx.erase_regions(t);
let Ok(layout) = cx.layout_of(ty) else { return };
let Variants::Multiple {
tag_encoding: TagEncoding::Direct, tag, ref variants, ..
} = &layout.variants else {
return
let Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, ref variants, .. } =
&layout.variants
else {
return;
};
let tag_size = tag.size(&cx.tcx).bytes();
@ -1760,8 +1763,13 @@ impl InvalidAtomicOrdering {
}
fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak])
else {return };
let Some((method, args)) = Self::inherent_atomic_method_call(
cx,
expr,
&[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak],
) else {
return;
};
let fail_order_arg = match method {
sym::fetch_update => &args[1],

View file

@ -94,7 +94,9 @@ declare_lint_pass!(UnusedResults => [UNUSED_MUST_USE, UNUSED_RESULTS]);
impl<'tcx> LateLintPass<'tcx> for UnusedResults {
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
let hir::StmtKind::Semi(mut expr) = s.kind else { return; };
let hir::StmtKind::Semi(mut expr) = s.kind else {
return;
};
let mut expr_is_from_block = false;
while let hir::ExprKind::Block(blk, ..) = expr.kind