From b28ca32db22d5e2ed34db556c6fd50a5fc2d679c Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 3 Jun 2019 10:27:51 -0400 Subject: Fix clippy::or_fun_call --- crates/ra_hir/src/lang_item.rs | 2 +- crates/ra_hir/src/nameres.rs | 17 +++++++++++------ crates/ra_hir/src/ty.rs | 2 +- crates/ra_hir/src/ty/infer.rs | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index 4cacaeba4..684fbc068 100644 --- a/crates/ra_hir/src/lang_item.rs +++ b/crates/ra_hir/src/lang_item.rs @@ -95,7 +95,7 @@ impl LangItems { .nth(0); if let Some(lang_item_name) = lang_item_name { let imp = ImplBlock::from_id(*module, impl_id); - self.items.entry(lang_item_name).or_insert(LangItemTarget::ImplBlock(imp)); + self.items.entry(lang_item_name).or_insert_with(|| LangItemTarget::ImplBlock(imp)); } } diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index d822f7d93..7bddee9b9 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -332,7 +332,8 @@ impl CrateDefMap { let name = path.expand_macro_expr()?; // search local first // FIXME: Remove public_macros check when we have a correct local_macors implementation - let local = self.public_macros.get(&name).or(self.local_macros.get(&name)).map(|it| *it); + let local = + self.public_macros.get(&name).or_else(|| self.local_macros.get(&name)).map(|it| *it); if local.is_some() { return local; } @@ -479,8 +480,10 @@ impl CrateDefMap { } fn resolve_name_in_crate_root_or_extern_prelude(&self, name: &Name) -> ItemOrMacro { - let from_crate_root = - self[self.root].scope.get_item_or_macro(name).unwrap_or(Either::Left(PerNs::none())); + let from_crate_root = self[self.root] + .scope + .get_item_or_macro(name) + .unwrap_or_else(|| Either::Left(PerNs::none())); let from_extern_prelude = self.resolve_name_in_extern_prelude(name); or(from_crate_root, Either::Left(from_extern_prelude)) @@ -505,8 +508,10 @@ impl CrateDefMap { // - current module / scope // - extern prelude // - std prelude - let from_scope = - self[module].scope.get_item_or_macro(name).unwrap_or(Either::Left(PerNs::none()));; + let from_scope = self[module] + .scope + .get_item_or_macro(name) + .unwrap_or_else(|| Either::Left(PerNs::none()));; let from_extern_prelude = self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); let from_prelude = self.resolve_in_prelude(db, name); @@ -525,7 +530,7 @@ impl CrateDefMap { } else { db.crate_def_map(prelude.krate)[prelude.module_id].scope.get_item_or_macro(name) }; - resolution.unwrap_or(Either::Left(PerNs::none())) + resolution.unwrap_or_else(|| Either::Left(PerNs::none())) } else { Either::Left(PerNs::none()) } diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 76d34c12b..4a37e0268 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -451,7 +451,7 @@ impl Ty { /// Substitutes `Ty::Bound` vars (as opposed to type parameters). pub fn subst_bound_vars(self, substs: &Substs) -> Ty { self.fold(&mut |ty| match ty { - Ty::Bound(idx) => substs.get(idx as usize).cloned().unwrap_or(Ty::Bound(idx)), + Ty::Bound(idx) => substs.get(idx as usize).cloned().unwrap_or_else(|| Ty::Bound(idx)), ty => ty, }) } diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 5edc59f18..905fe9f0e 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -462,7 +462,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let mut resolved = if remaining_index.is_none() { def.take_values()? } else { def.take_types()? }; - let remaining_index = remaining_index.unwrap_or(path.segments.len()); + let remaining_index = remaining_index.unwrap_or_else(|| path.segments.len()); let mut actual_def_ty: Option = None; let krate = resolver.krate()?; -- cgit v1.2.3