Fix a few clippy::perf warnings

This commit is contained in:
kjeremy 2021-02-16 10:55:34 -05:00
parent cc49502ab4
commit f9bb398cc5
8 changed files with 14 additions and 12 deletions

View file

@ -232,7 +232,7 @@ fn rewrite_intra_doc_link(
let items = t.items(db);
if let Some(field_or_assoc_item) = items.iter().find_map(|assoc_item| {
if let Some(name) = assoc_item.name(db) {
if link.to_string() == format!("{}::{}", canonical_path, name) {
if *link == format!("{}::{}", canonical_path, name) {
return Some(FieldOrAssocItem::AssocItem(*assoc_item));
}
}

View file

@ -31,7 +31,7 @@ pub(crate) fn goto_definition(
let original_token = pick_best(file.token_at_offset(position.offset))?;
let token = sema.descend_into_macros(original_token.clone());
let parent = token.parent();
if let Some(comment) = ast::Comment::cast(token.clone()) {
if let Some(comment) = ast::Comment::cast(token) {
let nav = def_for_doc_comment(&sema, position, &comment)?.try_to_nav(db)?;
return Some(RangeInfo::new(original_token.text_range(), vec![nav]));
}

View file

@ -342,8 +342,10 @@ fn rename_to_self(sema: &Semantics<RootDatabase>, local: hir::Local) -> RenameRe
// FIXME: reimplement this on the hir instead
// as of the time of this writing params in hir don't keep their names
let fn_ast =
fn_def.source(sema.db).ok_or(format_err!("Cannot rename non-param local to self"))?.value;
let fn_ast = fn_def
.source(sema.db)
.ok_or_else(|| format_err!("Cannot rename non-param local to self"))?
.value;
let first_param_range = fn_ast
.param_list()

View file

@ -11,7 +11,7 @@ use syntax::{algo::find_node_at_offset, ast, AstNode};
// | VS Code | **Rust Analyzer: View Hir**
// |===
pub(crate) fn view_hir(db: &RootDatabase, position: FilePosition) -> String {
body_hir(db, position).unwrap_or("Not inside a function body".to_string())
body_hir(db, position).unwrap_or_else(|| "Not inside a function body".to_string())
}
fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {

View file

@ -345,7 +345,7 @@ impl<'a> FindUsages<'a> {
for (file_id, search_range) in search_scope {
let text = sema.db.file_text(file_id);
let search_range =
search_range.unwrap_or(TextRange::up_to(TextSize::of(text.as_str())));
search_range.unwrap_or_else(|| TextRange::up_to(TextSize::of(text.as_str())));
let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());

View file

@ -61,7 +61,7 @@ pub(crate) type BuildDataMap = FxHashMap<String, BuildData>;
impl BuildDataCollector {
pub(crate) fn add_config(&mut self, workspace_root: &AbsPath, config: BuildDataConfig) {
self.configs.insert(workspace_root.to_path_buf().clone(), config);
self.configs.insert(workspace_root.to_path_buf(), config);
}
pub fn collect(&mut self, progress: &dyn Fn(String)) -> Result<BuildDataResult> {

View file

@ -519,7 +519,7 @@ impl Config {
.data
.checkOnSave_target
.clone()
.or(self.data.cargo_target.clone()),
.or_else(|| self.data.cargo_target.clone()),
all_targets: self.data.checkOnSave_allTargets,
no_default_features: self
.data
@ -533,7 +533,7 @@ impl Config {
.data
.checkOnSave_features
.clone()
.unwrap_or(self.data.cargo_features.clone()),
.unwrap_or_else(|| self.data.cargo_features.clone()),
extra_args: self.data.checkOnSave_extraArgs.clone(),
},
};
@ -731,7 +731,7 @@ fn get_field<T: DeserializeOwned>(
fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value {
for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) {
fn key(f: &str) -> &str {
f.splitn(2, "_").next().unwrap()
f.splitn(2, '_').next().unwrap()
}
assert!(key(f1) <= key(f2), "wrong field order: {:?} {:?}", f1, f2);
}

View file

@ -891,10 +891,10 @@ pub(crate) fn code_lens(
let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
let doc_pos = lsp_types::TextDocumentPositionParams::new(id.clone(), position);
let doc_pos = lsp_types::TextDocumentPositionParams::new(id, position);
let goto_params = lsp_types::request::GotoImplementationParams {
text_document_position_params: doc_pos.clone(),
text_document_position_params: doc_pos,
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
};