Minor clippy performance suggestions

This commit is contained in:
kjeremy 2020-09-30 15:22:49 -04:00
parent 7c9ae771bc
commit 82d6cfd495
6 changed files with 7 additions and 7 deletions

View file

@ -146,7 +146,7 @@ fn add_missing_impl_members_inner(
let target = impl_def.syntax().text_range();
acc.add(AssistId(assist_id, AssistKind::QuickFix), label, target, |builder| {
let impl_item_list = impl_def.assoc_item_list().unwrap_or(make::assoc_item_list());
let impl_item_list = impl_def.assoc_item_list().unwrap_or_else(make::assoc_item_list);
let n_existing_items = impl_item_list.assoc_items().count();
let source_scope = ctx.sema.scope_for_def(trait_);

View file

@ -91,7 +91,7 @@ fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVari
.module(db)
.scope(db, None)
.into_iter()
.any(|(name, _)| name.to_string() == variant_name.to_string())
.any(|(name, _)| name.to_string() == variant_name)
}
#[allow(dead_code)]

View file

@ -145,7 +145,7 @@ impl Crate {
}
}).flat_map(|t| t).next();
doc_url.map(|s| s.trim_matches('"').trim_end_matches("/").to_owned() + "/")
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
}
}

View file

@ -120,7 +120,7 @@ fn rewrite_intra_doc_link(
/// Try to resolve path to local documentation via path-based links (i.e. `../gateway/struct.Shard.html`).
fn rewrite_url_link(db: &RootDatabase, def: ModuleDef, target: &str) -> Option<String> {
if !(target.contains("#") || target.contains(".html")) {
if !(target.contains('#') || target.contains(".html")) {
return None;
}
@ -190,7 +190,7 @@ fn strip_prefixes_suffixes(mut s: &str) -> &str {
prefixes.clone().for_each(|prefix| s = s.trim_start_matches(*prefix));
suffixes.clone().for_each(|suffix| s = s.trim_end_matches(*suffix));
});
s.trim_start_matches("@").trim()
s.trim_start_matches('@').trim()
}
static TYPES: ([&str; 7], [&str; 0]) =

View file

@ -205,7 +205,7 @@ impl<'db> ResolutionScope<'db> {
/// Returns the function in which SSR was invoked, if any.
pub(crate) fn current_function(&self) -> Option<SyntaxNode> {
self.node.ancestors().find(|node| node.kind() == SyntaxKind::FN).map(|node| node.clone())
self.node.ancestors().find(|node| node.kind() == SyntaxKind::FN)
}
fn resolve_path(&self, path: &ast::Path) -> Option<hir::PathResolution> {

View file

@ -159,7 +159,7 @@ impl ast::AssocItemList {
let whitespace =
last_token_before_curly.clone().into_token().and_then(ast::Whitespace::cast)?;
let text = whitespace.syntax().text();
let newline = text.rfind("\n")?;
let newline = text.rfind('\n')?;
let keep = tokens::WsBuilder::new(&text[newline..]);
Some(self.replace_children(
first_token_after_items..=last_token_before_curly,