aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAlan Du <[email protected]>2019-06-03 15:27:51 +0100
committerAlan Du <[email protected]>2019-06-04 23:05:07 +0100
commitb28ca32db22d5e2ed34db556c6fd50a5fc2d679c (patch)
tree7e86e3f6ffdbc972b2ac968503f2b3671fd9b3a5 /crates
parent40424d4222d4630bc53294d10f1718f2d3d300de (diff)
Fix clippy::or_fun_call
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/auto_import.rs4
-rw-r--r--crates/ra_assists/src/change_visibility.rs2
-rw-r--r--crates/ra_hir/src/lang_item.rs2
-rw-r--r--crates/ra_hir/src/nameres.rs17
-rw-r--r--crates/ra_hir/src/ty.rs2
-rw-r--r--crates/ra_hir/src/ty/infer.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_pattern.rs2
-rw-r--r--crates/ra_ide_api/src/extend_selection.rs2
-rw-r--r--crates/ra_lsp_server/src/main.rs2
-rw-r--r--crates/ra_mbe/src/mbe_expander.rs14
-rw-r--r--crates/ra_mbe/src/mbe_parser.rs4
-rw-r--r--crates/ra_syntax/src/validation/unescape.rs2
12 files changed, 29 insertions, 26 deletions
diff --git a/crates/ra_assists/src/auto_import.rs b/crates/ra_assists/src/auto_import.rs
index 1566cf179..9617beb5c 100644
--- a/crates/ra_assists/src/auto_import.rs
+++ b/crates/ra_assists/src/auto_import.rs
@@ -334,7 +334,7 @@ fn best_action_for_target<'b, 'a: 'b>(
334 .filter_map(ast::UseItem::use_tree) 334 .filter_map(ast::UseItem::use_tree)
335 .map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target)) 335 .map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
336 .fold(None, |best, a| { 336 .fold(None, |best, a| {
337 best.and_then(|best| Some(*ImportAction::better(&best, &a))).or(Some(a)) 337 best.and_then(|best| Some(*ImportAction::better(&best, &a))).or_else(|| Some(a))
338 }); 338 });
339 339
340 match best_action { 340 match best_action {
@@ -347,7 +347,7 @@ fn best_action_for_target<'b, 'a: 'b>(
347 let anchor = container 347 let anchor = container
348 .children() 348 .children()
349 .find(|n| n.range().start() < anchor.range().start()) 349 .find(|n| n.range().start() < anchor.range().start())
350 .or(Some(anchor)); 350 .or_else(|| Some(anchor));
351 351
352 return ImportAction::add_new_use(anchor, false); 352 return ImportAction::add_new_use(anchor, false);
353 } 353 }
diff --git a/crates/ra_assists/src/change_visibility.rs b/crates/ra_assists/src/change_visibility.rs
index 620f534b5..4eb24d27f 100644
--- a/crates/ra_assists/src/change_visibility.rs
+++ b/crates/ra_assists/src/change_visibility.rs
@@ -59,7 +59,7 @@ fn vis_offset(node: &SyntaxNode) -> TextUnit {
59 }) 59 })
60 .next() 60 .next()
61 .map(|it| it.range().start()) 61 .map(|it| it.range().start())
62 .unwrap_or(node.range().start()) 62 .unwrap_or_else(|| node.range().start())
63} 63}
64 64
65fn change_vis(mut ctx: AssistCtx<impl HirDatabase>, vis: &ast::Visibility) -> Option<Assist> { 65fn change_vis(mut ctx: AssistCtx<impl HirDatabase>, vis: &ast::Visibility) -> Option<Assist> {
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 {
95 .nth(0); 95 .nth(0);
96 if let Some(lang_item_name) = lang_item_name { 96 if let Some(lang_item_name) = lang_item_name {
97 let imp = ImplBlock::from_id(*module, impl_id); 97 let imp = ImplBlock::from_id(*module, impl_id);
98 self.items.entry(lang_item_name).or_insert(LangItemTarget::ImplBlock(imp)); 98 self.items.entry(lang_item_name).or_insert_with(|| LangItemTarget::ImplBlock(imp));
99 } 99 }
100 } 100 }
101 101
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 {
332 let name = path.expand_macro_expr()?; 332 let name = path.expand_macro_expr()?;
333 // search local first 333 // search local first
334 // FIXME: Remove public_macros check when we have a correct local_macors implementation 334 // FIXME: Remove public_macros check when we have a correct local_macors implementation
335 let local = self.public_macros.get(&name).or(self.local_macros.get(&name)).map(|it| *it); 335 let local =
336 self.public_macros.get(&name).or_else(|| self.local_macros.get(&name)).map(|it| *it);
336 if local.is_some() { 337 if local.is_some() {
337 return local; 338 return local;
338 } 339 }
@@ -479,8 +480,10 @@ impl CrateDefMap {
479 } 480 }
480 481
481 fn resolve_name_in_crate_root_or_extern_prelude(&self, name: &Name) -> ItemOrMacro { 482 fn resolve_name_in_crate_root_or_extern_prelude(&self, name: &Name) -> ItemOrMacro {
482 let from_crate_root = 483 let from_crate_root = self[self.root]
483 self[self.root].scope.get_item_or_macro(name).unwrap_or(Either::Left(PerNs::none())); 484 .scope
485 .get_item_or_macro(name)
486 .unwrap_or_else(|| Either::Left(PerNs::none()));
484 let from_extern_prelude = self.resolve_name_in_extern_prelude(name); 487 let from_extern_prelude = self.resolve_name_in_extern_prelude(name);
485 488
486 or(from_crate_root, Either::Left(from_extern_prelude)) 489 or(from_crate_root, Either::Left(from_extern_prelude))
@@ -505,8 +508,10 @@ impl CrateDefMap {
505 // - current module / scope 508 // - current module / scope
506 // - extern prelude 509 // - extern prelude
507 // - std prelude 510 // - std prelude
508 let from_scope = 511 let from_scope = self[module]
509 self[module].scope.get_item_or_macro(name).unwrap_or(Either::Left(PerNs::none()));; 512 .scope
513 .get_item_or_macro(name)
514 .unwrap_or_else(|| Either::Left(PerNs::none()));;
510 let from_extern_prelude = 515 let from_extern_prelude =
511 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); 516 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it));
512 let from_prelude = self.resolve_in_prelude(db, name); 517 let from_prelude = self.resolve_in_prelude(db, name);
@@ -525,7 +530,7 @@ impl CrateDefMap {
525 } else { 530 } else {
526 db.crate_def_map(prelude.krate)[prelude.module_id].scope.get_item_or_macro(name) 531 db.crate_def_map(prelude.krate)[prelude.module_id].scope.get_item_or_macro(name)
527 }; 532 };
528 resolution.unwrap_or(Either::Left(PerNs::none())) 533 resolution.unwrap_or_else(|| Either::Left(PerNs::none()))
529 } else { 534 } else {
530 Either::Left(PerNs::none()) 535 Either::Left(PerNs::none())
531 } 536 }
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 {
451 /// Substitutes `Ty::Bound` vars (as opposed to type parameters). 451 /// Substitutes `Ty::Bound` vars (as opposed to type parameters).
452 pub fn subst_bound_vars(self, substs: &Substs) -> Ty { 452 pub fn subst_bound_vars(self, substs: &Substs) -> Ty {
453 self.fold(&mut |ty| match ty { 453 self.fold(&mut |ty| match ty {
454 Ty::Bound(idx) => substs.get(idx as usize).cloned().unwrap_or(Ty::Bound(idx)), 454 Ty::Bound(idx) => substs.get(idx as usize).cloned().unwrap_or_else(|| Ty::Bound(idx)),
455 ty => ty, 455 ty => ty,
456 }) 456 })
457 } 457 }
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> {
462 let mut resolved = 462 let mut resolved =
463 if remaining_index.is_none() { def.take_values()? } else { def.take_types()? }; 463 if remaining_index.is_none() { def.take_values()? } else { def.take_types()? };
464 464
465 let remaining_index = remaining_index.unwrap_or(path.segments.len()); 465 let remaining_index = remaining_index.unwrap_or_else(|| path.segments.len());
466 let mut actual_def_ty: Option<Ty> = None; 466 let mut actual_def_ty: Option<Ty> = None;
467 467
468 let krate = resolver.krate()?; 468 let krate = resolver.krate()?;
diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs
index 74833a756..6655a05a7 100644
--- a/crates/ra_ide_api/src/completion/complete_pattern.rs
+++ b/crates/ra_ide_api/src/completion/complete_pattern.rs
@@ -10,7 +10,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
10 let names = ctx.analyzer.all_names(ctx.db); 10 let names = ctx.analyzer.all_names(ctx.db);
11 for (name, res) in names.into_iter() { 11 for (name, res) in names.into_iter() {
12 let r = res.as_ref(); 12 let r = res.as_ref();
13 let def = match r.take_types().or(r.take_values()) { 13 let def = match r.take_types().or_else(|| r.take_values()) {
14 Some(hir::Resolution::Def(def)) => def, 14 Some(hir::Resolution::Def(def)) => def,
15 _ => continue, 15 _ => continue,
16 }; 16 };
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs
index 00c445310..a713b762c 100644
--- a/crates/ra_ide_api/src/extend_selection.rs
+++ b/crates/ra_ide_api/src/extend_selection.rs
@@ -95,7 +95,7 @@ fn extend_single_word_in_comment_or_string(
95 } 95 }
96 96
97 let start_idx = before.rfind(non_word_char)? as u32; 97 let start_idx = before.rfind(non_word_char)? as u32;
98 let end_idx = after.find(non_word_char).unwrap_or(after.len()) as u32; 98 let end_idx = after.find(non_word_char).unwrap_or_else(|| after.len()) as u32;
99 99
100 let from: TextUnit = (start_idx + 1).into(); 100 let from: TextUnit = (start_idx + 1).into();
101 let to: TextUnit = (cursor_position + end_idx).into(); 101 let to: TextUnit = (cursor_position + end_idx).into();
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs
index b0b70df5c..a0df32dde 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/ra_lsp_server/src/main.rs
@@ -49,7 +49,7 @@ fn main_inner() -> Result<()> {
49 let opts = params 49 let opts = params
50 .initialization_options 50 .initialization_options
51 .and_then(|v| InitializationOptions::deserialize(v).ok()) 51 .and_then(|v| InitializationOptions::deserialize(v).ok())
52 .unwrap_or(InitializationOptions::default()); 52 .unwrap_or_default();
53 53
54 ra_lsp_server::main_loop(workspace_roots, opts, r, s) 54 ra_lsp_server::main_loop(workspace_roots, opts, r, s)
55 })?; 55 })?;
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs
index 7cfb47f7a..55a6ecf58 100644
--- a/crates/ra_mbe/src/mbe_expander.rs
+++ b/crates/ra_mbe/src/mbe_expander.rs
@@ -105,17 +105,15 @@ impl Bindings {
105 } 105 }
106 106
107 fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree, ExpandError> { 107 fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree, ExpandError> {
108 let mut b = self 108 let mut b = self.inner.get(name).ok_or_else(|| {
109 .inner 109 ExpandError::BindingError(format!("could not find binding `{}`", name))
110 .get(name) 110 })?;
111 .ok_or(ExpandError::BindingError(format!("could not find binding `{}`", name)))?;
112 for &idx in nesting.iter() { 111 for &idx in nesting.iter() {
113 b = match b { 112 b = match b {
114 Binding::Simple(_) => break, 113 Binding::Simple(_) => break,
115 Binding::Nested(bs) => bs.get(idx).ok_or(ExpandError::BindingError(format!( 114 Binding::Nested(bs) => bs.get(idx).ok_or_else(|| {
116 "could not find nested binding `{}`", 115 ExpandError::BindingError(format!("could not find nested binding `{}`", name))
117 name 116 })?,
118 )))?,
119 Binding::Empty => { 117 Binding::Empty => {
120 return Err(ExpandError::BindingError(format!( 118 return Err(ExpandError::BindingError(format!(
121 "could not find empty binding `{}`", 119 "could not find empty binding `{}`",
diff --git a/crates/ra_mbe/src/mbe_parser.rs b/crates/ra_mbe/src/mbe_parser.rs
index d8fe293c7..dca16b537 100644
--- a/crates/ra_mbe/src/mbe_parser.rs
+++ b/crates/ra_mbe/src/mbe_parser.rs
@@ -125,8 +125,8 @@ fn parse_repeat(p: &mut TtCursor, transcriber: bool) -> Result<crate::Repeat, Pa
125 } 125 }
126 } 126 }
127 127
128 let sep = p.eat_seperator().ok_or(ParseError::Expected(String::from("separator")))?; 128 let sep = p.eat_seperator().ok_or_else(|| ParseError::Expected(String::from("separator")))?;
129 let rep = p.eat_punct().ok_or(ParseError::Expected(String::from("repeat")))?; 129 let rep = p.eat_punct().ok_or_else(|| ParseError::Expected(String::from("repeat")))?;
130 130
131 mk_repeat(rep.char, subtree, Some(sep)) 131 mk_repeat(rep.char, subtree, Some(sep))
132} 132}
diff --git a/crates/ra_syntax/src/validation/unescape.rs b/crates/ra_syntax/src/validation/unescape.rs
index 2086046b6..91dbcfae8 100644
--- a/crates/ra_syntax/src/validation/unescape.rs
+++ b/crates/ra_syntax/src/validation/unescape.rs
@@ -255,7 +255,7 @@ where
255 let first_non_space = str 255 let first_non_space = str
256 .bytes() 256 .bytes()
257 .position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r') 257 .position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r')
258 .unwrap_or(str.len()); 258 .unwrap_or_else(|| str.len());
259 *chars = str[first_non_space..].chars() 259 *chars = str[first_non_space..].chars()
260 } 260 }
261} 261}