More manual clippy fixes

This commit is contained in:
Kirill Bulatov
2020-02-18 15:32:19 +02:00
parent b8ddcb0652
commit eceaf94f19
32 changed files with 141 additions and 159 deletions

View File

@@ -128,7 +128,7 @@ impl FnCallNode {
}),
FnCallNode::MethodCallExpr(call_expr) => {
call_expr.syntax().children().filter_map(ast::NameRef::cast).nth(0)
call_expr.syntax().children().filter_map(ast::NameRef::cast).next()
}
FnCallNode::MacroCallExpr(call_expr) => call_expr.path()?.segment()?.name_ref(),

View File

@@ -59,7 +59,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
.as_ref()
.and_then(|node| node.parent())
.and_then(|node| node.parent())
.and_then(|node| ast::ImplBlock::cast(node));
.and_then(ast::ImplBlock::cast);
if let (Some(trigger), Some(impl_block)) = (trigger, impl_block) {
match trigger.kind() {
@@ -110,17 +110,17 @@ fn add_function_impl(
ctx: &CompletionContext,
func: &hir::Function,
) {
let display = FunctionSignature::from_hir(ctx.db, func.clone());
let display = FunctionSignature::from_hir(ctx.db, *func);
let fn_name = func.name(ctx.db).to_string();
let label = if func.params(ctx.db).len() > 0 {
let label = if !func.params(ctx.db).is_empty() {
format!("fn {}(..)", fn_name)
} else {
format!("fn {}()", fn_name)
};
let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label.clone())
let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
.lookup_by(fn_name)
.set_documentation(func.docs(ctx.db));

View File

@@ -159,7 +159,7 @@ impl CompletionItem {
/// Short one-line additional information, like a type
pub fn detail(&self) -> Option<&str> {
self.detail.as_ref().map(|it| it.as_str())
self.detail.as_deref()
}
/// A doc-comment
pub fn documentation(&self) -> Option<Documentation> {
@@ -167,7 +167,7 @@ impl CompletionItem {
}
/// What string is used for filtering.
pub fn lookup(&self) -> &str {
self.lookup.as_ref().map(|it| it.as_str()).unwrap_or_else(|| self.label())
self.lookup.as_deref().unwrap_or_else(|| self.label())
}
pub fn kind(&self) -> Option<CompletionItemKind> {

View File

@@ -54,9 +54,8 @@ impl FunctionSignature {
pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option<Self> {
let node: ast::StructDef = st.source(db).value;
match node.kind() {
ast::StructKind::Record(_) => return None,
_ => (),
if let ast::StructKind::Record(_) = node.kind() {
return None;
};
let params = st

View File

@@ -64,11 +64,11 @@ impl NavigationTarget {
}
pub fn docs(&self) -> Option<&str> {
self.docs.as_ref().map(String::as_str)
self.docs.as_deref()
}
pub fn description(&self) -> Option<&str> {
self.description.as_ref().map(String::as_str)
self.description.as_deref()
}
/// A "most interesting" range withing the `full_range`.

View File

@@ -268,7 +268,7 @@ fn decl_access(
};
let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?;
if let Some(_) = stmt.initializer() {
if stmt.initializer().is_some() {
let pat = stmt.pat()?;
if let ast::Pat::BindPat(it) = pat {
if it.name()?.text().as_str() == name {

View File

@@ -85,8 +85,11 @@ impl FromStr for SsrQuery {
fn from_str(query: &str) -> Result<SsrQuery, SsrError> {
let mut it = query.split("==>>");
let pattern = it.next().expect("at least empty string").trim();
let mut template =
it.next().ok_or(SsrError("Cannot find delemiter `==>>`".into()))?.trim().to_string();
let mut template = it
.next()
.ok_or_else(|| SsrError("Cannot find delemiter `==>>`".into()))?
.trim()
.to_string();
if it.next().is_some() {
return Err(SsrError("More than one delimiter found".into()));
}
@@ -131,11 +134,12 @@ fn traverse(node: &SyntaxNode, go: &mut impl FnMut(&SyntaxNode) -> bool) {
}
fn split_by_var(s: &str) -> Result<(&str, &str, &str), SsrError> {
let end_of_name = s.find(":").ok_or(SsrError("Use $<name>:expr".into()))?;
let end_of_name = s.find(':').ok_or_else(|| SsrError("Use $<name>:expr".into()))?;
let name = &s[0..end_of_name];
is_name(name)?;
let type_begin = end_of_name + 1;
let type_length = s[type_begin..].find(|c| !char::is_ascii_alphanumeric(&c)).unwrap_or(s.len());
let type_length =
s[type_begin..].find(|c| !char::is_ascii_alphanumeric(&c)).unwrap_or_else(|| s.len());
let type_name = &s[type_begin..type_begin + type_length];
Ok((name, type_name, &s[type_begin + type_length..]))
}
@@ -182,7 +186,7 @@ fn find(pattern: &SsrPattern, code: &SyntaxNode) -> SsrMatches {
pattern.text() == code.text()
}
(SyntaxElement::Node(ref pattern), SyntaxElement::Node(ref code)) => {
if placeholders.iter().find(|&n| n.0.as_str() == pattern.text()).is_some() {
if placeholders.iter().any(|n| n.0.as_str() == pattern.text()) {
match_.binding.insert(Var(pattern.text().to_string()), code.clone());
true
} else {