mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-03 00:57:25 +00:00
Fix clippy::or_fun_call
This commit is contained in:
parent
40424d4222
commit
b28ca32db2
12 changed files with 29 additions and 26 deletions
|
@ -334,7 +334,7 @@ fn best_action_for_target<'b, 'a: 'b>(
|
||||||
.filter_map(ast::UseItem::use_tree)
|
.filter_map(ast::UseItem::use_tree)
|
||||||
.map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
|
.map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
|
||||||
.fold(None, |best, a| {
|
.fold(None, |best, a| {
|
||||||
best.and_then(|best| Some(*ImportAction::better(&best, &a))).or(Some(a))
|
best.and_then(|best| Some(*ImportAction::better(&best, &a))).or_else(|| Some(a))
|
||||||
});
|
});
|
||||||
|
|
||||||
match best_action {
|
match best_action {
|
||||||
|
@ -347,7 +347,7 @@ fn best_action_for_target<'b, 'a: 'b>(
|
||||||
let anchor = container
|
let anchor = container
|
||||||
.children()
|
.children()
|
||||||
.find(|n| n.range().start() < anchor.range().start())
|
.find(|n| n.range().start() < anchor.range().start())
|
||||||
.or(Some(anchor));
|
.or_else(|| Some(anchor));
|
||||||
|
|
||||||
return ImportAction::add_new_use(anchor, false);
|
return ImportAction::add_new_use(anchor, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ fn vis_offset(node: &SyntaxNode) -> TextUnit {
|
||||||
})
|
})
|
||||||
.next()
|
.next()
|
||||||
.map(|it| it.range().start())
|
.map(|it| it.range().start())
|
||||||
.unwrap_or(node.range().start())
|
.unwrap_or_else(|| node.range().start())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_vis(mut ctx: AssistCtx<impl HirDatabase>, vis: &ast::Visibility) -> Option<Assist> {
|
fn change_vis(mut ctx: AssistCtx<impl HirDatabase>, vis: &ast::Visibility) -> Option<Assist> {
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl LangItems {
|
||||||
.nth(0);
|
.nth(0);
|
||||||
if let Some(lang_item_name) = lang_item_name {
|
if let Some(lang_item_name) = lang_item_name {
|
||||||
let imp = ImplBlock::from_id(*module, impl_id);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,7 +332,8 @@ impl CrateDefMap {
|
||||||
let name = path.expand_macro_expr()?;
|
let name = path.expand_macro_expr()?;
|
||||||
// search local first
|
// search local first
|
||||||
// FIXME: Remove public_macros check when we have a correct local_macors implementation
|
// 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() {
|
if local.is_some() {
|
||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
|
@ -479,8 +480,10 @@ impl CrateDefMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_name_in_crate_root_or_extern_prelude(&self, name: &Name) -> ItemOrMacro {
|
fn resolve_name_in_crate_root_or_extern_prelude(&self, name: &Name) -> ItemOrMacro {
|
||||||
let from_crate_root =
|
let from_crate_root = self[self.root]
|
||||||
self[self.root].scope.get_item_or_macro(name).unwrap_or(Either::Left(PerNs::none()));
|
.scope
|
||||||
|
.get_item_or_macro(name)
|
||||||
|
.unwrap_or_else(|| Either::Left(PerNs::none()));
|
||||||
let from_extern_prelude = self.resolve_name_in_extern_prelude(name);
|
let from_extern_prelude = self.resolve_name_in_extern_prelude(name);
|
||||||
|
|
||||||
or(from_crate_root, Either::Left(from_extern_prelude))
|
or(from_crate_root, Either::Left(from_extern_prelude))
|
||||||
|
@ -505,8 +508,10 @@ impl CrateDefMap {
|
||||||
// - current module / scope
|
// - current module / scope
|
||||||
// - extern prelude
|
// - extern prelude
|
||||||
// - std prelude
|
// - std prelude
|
||||||
let from_scope =
|
let from_scope = self[module]
|
||||||
self[module].scope.get_item_or_macro(name).unwrap_or(Either::Left(PerNs::none()));;
|
.scope
|
||||||
|
.get_item_or_macro(name)
|
||||||
|
.unwrap_or_else(|| Either::Left(PerNs::none()));;
|
||||||
let from_extern_prelude =
|
let from_extern_prelude =
|
||||||
self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it));
|
self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it));
|
||||||
let from_prelude = self.resolve_in_prelude(db, name);
|
let from_prelude = self.resolve_in_prelude(db, name);
|
||||||
|
@ -525,7 +530,7 @@ impl CrateDefMap {
|
||||||
} else {
|
} else {
|
||||||
db.crate_def_map(prelude.krate)[prelude.module_id].scope.get_item_or_macro(name)
|
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 {
|
} else {
|
||||||
Either::Left(PerNs::none())
|
Either::Left(PerNs::none())
|
||||||
}
|
}
|
||||||
|
|
|
@ -451,7 +451,7 @@ impl Ty {
|
||||||
/// Substitutes `Ty::Bound` vars (as opposed to type parameters).
|
/// Substitutes `Ty::Bound` vars (as opposed to type parameters).
|
||||||
pub fn subst_bound_vars(self, substs: &Substs) -> Ty {
|
pub fn subst_bound_vars(self, substs: &Substs) -> Ty {
|
||||||
self.fold(&mut |ty| match 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,
|
ty => ty,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -462,7 +462,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||||
let mut resolved =
|
let mut resolved =
|
||||||
if remaining_index.is_none() { def.take_values()? } else { def.take_types()? };
|
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<Ty> = None;
|
let mut actual_def_ty: Option<Ty> = None;
|
||||||
|
|
||||||
let krate = resolver.krate()?;
|
let krate = resolver.krate()?;
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
let names = ctx.analyzer.all_names(ctx.db);
|
let names = ctx.analyzer.all_names(ctx.db);
|
||||||
for (name, res) in names.into_iter() {
|
for (name, res) in names.into_iter() {
|
||||||
let r = res.as_ref();
|
let r = res.as_ref();
|
||||||
let def = match r.take_types().or(r.take_values()) {
|
let def = match r.take_types().or_else(|| r.take_values()) {
|
||||||
Some(hir::Resolution::Def(def)) => def,
|
Some(hir::Resolution::Def(def)) => def,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
|
@ -95,7 +95,7 @@ fn extend_single_word_in_comment_or_string(
|
||||||
}
|
}
|
||||||
|
|
||||||
let start_idx = before.rfind(non_word_char)? as u32;
|
let start_idx = before.rfind(non_word_char)? as u32;
|
||||||
let end_idx = after.find(non_word_char).unwrap_or(after.len()) as u32;
|
let end_idx = after.find(non_word_char).unwrap_or_else(|| after.len()) as u32;
|
||||||
|
|
||||||
let from: TextUnit = (start_idx + 1).into();
|
let from: TextUnit = (start_idx + 1).into();
|
||||||
let to: TextUnit = (cursor_position + end_idx).into();
|
let to: TextUnit = (cursor_position + end_idx).into();
|
||||||
|
|
|
@ -49,7 +49,7 @@ fn main_inner() -> Result<()> {
|
||||||
let opts = params
|
let opts = params
|
||||||
.initialization_options
|
.initialization_options
|
||||||
.and_then(|v| InitializationOptions::deserialize(v).ok())
|
.and_then(|v| InitializationOptions::deserialize(v).ok())
|
||||||
.unwrap_or(InitializationOptions::default());
|
.unwrap_or_default();
|
||||||
|
|
||||||
ra_lsp_server::main_loop(workspace_roots, opts, r, s)
|
ra_lsp_server::main_loop(workspace_roots, opts, r, s)
|
||||||
})?;
|
})?;
|
||||||
|
|
|
@ -105,17 +105,15 @@ impl Bindings {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree, ExpandError> {
|
fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree, ExpandError> {
|
||||||
let mut b = self
|
let mut b = self.inner.get(name).ok_or_else(|| {
|
||||||
.inner
|
ExpandError::BindingError(format!("could not find binding `{}`", name))
|
||||||
.get(name)
|
})?;
|
||||||
.ok_or(ExpandError::BindingError(format!("could not find binding `{}`", name)))?;
|
|
||||||
for &idx in nesting.iter() {
|
for &idx in nesting.iter() {
|
||||||
b = match b {
|
b = match b {
|
||||||
Binding::Simple(_) => break,
|
Binding::Simple(_) => break,
|
||||||
Binding::Nested(bs) => bs.get(idx).ok_or(ExpandError::BindingError(format!(
|
Binding::Nested(bs) => bs.get(idx).ok_or_else(|| {
|
||||||
"could not find nested binding `{}`",
|
ExpandError::BindingError(format!("could not find nested binding `{}`", name))
|
||||||
name
|
})?,
|
||||||
)))?,
|
|
||||||
Binding::Empty => {
|
Binding::Empty => {
|
||||||
return Err(ExpandError::BindingError(format!(
|
return Err(ExpandError::BindingError(format!(
|
||||||
"could not find empty binding `{}`",
|
"could not find empty binding `{}`",
|
||||||
|
|
|
@ -125,8 +125,8 @@ fn parse_repeat(p: &mut TtCursor, transcriber: bool) -> Result<crate::Repeat, Pa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sep = p.eat_seperator().ok_or(ParseError::Expected(String::from("separator")))?;
|
let sep = p.eat_seperator().ok_or_else(|| ParseError::Expected(String::from("separator")))?;
|
||||||
let rep = p.eat_punct().ok_or(ParseError::Expected(String::from("repeat")))?;
|
let rep = p.eat_punct().ok_or_else(|| ParseError::Expected(String::from("repeat")))?;
|
||||||
|
|
||||||
mk_repeat(rep.char, subtree, Some(sep))
|
mk_repeat(rep.char, subtree, Some(sep))
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,7 +255,7 @@ where
|
||||||
let first_non_space = str
|
let first_non_space = str
|
||||||
.bytes()
|
.bytes()
|
||||||
.position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r')
|
.position(|b| b != b' ' && b != b'\t' && b != b'\n' && b != b'\r')
|
||||||
.unwrap_or(str.len());
|
.unwrap_or_else(|| str.len());
|
||||||
*chars = str[first_non_space..].chars()
|
*chars = str[first_non_space..].chars()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue