Skip to content

Commit 62a82b3

Browse files
committed
Format let-chains across the code base
In the updated nightly version, it seems that rustfmt now supports formatting let-chains. Since we're using them a lot, it's a lot of reformatting.
1 parent 5eee19e commit 62a82b3

File tree

159 files changed

+1799
-1471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+1799
-1471
lines changed

Diff for: clippy_lints/src/almost_complete_range.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,20 @@ fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg
8282
(
8383
Ok(LitKind::Byte(b'a') | LitKind::Char('a')),
8484
Ok(LitKind::Byte(b'z') | LitKind::Char('z'))
85-
)
86-
| (
85+
) | (
8786
Ok(LitKind::Byte(b'A') | LitKind::Char('A')),
8887
Ok(LitKind::Byte(b'Z') | LitKind::Char('Z')),
89-
)
90-
| (
88+
) | (
9189
Ok(LitKind::Byte(b'0') | LitKind::Char('0')),
9290
Ok(LitKind::Byte(b'9') | LitKind::Char('9')),
9391
)
9492
)
9593
&& !in_external_macro(cx.sess(), span)
9694
{
97-
span_lint_and_then(
98-
cx,
99-
ALMOST_COMPLETE_RANGE,
100-
span,
101-
"almost complete ascii range",
102-
|diag| {
103-
if let Some((span, sugg)) = sugg {
104-
diag.span_suggestion(
105-
span,
106-
"use an inclusive range",
107-
sugg,
108-
Applicability::MaybeIncorrect,
109-
);
110-
}
95+
span_lint_and_then(cx, ALMOST_COMPLETE_RANGE, span, "almost complete ascii range", |diag| {
96+
if let Some((span, sugg)) = sugg {
97+
diag.span_suggestion(span, "use an inclusive range", sugg, Applicability::MaybeIncorrect);
11198
}
112-
);
99+
});
113100
}
114101
}

Diff for: clippy_lints/src/arc_with_non_send_sync.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,21 @@ impl<'tcx> LateLintPass<'tcx> for ArcWithNonSendSync {
6262
ARC_WITH_NON_SEND_SYNC,
6363
expr.span,
6464
"usage of an `Arc` that is not `Send` or `Sync`",
65-
|diag| with_forced_trimmed_paths!({
66-
if !is_send {
67-
diag.note(format!("the trait `Send` is not implemented for `{arg_ty}`"));
68-
}
69-
if !is_sync {
70-
diag.note(format!("the trait `Sync` is not implemented for `{arg_ty}`"));
71-
}
65+
|diag| {
66+
with_forced_trimmed_paths!({
67+
if !is_send {
68+
diag.note(format!("the trait `Send` is not implemented for `{arg_ty}`"));
69+
}
70+
if !is_sync {
71+
diag.note(format!("the trait `Sync` is not implemented for `{arg_ty}`"));
72+
}
7273

73-
diag.note(format!("required for `{ty}` to implement `Send` and `Sync`"));
74+
diag.note(format!("required for `{ty}` to implement `Send` and `Sync`"));
7475

75-
diag.help("consider using an `Rc` instead or wrapping the inner type with a `Mutex`");
76-
}
77-
));
76+
diag.help("consider using an `Rc` instead or wrapping the inner type with a `Mutex`");
77+
});
78+
},
79+
);
7880
}
7981
}
8082
}

Diff for: clippy_lints/src/assertions_on_result_states.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
5858
return;
5959
}
6060
}
61-
let semicolon = if is_expr_final_block_expr(cx.tcx, e) {";"} else {""};
61+
let semicolon = if is_expr_final_block_expr(cx.tcx, e) { ";" } else { "" };
6262
let mut app = Applicability::MachineApplicable;
6363
match method_segment.ident.as_str() {
6464
"is_ok" if type_suitable_to_unwrap(cx, args.type_at(1)) => {
@@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
7474
),
7575
app,
7676
);
77-
}
77+
},
7878
"is_err" if type_suitable_to_unwrap(cx, args.type_at(0)) => {
7979
span_lint_and_sugg(
8080
cx,
@@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
8888
),
8989
app,
9090
);
91-
}
91+
},
9292
_ => (),
9393
};
9494
}

Diff for: clippy_lints/src/async_yields_async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
22
use clippy_utils::source::snippet;
33
use clippy_utils::ty::implements_trait;
44
use rustc_errors::Applicability;
5-
use rustc_hir::{CoroutineSource, Body, BodyId, CoroutineKind, ExprKind, QPath};
5+
use rustc_hir::{Body, BodyId, CoroutineKind, CoroutineSource, ExprKind, QPath};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88

Diff for: clippy_lints/src/attrs.rs

+27-8
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,26 @@ fn check_should_panic_reason(cx: &LateContext<'_>, attr: &Attribute) {
602602

603603
if let AttrArgs::Delimited(args) = &normal_attr.item.args
604604
&& let mut tt_iter = args.tokens.trees()
605-
&& let Some(TokenTree::Token(Token { kind: TokenKind::Ident(sym::expected, _), .. }, _)) = tt_iter.next()
606-
&& let Some(TokenTree::Token(Token { kind: TokenKind::Eq, .. }, _)) = tt_iter.next()
607-
&& let Some(TokenTree::Token(Token { kind: TokenKind::Literal(_), .. }, _)) = tt_iter.next()
605+
&& let Some(TokenTree::Token(
606+
Token {
607+
kind: TokenKind::Ident(sym::expected, _),
608+
..
609+
},
610+
_,
611+
)) = tt_iter.next()
612+
&& let Some(TokenTree::Token(
613+
Token {
614+
kind: TokenKind::Eq, ..
615+
},
616+
_,
617+
)) = tt_iter.next()
618+
&& let Some(TokenTree::Token(
619+
Token {
620+
kind: TokenKind::Literal(_),
621+
..
622+
},
623+
_,
624+
)) = tt_iter.next()
608625
{
609626
// `#[should_panic(expected = "..")]` found, good
610627
return;
@@ -914,7 +931,9 @@ fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
914931
fn check_nested_misused_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
915932
for item in items {
916933
if let NestedMetaItem::MetaItem(meta) = item {
917-
if meta.has_name(sym!(features)) && let Some(val) = meta.value_str() {
934+
if meta.has_name(sym!(features))
935+
&& let Some(val) = meta.value_str()
936+
{
918937
span_lint_and_sugg(
919938
cx,
920939
MAYBE_MISUSED_CFG,
@@ -933,16 +952,16 @@ fn check_nested_misused_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
933952
}
934953

935954
fn check_minimal_cfg_condition(cx: &EarlyContext<'_>, attr: &Attribute) {
936-
if attr.has_name(sym::cfg) &&
937-
let Some(items) = attr.meta_item_list()
955+
if attr.has_name(sym::cfg)
956+
&& let Some(items) = attr.meta_item_list()
938957
{
939958
check_nested_cfg(cx, &items);
940959
}
941960
}
942961

943962
fn check_misused_cfg(cx: &EarlyContext<'_>, attr: &Attribute) {
944-
if attr.has_name(sym::cfg) &&
945-
let Some(items) = attr.meta_item_list()
963+
if attr.has_name(sym::cfg)
964+
&& let Some(items) = attr.meta_item_list()
946965
{
947966
check_nested_misused_cfg(cx, &items);
948967
}

Diff for: clippy_lints/src/await_holding_invalid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::{match_def_path, paths};
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_hir::def_id::DefId;
6-
use rustc_hir::{CoroutineSource, Body, CoroutineKind};
6+
use rustc_hir::{Body, CoroutineKind, CoroutineSource};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_middle::mir::CoroutineLayout;
99
use rustc_session::{declare_tool_lint, impl_lint_pass};

Diff for: clippy_lints/src/bool_to_int_with_if.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ impl<'tcx> LateLintPass<'tcx> for BoolToIntWithIf {
5555
}
5656

5757
fn check_if_else<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'tcx>) {
58-
if let Some(If { cond, then, r#else: Some(r#else) }) = If::hir(expr)
58+
if let Some(If {
59+
cond,
60+
then,
61+
r#else: Some(r#else),
62+
}) = If::hir(expr)
5963
&& let Some(then_lit) = int_literal(then)
6064
&& let Some(else_lit) = int_literal(r#else)
6165
{
@@ -90,27 +94,26 @@ fn check_if_else<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'tcx>
9094
let into_snippet = snippet.clone().maybe_par();
9195
let as_snippet = snippet.as_ty(ty);
9296

93-
span_lint_and_then(cx,
97+
span_lint_and_then(
98+
cx,
9499
BOOL_TO_INT_WITH_IF,
95100
expr.span,
96101
"boolean to int conversion using if",
97102
|diag| {
98-
diag.span_suggestion(
99-
expr.span,
100-
"replace with from",
101-
suggestion,
102-
applicability,
103-
);
104-
diag.note(format!("`{as_snippet}` or `{into_snippet}.into()` can also be valid options"));
105-
});
103+
diag.span_suggestion(expr.span, "replace with from", suggestion, applicability);
104+
diag.note(format!(
105+
"`{as_snippet}` or `{into_snippet}.into()` can also be valid options"
106+
));
107+
},
108+
);
106109
};
107110
}
108111

109112
// If block contains only a int literal expression, return literal expression
110113
fn int_literal<'tcx>(expr: &'tcx rustc_hir::Expr<'tcx>) -> Option<&'tcx rustc_hir::Expr<'tcx>> {
111114
if let ExprKind::Block(block, _) = expr.kind
112115
&& let Block {
113-
stmts: [], // Shouldn't lint if statements with side effects
116+
stmts: [], // Shouldn't lint if statements with side effects
114117
expr: Some(expr),
115118
..
116119
} = block

Diff for: clippy_lints/src/booleans.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
472472
self.bool_expr(e);
473473
},
474474
ExprKind::Unary(UnOp::Not, inner) => {
475-
if let ExprKind::Unary(UnOp::Not, ex) = inner.kind &&
476-
!self.cx.typeck_results().node_types()[ex.hir_id].is_bool() {
475+
if let ExprKind::Unary(UnOp::Not, ex) = inner.kind
476+
&& !self.cx.typeck_results().node_types()[ex.hir_id].is_bool()
477+
{
477478
return;
478479
}
479480
if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() {
@@ -500,10 +501,10 @@ struct NotSimplificationVisitor<'a, 'tcx> {
500501

501502
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
502503
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
503-
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind &&
504-
!inner.span.from_expansion() &&
505-
let Some(suggestion) = simplify_not(self.cx, inner)
506-
&& self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow
504+
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind
505+
&& !inner.span.from_expansion()
506+
&& let Some(suggestion) = simplify_not(self.cx, inner)
507+
&& self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow
507508
{
508509
span_lint_and_sugg(
509510
self.cx,

Diff for: clippy_lints/src/box_default.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ impl LateLintPass<'_> for BoxDefault {
6161
} else if let Some(arg_ty) = cx.typeck_results().expr_ty(arg).make_suggestable(cx.tcx, true) {
6262
with_forced_trimmed_paths!(format!("Box::<{arg_ty}>::default()"))
6363
} else {
64-
return
64+
return;
6565
},
66-
Applicability::MachineApplicable
66+
Applicability::MachineApplicable,
6767
);
6868
}
6969
}
@@ -110,7 +110,8 @@ fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
110110
Node::Expr(Expr {
111111
kind: ExprKind::Call(path, args),
112112
..
113-
}) | Node::Block(Block {
113+
})
114+
| Node::Block(Block {
114115
expr:
115116
Some(Expr {
116117
kind: ExprKind::Call(path, args),
@@ -119,10 +120,10 @@ fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
119120
..
120121
}),
121122
) => {
122-
if let Some(index) = args.iter().position(|arg| arg.hir_id == expr.hir_id) &&
123-
let Some(sig) = expr_sig(cx, path) &&
124-
let Some(input) = sig.input(index) &&
125-
!cx.typeck_results().expr_ty_adjusted(expr).boxed_ty().is_trait()
123+
if let Some(index) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
124+
&& let Some(sig) = expr_sig(cx, path)
125+
&& let Some(input) = sig.input(index)
126+
&& !cx.typeck_results().expr_ty_adjusted(expr).boxed_ty().is_trait()
126127
{
127128
input.no_bound_vars().is_some()
128129
} else {

Diff for: clippy_lints/src/casts/as_ptr_cast_mut.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ use rustc_middle::ty::{self, Ty, TypeAndMut};
99
use super::AS_PTR_CAST_MUT;
1010

1111
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>) {
12-
if let ty::RawPtr(ptrty @ TypeAndMut { mutbl: Mutability::Mut, .. }) = cast_to.kind()
13-
&& let ty::RawPtr(TypeAndMut { mutbl: Mutability::Not, .. }) =
14-
cx.typeck_results().node_type(cast_expr.hir_id).kind()
12+
if let ty::RawPtr(
13+
ptrty @ TypeAndMut {
14+
mutbl: Mutability::Mut, ..
15+
},
16+
) = cast_to.kind()
17+
&& let ty::RawPtr(TypeAndMut {
18+
mutbl: Mutability::Not, ..
19+
}) = cx.typeck_results().node_type(cast_expr.hir_id).kind()
1520
&& let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind
1621
&& method_name.ident.name == rustc_span::sym::as_ptr
17-
&& let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id)
22+
&& let Some(as_ptr_did) = cx
23+
.typeck_results()
24+
.type_dependent_def_id(cast_expr.peel_blocks().hir_id)
1825
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).instantiate_identity()
1926
&& let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next()
2027
&& let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind()
@@ -30,7 +37,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
3037
&format!("casting the result of `as_ptr` to *{ptrty}"),
3138
"replace with",
3239
format!("{recv}.as_mut_ptr()"),
33-
applicability
40+
applicability,
3441
);
3542
}
3643
}

Diff for: clippy_lints/src/casts/cast_ptr_alignment.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
2626
// There probably is no obvious reason to do this, just to be consistent with `as` cases.
2727
&& !is_hir_ty_cfg_dependant(cx, cast_to)
2828
{
29-
let (cast_from, cast_to) =
30-
(cx.typeck_results().expr_ty(self_arg), cx.typeck_results().expr_ty(expr));
29+
let (cast_from, cast_to) = (cx.typeck_results().expr_ty(self_arg), cx.typeck_results().expr_ty(expr));
3130
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
3231
}
3332
}
@@ -81,9 +80,9 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
8180
cx.tcx.get_diagnostic_name(def_id),
8281
Some(
8382
sym::ptr_write_unaligned
84-
| sym::ptr_read_unaligned
85-
| sym::intrinsics_unaligned_volatile_load
86-
| sym::intrinsics_unaligned_volatile_store
83+
| sym::ptr_read_unaligned
84+
| sym::intrinsics_unaligned_volatile_load
85+
| sym::intrinsics_unaligned_volatile_store
8786
)
8887
)
8988
{

Diff for: clippy_lints/src/casts/unnecessary_cast.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ pub(super) fn check<'tcx>(
9797
}
9898

9999
// skip cast of fn call that returns type alias
100-
if let ExprKind::Cast(inner, ..) = expr.kind && is_cast_from_ty_alias(cx, inner, cast_from) {
100+
if let ExprKind::Cast(inner, ..) = expr.kind
101+
&& is_cast_from_ty_alias(cx, inner, cast_from)
102+
{
101103
return false;
102104
}
103105

@@ -189,11 +191,10 @@ fn lint_unnecessary_cast(
189191
let sugg = if let Some(parent_expr) = get_parent_expr(cx, expr)
190192
&& let ExprKind::MethodCall(..) = parent_expr.kind
191193
&& literal_str.starts_with('-')
192-
{
193-
format!("({literal_str}_{cast_to})")
194-
195-
} else {
196-
format!("{literal_str}_{cast_to}")
194+
{
195+
format!("({literal_str}_{cast_to})")
196+
} else {
197+
format!("{literal_str}_{cast_to}")
197198
};
198199

199200
span_lint_and_sugg(
@@ -269,7 +270,9 @@ fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx
269270
&& let Some(parent) = get_parent_node(cx.tcx, hir_id)
270271
&& let Node::Local(l) = parent
271272
{
272-
if let Some(e) = l.init && is_cast_from_ty_alias(cx, e, cast_from) {
273+
if let Some(e) = l.init
274+
&& is_cast_from_ty_alias(cx, e, cast_from)
275+
{
273276
return ControlFlow::Break::<()>(());
274277
}
275278

Diff for: clippy_lints/src/default_instead_of_iter_empty.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ fn make_sugg(
6868
_ => None,
6969
})
7070
{
71-
format!("std::iter::empty::<{}>()", snippet_with_context(cx, iter_ty.span, ctxt, "..", applicability).0)
71+
format!(
72+
"std::iter::empty::<{}>()",
73+
snippet_with_context(cx, iter_ty.span, ctxt, "..", applicability).0
74+
)
7275
} else {
7376
"std::iter::empty()".to_owned()
7477
}

0 commit comments

Comments
 (0)