From 3839f9a9a29297128d4dcf85f90d5adcfbf610a6 Mon Sep 17 00:00:00 2001 From: Johann Hemmann Date: Fri, 19 Jan 2024 15:25:51 +0100 Subject: [PATCH] needless_borrow --- Cargo.toml | 1 - crates/hir-def/src/body/lower.rs | 4 ++-- crates/hir-def/src/find_path.rs | 2 +- crates/hir-def/src/import_map.rs | 4 ++-- crates/hir-def/src/lang_item.rs | 2 +- crates/hir-def/src/nameres/collector.rs | 4 ++-- crates/hir-def/src/path.rs | 6 +++--- crates/hir/src/lib.rs | 4 ++-- crates/ide-ssr/src/matching.rs | 2 +- 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b927c78d9cd..b9d9887d56d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -175,7 +175,6 @@ field_reassign_with_default = "allow" forget_non_drop = "allow" format_collect = "allow" large_enum_variant = "allow" -needless_borrow = "allow" needless_doctest_main = "allow" needless_lifetimes = "allow" needless_pass_by_value = "allow" diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs index d9fadf557b9..5fc4867bfa6 100644 --- a/crates/hir-def/src/body/lower.rs +++ b/crates/hir-def/src/body/lower.rs @@ -1844,8 +1844,8 @@ impl ExprCollector<'_> { flags as u128, Some(BuiltinUint::U32), ))); - let precision = self.make_count(&precision, argmap); - let width = self.make_count(&width, argmap); + let precision = self.make_count(precision, argmap); + let width = self.make_count(width, argmap); let format_placeholder_new = { let format_placeholder_new = diff --git a/crates/hir-def/src/find_path.rs b/crates/hir-def/src/find_path.rs index 3ff51b9845c..efda8abf4b8 100644 --- a/crates/hir-def/src/find_path.rs +++ b/crates/hir-def/src/find_path.rs @@ -230,7 +230,7 @@ fn find_path_for_module( } if let value @ Some(_) = - find_in_prelude(ctx.db, &root_def_map, &def_map, ItemInNs::Types(module_id.into()), from) + find_in_prelude(ctx.db, &root_def_map, def_map, ItemInNs::Types(module_id.into()), from) { return value.zip(Some(Stable)); } diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs index 7b38a2041b9..15c127f1562 100644 --- a/crates/hir-def/src/import_map.rs +++ b/crates/hir-def/src/import_map.rs @@ -294,14 +294,14 @@ impl SearchMode { pub fn check(self, query: &str, case_sensitive: bool, candidate: &str) -> bool { match self { SearchMode::Exact if case_sensitive => candidate == query, - SearchMode::Exact => candidate.eq_ignore_ascii_case(&query), + SearchMode::Exact => candidate.eq_ignore_ascii_case(query), SearchMode::Prefix => { query.len() <= candidate.len() && { let prefix = &candidate[..query.len() as usize]; if case_sensitive { prefix == query } else { - prefix.eq_ignore_ascii_case(&query) + prefix.eq_ignore_ascii_case(query) } } } diff --git a/crates/hir-def/src/lang_item.rs b/crates/hir-def/src/lang_item.rs index dd2e8735573..60c8baf424d 100644 --- a/crates/hir-def/src/lang_item.rs +++ b/crates/hir-def/src/lang_item.rs @@ -192,7 +192,7 @@ impl LangItems { pub(crate) fn lang_attr(db: &dyn DefDatabase, item: AttrDefId) -> Option { let attrs = db.attrs(item); - attrs.by_key("lang").string_value().and_then(|it| LangItem::from_str(&it)) + attrs.by_key("lang").string_value().and_then(|it| LangItem::from_str(it)) } pub(crate) fn notable_traits_in_deps( diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 893ad47e241..2d323733714 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -1406,7 +1406,7 @@ impl DefCollector<'_> { } if let errors @ [_, ..] = &*value { let loc: MacroCallLoc = self.db.lookup_intern_macro_call(macro_call_id); - let diag = DefDiagnostic::macro_expansion_parse_error(module_id, loc.kind, &errors); + let diag = DefDiagnostic::macro_expansion_parse_error(module_id, loc.kind, errors); self.def_map.diagnostics.push(diag); } @@ -2287,7 +2287,7 @@ impl ModCollector<'_, '_> { &MacroCall { ref path, ast_id, expand_to, call_site }: &MacroCall, container: ItemContainerId, ) { - let ast_id = AstIdWithPath::new(self.file_id(), ast_id, ModPath::clone(&path)); + let ast_id = AstIdWithPath::new(self.file_id(), ast_id, ModPath::clone(path)); let db = self.def_collector.db; // FIXME: Immediately expanding in "Case 1" is insufficient since "Case 2" may also define diff --git a/crates/hir-def/src/path.rs b/crates/hir-def/src/path.rs index 215c49d4c2c..ff5d39cf53d 100644 --- a/crates/hir-def/src/path.rs +++ b/crates/hir-def/src/path.rs @@ -154,7 +154,7 @@ impl Path { pub fn mod_path(&self) -> Option<&ModPath> { match self { - Path::Normal { mod_path, .. } => Some(&mod_path), + Path::Normal { mod_path, .. } => Some(mod_path), Path::LangItem(..) => None, } } @@ -219,13 +219,13 @@ impl<'a> PathSegments<'a> { } pub fn skip(&self, len: usize) -> PathSegments<'a> { PathSegments { - segments: &self.segments.get(len..).unwrap_or(&[]), + segments: self.segments.get(len..).unwrap_or(&[]), generic_args: self.generic_args.and_then(|it| it.get(len..)), } } pub fn take(&self, len: usize) -> PathSegments<'a> { PathSegments { - segments: &self.segments.get(..len).unwrap_or(&self.segments), + segments: self.segments.get(..len).unwrap_or(self.segments), generic_args: self.generic_args.map(|it| it.get(..len).unwrap_or(it)), } } diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 5d42f7e07ca..3adeef6c189 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1439,7 +1439,7 @@ impl Adt { resolver .generic_params() .and_then(|gp| { - (&gp.lifetimes) + gp.lifetimes .iter() // there should only be a single lifetime // but `Arena` requires to use an iterator @@ -4286,7 +4286,7 @@ impl Type { ) -> impl Iterator + 'a { // iterate the lifetime self.as_adt() - .and_then(|a| a.lifetime(db).map(|lt| (<.name).to_smol_str())) + .and_then(|a| a.lifetime(db).map(|lt| lt.name.to_smol_str())) .into_iter() // add the type and const parameters .chain(self.type_and_const_arguments(db)) diff --git a/crates/ide-ssr/src/matching.rs b/crates/ide-ssr/src/matching.rs index 3e6b2d4dd98..113457ba97e 100644 --- a/crates/ide-ssr/src/matching.rs +++ b/crates/ide-ssr/src/matching.rs @@ -764,7 +764,7 @@ impl Iterator for PatternIterator { type Item = SyntaxElement; fn next(&mut self) -> Option { - (&mut self.iter).find(|element| !element.kind().is_trivia()) + self.iter.find(|element| !element.kind().is_trivia()) } }