Skip to content

Commit f7b7a09

Browse files
bors[bot]kjeremy
andauthored
Merge #7696
7696: Fix a few clippy::perf warnings r=kjeremy a=kjeremy Co-authored-by: kjeremy <[email protected]>
2 parents cc49502 + f9bb398 commit f7b7a09

File tree

8 files changed

+14
-12
lines changed

8 files changed

+14
-12
lines changed

crates/ide/src/doc_links.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn rewrite_intra_doc_link(
232232
let items = t.items(db);
233233
if let Some(field_or_assoc_item) = items.iter().find_map(|assoc_item| {
234234
if let Some(name) = assoc_item.name(db) {
235-
if link.to_string() == format!("{}::{}", canonical_path, name) {
235+
if *link == format!("{}::{}", canonical_path, name) {
236236
return Some(FieldOrAssocItem::AssocItem(*assoc_item));
237237
}
238238
}

crates/ide/src/goto_definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) fn goto_definition(
3131
let original_token = pick_best(file.token_at_offset(position.offset))?;
3232
let token = sema.descend_into_macros(original_token.clone());
3333
let parent = token.parent();
34-
if let Some(comment) = ast::Comment::cast(token.clone()) {
34+
if let Some(comment) = ast::Comment::cast(token) {
3535
let nav = def_for_doc_comment(&sema, position, &comment)?.try_to_nav(db)?;
3636
return Some(RangeInfo::new(original_token.text_range(), vec![nav]));
3737
}

crates/ide/src/references/rename.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,10 @@ fn rename_to_self(sema: &Semantics<RootDatabase>, local: hir::Local) -> RenameRe
342342

343343
// FIXME: reimplement this on the hir instead
344344
// as of the time of this writing params in hir don't keep their names
345-
let fn_ast =
346-
fn_def.source(sema.db).ok_or(format_err!("Cannot rename non-param local to self"))?.value;
345+
let fn_ast = fn_def
346+
.source(sema.db)
347+
.ok_or_else(|| format_err!("Cannot rename non-param local to self"))?
348+
.value;
347349

348350
let first_param_range = fn_ast
349351
.param_list()

crates/ide/src/view_hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use syntax::{algo::find_node_at_offset, ast, AstNode};
1111
// | VS Code | **Rust Analyzer: View Hir**
1212
// |===
1313
pub(crate) fn view_hir(db: &RootDatabase, position: FilePosition) -> String {
14-
body_hir(db, position).unwrap_or("Not inside a function body".to_string())
14+
body_hir(db, position).unwrap_or_else(|| "Not inside a function body".to_string())
1515
}
1616

1717
fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {

crates/ide_db/src/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl<'a> FindUsages<'a> {
345345
for (file_id, search_range) in search_scope {
346346
let text = sema.db.file_text(file_id);
347347
let search_range =
348-
search_range.unwrap_or(TextRange::up_to(TextSize::of(text.as_str())));
348+
search_range.unwrap_or_else(|| TextRange::up_to(TextSize::of(text.as_str())));
349349

350350
let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());
351351

crates/project_model/src/build_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) type BuildDataMap = FxHashMap<String, BuildData>;
6161

6262
impl BuildDataCollector {
6363
pub(crate) fn add_config(&mut self, workspace_root: &AbsPath, config: BuildDataConfig) {
64-
self.configs.insert(workspace_root.to_path_buf().clone(), config);
64+
self.configs.insert(workspace_root.to_path_buf(), config);
6565
}
6666

6767
pub fn collect(&mut self, progress: &dyn Fn(String)) -> Result<BuildDataResult> {

crates/rust-analyzer/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl Config {
519519
.data
520520
.checkOnSave_target
521521
.clone()
522-
.or(self.data.cargo_target.clone()),
522+
.or_else(|| self.data.cargo_target.clone()),
523523
all_targets: self.data.checkOnSave_allTargets,
524524
no_default_features: self
525525
.data
@@ -533,7 +533,7 @@ impl Config {
533533
.data
534534
.checkOnSave_features
535535
.clone()
536-
.unwrap_or(self.data.cargo_features.clone()),
536+
.unwrap_or_else(|| self.data.cargo_features.clone()),
537537
extra_args: self.data.checkOnSave_extraArgs.clone(),
538538
},
539539
};
@@ -731,7 +731,7 @@ fn get_field<T: DeserializeOwned>(
731731
fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value {
732732
for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) {
733733
fn key(f: &str) -> &str {
734-
f.splitn(2, "_").next().unwrap()
734+
f.splitn(2, '_').next().unwrap()
735735
}
736736
assert!(key(f1) <= key(f2), "wrong field order: {:?} {:?}", f1, f2);
737737
}

crates/rust-analyzer/src/to_proto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,10 @@ pub(crate) fn code_lens(
891891

892892
let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
893893

894-
let doc_pos = lsp_types::TextDocumentPositionParams::new(id.clone(), position);
894+
let doc_pos = lsp_types::TextDocumentPositionParams::new(id, position);
895895

896896
let goto_params = lsp_types::request::GotoImplementationParams {
897-
text_document_position_params: doc_pos.clone(),
897+
text_document_position_params: doc_pos,
898898
work_done_progress_params: Default::default(),
899899
partial_result_params: Default::default(),
900900
};

0 commit comments

Comments
 (0)