Skip to content

Commit e1a4cc4

Browse files
Format all the let-chains
1 parent 2763ca5 commit e1a4cc4

File tree

206 files changed

+3123
-2231
lines changed

Some content is hidden

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

206 files changed

+3123
-2231
lines changed

Diff for: compiler/rustc_ast/src/attr/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,7 @@ impl NestedMetaItem {
520520
I: Iterator<Item = &'a TokenTree>,
521521
{
522522
match tokens.peek() {
523-
Some(TokenTree::Token(token, _))
524-
if let Some(lit) = MetaItemLit::from_token(token) =>
525-
{
523+
Some(TokenTree::Token(token, _)) if let Some(lit) = MetaItemLit::from_token(token) => {
526524
tokens.next();
527525
return Some(NestedMetaItem::Lit(lit));
528526
}

Diff for: compiler/rustc_ast/src/entry.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ pub fn entry_point_type(
2121
} else if attr::contains_name(attrs, sym::rustc_main) {
2222
EntryPointType::RustcMainAttr
2323
} else {
24-
if let Some(name) = name && name == sym::main {
24+
if let Some(name) = name
25+
&& name == sym::main
26+
{
2527
if at_root {
2628
// This is a top-level function so it can be `main`.
2729
EntryPointType::MainNamed

Diff for: compiler/rustc_ast/src/token.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,11 @@ impl Lit {
107107
/// Keep this in sync with `Token::can_begin_literal_or_bool` excluding unary negation.
108108
pub fn from_token(token: &Token) -> Option<Lit> {
109109
match token.uninterpolate().kind {
110-
Ident(name, false) if name.is_bool_lit() => {
111-
Some(Lit::new(Bool, name, None))
112-
}
110+
Ident(name, false) if name.is_bool_lit() => Some(Lit::new(Bool, name, None)),
113111
Literal(token_lit) => Some(token_lit),
114112
Interpolated(ref nt)
115113
if let NtExpr(expr) | NtLiteral(expr) = &**nt
116-
&& let ast::ExprKind::Lit(token_lit) = expr.kind =>
114+
&& let ast::ExprKind::Lit(token_lit) = expr.kind =>
117115
{
118116
Some(token_lit)
119117
}
@@ -628,7 +626,9 @@ impl Token {
628626

629627
/// Returns `true` if the token is an interpolated path.
630628
fn is_path(&self) -> bool {
631-
if let Interpolated(nt) = &self.kind && let NtPath(..) = **nt {
629+
if let Interpolated(nt) = &self.kind
630+
&& let NtPath(..) = **nt
631+
{
632632
return true;
633633
}
634634

@@ -650,7 +650,9 @@ impl Token {
650650

651651
/// Is the token an interpolated block (`$b:block`)?
652652
pub fn is_whole_block(&self) -> bool {
653-
if let Interpolated(nt) = &self.kind && let NtBlock(..) = **nt {
653+
if let Interpolated(nt) = &self.kind
654+
&& let NtBlock(..) = **nt
655+
{
654656
return true;
655657
}
656658

Diff for: compiler/rustc_ast/src/tokenstream.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,9 @@ impl TokenStream {
550550

551551
let stream_iter = stream.0.iter().cloned();
552552

553-
if let Some(first) = stream.0.first() && Self::try_glue_to_last(vec_mut, first) {
553+
if let Some(first) = stream.0.first()
554+
&& Self::try_glue_to_last(vec_mut, first)
555+
{
554556
// Now skip the first token tree from `stream`.
555557
vec_mut.extend(stream_iter.skip(1));
556558
} else {

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -673,12 +673,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
673673
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
674674
&& attrs.into_iter().any(|attr| attr.has_name(sym::track_caller))
675675
{
676-
let unstable_span =
677-
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
676+
let unstable_span = self.mark_span_with_reason(
677+
DesugaringKind::Async,
678+
span,
679+
self.allow_gen_future.clone(),
680+
);
678681
self.lower_attrs(
679682
inner_hir_id,
680683
&[Attribute {
681-
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(sym::track_caller, span)))),
684+
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
685+
sym::track_caller,
686+
span,
687+
)))),
682688
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
683689
style: AttrStyle::Outer,
684690
span: unstable_span,
@@ -1102,7 +1108,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
11021108
if let ExprKind::Path(qself, path) = &expr.kind {
11031109
// Does the path resolve to something disallowed in a tuple struct/variant pattern?
11041110
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1105-
if let Some(res) = partial_res.full_res() && !res.expected_in_tuple_struct_pat() {
1111+
if let Some(res) = partial_res.full_res()
1112+
&& !res.expected_in_tuple_struct_pat()
1113+
{
11061114
return None;
11071115
}
11081116
}
@@ -1122,7 +1130,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
11221130
if let ExprKind::Path(qself, path) = &expr.kind {
11231131
// Does the path resolve to something disallowed in a unit struct/variant pattern?
11241132
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1125-
if let Some(res) = partial_res.full_res() && !res.expected_in_unit_struct_pat() {
1133+
if let Some(res) = partial_res.full_res()
1134+
&& !res.expected_in_unit_struct_pat()
1135+
{
11261136
return None;
11271137
}
11281138
}

Diff for: compiler/rustc_ast_lowering/src/format.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ fn flatten_format_args(mut fmt: Cow<'_, FormatArgs>) -> Cow<'_, FormatArgs> {
6161
let remaining_args = args.split_off(arg_index + 1);
6262
let old_arg_offset = args.len();
6363
let mut fmt2 = &mut args.pop().unwrap().expr; // The inner FormatArgs.
64-
let fmt2 = loop { // Unwrap the Expr to get to the FormatArgs.
64+
let fmt2 = loop {
65+
// Unwrap the Expr to get to the FormatArgs.
6566
match &mut fmt2.kind {
66-
ExprKind::Paren(inner) | ExprKind::AddrOf(BorrowKind::Ref, _, inner) => fmt2 = inner,
67+
ExprKind::Paren(inner) | ExprKind::AddrOf(BorrowKind::Ref, _, inner) => {
68+
fmt2 = inner
69+
}
6770
ExprKind::FormatArgs(fmt2) => break fmt2,
6871
_ => unreachable!(),
6972
}

Diff for: compiler/rustc_ast_lowering/src/item.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1387,10 +1387,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
13871387
// Desugar `~const` bound in generics into an additional `const host: bool` param
13881388
// if the effects feature is enabled. This needs to be done before we lower where
13891389
// clauses since where clauses need to bind to the DefId of the host param
1390-
let host_param_parts = if let Const::Yes(span) = constness && self.tcx.features().effects {
1391-
if let Some(param) = generics.params.iter().find(|x| {
1392-
x.attrs.iter().any(|x| x.has_name(sym::rustc_host))
1393-
}) {
1390+
let host_param_parts = if let Const::Yes(span) = constness
1391+
&& self.tcx.features().effects
1392+
{
1393+
if let Some(param) =
1394+
generics.params.iter().find(|x| x.attrs.iter().any(|x| x.has_name(sym::rustc_host)))
1395+
{
13941396
// user has manually specified a `rustc_host` param, in this case, we set
13951397
// the param id so that lowering logic can use that. But we don't create
13961398
// another host param, so this gives `None`.
@@ -1399,7 +1401,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
13991401
} else {
14001402
let param_node_id = self.next_node_id();
14011403
let hir_id = self.next_id();
1402-
let def_id = self.create_def(self.local_def_id(parent_node_id), param_node_id, DefPathData::TypeNs(sym::host), span);
1404+
let def_id = self.create_def(
1405+
self.local_def_id(parent_node_id),
1406+
param_node_id,
1407+
DefPathData::TypeNs(sym::host),
1408+
span,
1409+
);
14031410
self.host_param_id = Some(def_id);
14041411
Some((span, hir_id, def_id))
14051412
}

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12711271
&PolyTraitRef {
12721272
bound_generic_params: ThinVec::new(),
12731273
trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1274-
span: t.span
1274+
span: t.span,
12751275
},
12761276
itctx,
12771277
ast::Const::No,

Diff for: compiler/rustc_ast_lowering/src/lifetime_collector.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
8282
// We can sometimes encounter bare trait objects
8383
// which are represented in AST as paths.
8484
if let Some(partial_res) = self.resolver.get_partial_res(t.id)
85-
&& let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
85+
&& let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) =
86+
partial_res.full_res()
8687
{
8788
self.current_binders.push(t.id);
8889
visit::walk_ty(self, t);

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+40-28
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,15 @@ impl<'a> AstValidator<'a> {
215215
}
216216

217217
fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
218-
if let Some(ident) = field.ident &&
219-
ident.name == kw::Underscore {
220-
self.check_unnamed_field_ty(&field.ty, ident.span);
221-
self.visit_vis(&field.vis);
222-
self.visit_ident(ident);
223-
self.visit_ty_common(&field.ty);
224-
self.walk_ty(&field.ty);
225-
walk_list!(self, visit_attribute, &field.attrs);
218+
if let Some(ident) = field.ident
219+
&& ident.name == kw::Underscore
220+
{
221+
self.check_unnamed_field_ty(&field.ty, ident.span);
222+
self.visit_vis(&field.vis);
223+
self.visit_ident(ident);
224+
self.visit_ty_common(&field.ty);
225+
self.walk_ty(&field.ty);
226+
walk_list!(self, visit_attribute, &field.attrs);
226227
} else {
227228
self.visit_field_def(field);
228229
}
@@ -291,13 +292,11 @@ impl<'a> AstValidator<'a> {
291292
}
292293

293294
fn deny_unnamed_field(&self, field: &FieldDef) {
294-
if let Some(ident) = field.ident &&
295-
ident.name == kw::Underscore {
296-
self.err_handler()
297-
.emit_err(errors::InvalidUnnamedField {
298-
span: field.span,
299-
ident_span: ident.span
300-
});
295+
if let Some(ident) = field.ident
296+
&& ident.name == kw::Underscore
297+
{
298+
self.err_handler()
299+
.emit_err(errors::InvalidUnnamedField { span: field.span, ident_span: ident.span });
301300
}
302301
}
303302

@@ -1180,28 +1179,40 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11801179
(BoundKind::SuperTraits, TraitBoundModifier::Maybe) => {
11811180
self.err_handler().emit_err(errors::OptionalTraitSupertrait {
11821181
span: poly.span,
1183-
path_str: pprust::path_to_string(&poly.trait_ref.path)
1182+
path_str: pprust::path_to_string(&poly.trait_ref.path),
11841183
});
11851184
}
11861185
(BoundKind::TraitObject, TraitBoundModifier::Maybe) => {
1187-
self.err_handler().emit_err(errors::OptionalTraitObject {span: poly.span});
1186+
self.err_handler().emit_err(errors::OptionalTraitObject { span: poly.span });
11881187
}
1189-
(_, TraitBoundModifier::MaybeConst) if let Some(reason) = &self.disallow_tilde_const => {
1188+
(_, TraitBoundModifier::MaybeConst)
1189+
if let Some(reason) = &self.disallow_tilde_const =>
1190+
{
11901191
let reason = match reason {
1191-
DisallowTildeConstContext::TraitObject => errors::TildeConstReason::TraitObject,
1192-
DisallowTildeConstContext::Fn(FnKind::Closure(..)) => errors::TildeConstReason::Closure,
1193-
DisallowTildeConstContext::Fn(FnKind::Fn(_, ident, ..)) => errors::TildeConstReason::Function { ident: ident.span },
1192+
DisallowTildeConstContext::TraitObject => {
1193+
errors::TildeConstReason::TraitObject
1194+
}
1195+
DisallowTildeConstContext::Fn(FnKind::Closure(..)) => {
1196+
errors::TildeConstReason::Closure
1197+
}
1198+
DisallowTildeConstContext::Fn(FnKind::Fn(_, ident, ..)) => {
1199+
errors::TildeConstReason::Function { ident: ident.span }
1200+
}
11941201
};
1195-
self.err_handler().emit_err(errors::TildeConstDisallowed {
1196-
span: bound.span(),
1197-
reason
1198-
});
1202+
self.err_handler()
1203+
.emit_err(errors::TildeConstDisallowed { span: bound.span(), reason });
11991204
}
12001205
(_, TraitBoundModifier::MaybeConstMaybe) => {
1201-
self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span(), modifier: "?" });
1206+
self.err_handler().emit_err(errors::OptionalConstExclusive {
1207+
span: bound.span(),
1208+
modifier: "?",
1209+
});
12021210
}
12031211
(_, TraitBoundModifier::MaybeConstNegative) => {
1204-
self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span(), modifier: "!" });
1212+
self.err_handler().emit_err(errors::OptionalConstExclusive {
1213+
span: bound.span(),
1214+
modifier: "!",
1215+
});
12051216
}
12061217
_ => {}
12071218
}
@@ -1214,7 +1225,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12141225
{
12151226
for arg in &args.args {
12161227
if let ast::AngleBracketedArg::Constraint(constraint) = arg {
1217-
self.err_handler().emit_err(errors::ConstraintOnNegativeBound { span: constraint.span });
1228+
self.err_handler()
1229+
.emit_err(errors::ConstraintOnNegativeBound { span: constraint.span });
12181230
}
12191231
}
12201232
}

Diff for: compiler/rustc_attr/src/builtin.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
405405
}
406406
}
407407

408-
if let Some(s) = since && s.as_str() == VERSION_PLACEHOLDER {
408+
if let Some(s) = since
409+
&& s.as_str() == VERSION_PLACEHOLDER
410+
{
409411
since = Some(rust_version_symbol());
410412
}
411413

@@ -690,13 +692,16 @@ pub fn eval_condition(
690692
!eval_condition(mis[0].meta_item().unwrap(), sess, features, eval)
691693
}
692694
sym::target => {
693-
if let Some(features) = features && !features.cfg_target_compact {
695+
if let Some(features) = features
696+
&& !features.cfg_target_compact
697+
{
694698
feature_err(
695699
sess,
696700
sym::cfg_target_compact,
697701
cfg.span,
698-
"compact `cfg(target(..))` is experimental and subject to change"
699-
).emit();
702+
"compact `cfg(target(..))` is experimental and subject to change",
703+
)
704+
.emit();
700705
}
701706

702707
mis.iter().fold(true, |res, mi| {

0 commit comments

Comments
 (0)