Skip to content

Commit 69cd3c3

Browse files
committed
Format let-else
1 parent 28fcd1b commit 69cd3c3

File tree

38 files changed

+571
-305
lines changed

38 files changed

+571
-305
lines changed

crates/hir-def/src/attr.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,16 @@ impl Attrs {
137137

138138
let cfg_options = &crate_graph[krate].cfg_options;
139139

140-
let Some(variant) = enum_.variants.clone().filter(|variant| {
141-
let attrs = item_tree.attrs(db, krate, (*variant).into());
142-
attrs.is_cfg_enabled(cfg_options)
143-
})
144-
.zip(0u32..)
145-
.find(|(_variant, idx)| it.local_id == Idx::from_raw(RawIdx::from(*idx)))
146-
.map(|(variant, _idx)| variant)
140+
let Some(variant) = enum_
141+
.variants
142+
.clone()
143+
.filter(|variant| {
144+
let attrs = item_tree.attrs(db, krate, (*variant).into());
145+
attrs.is_cfg_enabled(cfg_options)
146+
})
147+
.zip(0u32..)
148+
.find(|(_variant, idx)| it.local_id == Idx::from_raw(RawIdx::from(*idx)))
149+
.map(|(variant, _idx)| variant)
147150
else {
148151
return Arc::new(res);
149152
};

crates/hir-def/src/body/lower.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,9 +1451,7 @@ impl ExprCollector<'_> {
14511451
&self,
14521452
lifetime: Option<ast::Lifetime>,
14531453
) -> Result<Option<LabelId>, BodyDiagnostic> {
1454-
let Some(lifetime) = lifetime else {
1455-
return Ok(None)
1456-
};
1454+
let Some(lifetime) = lifetime else { return Ok(None) };
14571455
let name = Name::new_lifetime(&lifetime);
14581456

14591457
for (rib_idx, rib) in self.label_ribs.iter().enumerate().rev() {

crates/hir-def/src/nameres/collector.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,8 +2235,12 @@ impl ModCollector<'_, '_> {
22352235
}
22362236

22372237
fn import_all_legacy_macros(&mut self, module_id: LocalModuleId) {
2238-
let Some((source, target)) = Self::borrow_modules(self.def_collector.def_map.modules.as_mut(), module_id, self.module_id) else {
2239-
return
2238+
let Some((source, target)) = Self::borrow_modules(
2239+
self.def_collector.def_map.modules.as_mut(),
2240+
module_id,
2241+
self.module_id,
2242+
) else {
2243+
return;
22402244
};
22412245

22422246
for (name, macs) in source.scope.legacy_macros() {

crates/hir-def/src/path.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ impl Path {
135135

136136
pub fn segments(&self) -> PathSegments<'_> {
137137
let Path::Normal { mod_path, generic_args, .. } = self else {
138-
return PathSegments {
139-
segments: &[],
140-
generic_args: None,
141-
};
138+
return PathSegments { segments: &[], generic_args: None };
142139
};
143140
let s =
144141
PathSegments { segments: mod_path.segments(), generic_args: generic_args.as_deref() };

crates/hir-def/src/path/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path
7474
// <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo
7575
Some(trait_ref) => {
7676
let Path::Normal { mod_path, generic_args: path_generic_args, .. } =
77-
Path::from_src(trait_ref.path()?, ctx)? else
78-
{
77+
Path::from_src(trait_ref.path()?, ctx)?
78+
else {
7979
return None;
8080
};
8181
let num_segments = mod_path.segments().len();

crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ pub(crate) fn include_arg_to_tt(
692692
arg_id: MacroCallId,
693693
) -> Result<(triomphe::Arc<(::tt::Subtree<::tt::TokenId>, TokenMap)>, FileId), ExpandError> {
694694
let loc = db.lookup_intern_macro_call(arg_id);
695-
let Some(EagerCallInfo {arg, arg_id: Some(arg_id), .. }) = loc.eager.as_deref() else {
695+
let Some(EagerCallInfo { arg, arg_id: Some(arg_id), .. }) = loc.eager.as_deref() else {
696696
panic!("include_arg_to_tt called on non include macro call: {:?}", &loc.eager);
697697
};
698698
let path = parse_string(&arg.0)?;

crates/hir-expand/src/db.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -471,17 +471,13 @@ fn macro_expand(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<Arc<tt
471471
};
472472
let Some(macro_arg) = db.macro_arg(id) else {
473473
return ExpandResult {
474-
value: Arc::new(
475-
tt::Subtree {
476-
delimiter: tt::Delimiter::UNSPECIFIED,
477-
token_trees: Vec::new(),
478-
},
479-
),
474+
value: Arc::new(tt::Subtree {
475+
delimiter: tt::Delimiter::UNSPECIFIED,
476+
token_trees: Vec::new(),
477+
}),
480478
// FIXME: We should make sure to enforce an invariant that invalid macro
481479
// calls do not reach this call path!
482-
err: Some(ExpandError::other(
483-
"invalid token tree"
484-
)),
480+
err: Some(ExpandError::other("invalid token tree")),
485481
};
486482
};
487483
let (arg_tt, arg_tm, undo_info) = &*macro_arg;
@@ -510,9 +506,7 @@ fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<A
510506
delimiter: tt::Delimiter::UNSPECIFIED,
511507
token_trees: Vec::new(),
512508
}),
513-
err: Some(ExpandError::other(
514-
"invalid token tree"
515-
)),
509+
err: Some(ExpandError::other("invalid token tree")),
516510
};
517511
};
518512
let (arg_tt, arg_tm, undo_info) = &*macro_arg;

crates/hir-expand/src/eager.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ pub fn expand_eager_macro_input(
4242
let token_tree = macro_call.value.token_tree();
4343

4444
let Some(token_tree) = token_tree else {
45-
return Ok(ExpandResult { value: None, err:
46-
Some(ExpandError::other(
47-
"invalid token tree"
48-
)),
45+
return Ok(ExpandResult {
46+
value: None,
47+
err: Some(ExpandError::other("invalid token tree")),
4948
});
5049
};
5150
let (parsed_args, arg_token_map) = mbe::syntax_node_to_token_tree(token_tree.syntax());
@@ -85,7 +84,7 @@ pub fn expand_eager_macro_input(
8584
resolver,
8685
)?;
8786
let Some(expanded_eager_input) = expanded_eager_input else {
88-
return Ok(ExpandResult { value: None, err })
87+
return Ok(ExpandResult { value: None, err });
8988
};
9089
let (mut subtree, token_map) = mbe::syntax_node_to_token_tree(&expanded_eager_input);
9190
subtree.delimiter = crate::tt::Delimiter::unspecified();

crates/hir-ty/src/chalk_ext.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ impl TyExt for Ty {
343343

344344
fn is_copy(self, db: &dyn HirDatabase, owner: DefWithBodyId) -> bool {
345345
let crate_id = owner.module(db.upcast()).krate();
346-
let Some(copy_trait) = db.lang_item(crate_id, LangItem::Copy).and_then(|x| x.as_trait()) else {
346+
let Some(copy_trait) = db.lang_item(crate_id, LangItem::Copy).and_then(|x| x.as_trait())
347+
else {
347348
return false;
348349
};
349350
let trait_ref = TyBuilder::trait_ref(db, copy_trait).push(self).build();

crates/hir-ty/src/display.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ fn render_const_scalar(
636636
}
637637
hir_def::AdtId::EnumId(e) => {
638638
let Some((var_id, var_layout)) =
639-
detect_variant_from_bytes(&layout, f.db, krate, b, e) else {
639+
detect_variant_from_bytes(&layout, f.db, krate, b, e)
640+
else {
640641
return f.write_str("<failed-to-detect-variant>");
641642
};
642643
let data = &f.db.enum_data(e).variants[var_id];

0 commit comments

Comments
 (0)