Skip to content

Commit cc80c5b

Browse files
committed
remove unnecessary lazy evaluations
1 parent 7530d76 commit cc80c5b

File tree

31 files changed

+50
-51
lines changed

31 files changed

+50
-51
lines changed

crates/hir-def/src/item_scope.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,14 @@ impl ItemScope {
159159
pub(crate) fn name_of(&self, item: ItemInNs) -> Option<(&Name, Visibility)> {
160160
let (def, mut iter) = match item {
161161
ItemInNs::Macros(def) => {
162-
return self
163-
.macros
164-
.iter()
165-
.find_map(|(name, &(other_def, vis))| (other_def == def).then(|| (name, vis)));
162+
return self.macros.iter().find_map(|(name, &(other_def, vis))| {
163+
(other_def == def).then_some((name, vis))
164+
});
166165
}
167166
ItemInNs::Types(def) => (def, self.types.iter()),
168167
ItemInNs::Values(def) => (def, self.values.iter()),
169168
};
170-
iter.find_map(|(name, &(other_def, vis))| (other_def == def).then(|| (name, vis)))
169+
iter.find_map(|(name, &(other_def, vis))| (other_def == def).then_some((name, vis)))
171170
}
172171

173172
pub(crate) fn traits<'a>(&'a self) -> impl Iterator<Item = TraitId> + 'a {

crates/hir-def/src/macro_expansion_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
170170
}
171171
let pp = pretty_print_macro_expansion(
172172
parse.syntax_node(),
173-
show_token_ids.then(|| &*token_map),
173+
show_token_ids.then_some(&*token_map),
174174
);
175175
let indent = IndentLevel::from_node(call.syntax());
176176
let pp = reindent(indent, pp);

crates/hir-expand/src/eager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn eager_macro_recur(
208208
// Collect replacement
209209
for child in children {
210210
let def = match child.path().and_then(|path| ModPath::from_src(db, path, hygiene)) {
211-
Some(path) => macro_resolver(path.clone()).ok_or_else(|| UnresolvedMacro { path })?,
211+
Some(path) => macro_resolver(path.clone()).ok_or(UnresolvedMacro { path })?,
212212
None => {
213213
diagnostic_sink(ExpandError::Other("malformed macro invocation".into()));
214214
continue;

crates/hir-ty/src/layout/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn eval_goal(ra_fixture: &str, minicore: &str) -> Result<Layout, LayoutError> {
3737
hir_def::AdtId::UnionId(x) => db.union_data(x).name.to_smol_str(),
3838
hir_def::AdtId::EnumId(x) => db.enum_data(x).name.to_smol_str(),
3939
};
40-
(name == "Goal").then(|| x)
40+
(name == "Goal").then_some(x)
4141
}
4242
_ => None,
4343
})

crates/hir-ty/src/method_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ fn lookup_impl_assoc_item_for_trait_ref(
714714
let impl_data = find_matching_impl(impls, table, trait_ref)?;
715715
impl_data.items.iter().find_map(|it| match it {
716716
AssocItemId::FunctionId(f) => {
717-
(db.function_data(*f).name == *name).then(|| AssocItemId::FunctionId(*f))
717+
(db.function_data(*f).name == *name).then_some(AssocItemId::FunctionId(*f))
718718
}
719719
AssocItemId::ConstId(c) => db
720720
.const_data(*c)

crates/hir-ty/src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl TraitEnvironment {
6161
) -> impl Iterator<Item = TraitId> + 'a {
6262
self.traits_from_clauses
6363
.iter()
64-
.filter_map(move |(self_ty, trait_id)| (*self_ty == ty).then(|| *trait_id))
64+
.filter_map(move |(self_ty, trait_id)| (*self_ty == ty).then_some(*trait_id))
6565
}
6666
}
6767

crates/hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ impl Function {
15591559
}
15601560

15611561
pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
1562-
self.has_self_param(db).then(|| SelfParam { func: self.id })
1562+
self.has_self_param(db).then_some(SelfParam { func: self.id })
15631563
}
15641564

15651565
pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> {

crates/hir/src/semantics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ impl<'db> SemanticsImpl<'db> {
795795
// requeue the tokens we got from mapping our current token down
796796
stack.extend(mapped_tokens);
797797
// if the length changed we have found a mapping for the token
798-
(stack.len() != len).then(|| ())
798+
(stack.len() != len).then_some(())
799799
};
800800

801801
// Remap the next token in the queue into a macro call its in, if it is not being remapped
@@ -1221,7 +1221,7 @@ impl<'db> SemanticsImpl<'db> {
12211221
krate
12221222
.dependencies(self.db)
12231223
.into_iter()
1224-
.find_map(|dep| (dep.name == name).then(|| dep.krate))
1224+
.find_map(|dep| (dep.name == name).then_some(dep.krate))
12251225
}
12261226

12271227
fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantId> {

crates/hir/src/source_analyzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ fn resolve_hir_path_(
987987
db,
988988
def,
989989
res.in_type_ns()?,
990-
|name, id| (name == unresolved.name).then(|| id),
990+
|name, id| (name == unresolved.name).then_some(id),
991991
)
992992
})
993993
.map(TypeAlias::from)

crates/ide-assists/src/handlers/add_missing_match_arms.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl ExtendedEnum {
326326
fn resolve_enum_def(sema: &Semantics<'_, RootDatabase>, expr: &ast::Expr) -> Option<ExtendedEnum> {
327327
sema.type_of_expr(expr)?.adjusted().autoderef(sema.db).find_map(|ty| match ty.as_adt() {
328328
Some(Adt::Enum(e)) => Some(ExtendedEnum::Enum(e)),
329-
_ => ty.is_bool().then(|| ExtendedEnum::Bool),
329+
_ => ty.is_bool().then_some(ExtendedEnum::Bool),
330330
})
331331
}
332332

@@ -344,7 +344,7 @@ fn resolve_tuple_of_enum_def(
344344
// For now we only handle expansion for a tuple of enums. Here
345345
// we map non-enum items to None and rely on `collect` to
346346
// convert Vec<Option<hir::Enum>> into Option<Vec<hir::Enum>>.
347-
_ => ty.is_bool().then(|| ExtendedEnum::Bool),
347+
_ => ty.is_bool().then_some(ExtendedEnum::Bool),
348348
})
349349
})
350350
.collect()

0 commit comments

Comments
 (0)