needless_borrow

This commit is contained in:
Johann Hemmann 2024-01-19 15:25:51 +01:00
parent d351cb8dfb
commit 3839f9a9a2
9 changed files with 14 additions and 15 deletions

View file

@ -175,7 +175,6 @@ field_reassign_with_default = "allow"
forget_non_drop = "allow" forget_non_drop = "allow"
format_collect = "allow" format_collect = "allow"
large_enum_variant = "allow" large_enum_variant = "allow"
needless_borrow = "allow"
needless_doctest_main = "allow" needless_doctest_main = "allow"
needless_lifetimes = "allow" needless_lifetimes = "allow"
needless_pass_by_value = "allow" needless_pass_by_value = "allow"

View file

@ -1844,8 +1844,8 @@ impl ExprCollector<'_> {
flags as u128, flags as u128,
Some(BuiltinUint::U32), Some(BuiltinUint::U32),
))); )));
let precision = self.make_count(&precision, argmap); let precision = self.make_count(precision, argmap);
let width = self.make_count(&width, argmap); let width = self.make_count(width, argmap);
let format_placeholder_new = { let format_placeholder_new = {
let format_placeholder_new = let format_placeholder_new =

View file

@ -230,7 +230,7 @@ fn find_path_for_module(
} }
if let value @ Some(_) = 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)); return value.zip(Some(Stable));
} }

View file

@ -294,14 +294,14 @@ impl SearchMode {
pub fn check(self, query: &str, case_sensitive: bool, candidate: &str) -> bool { pub fn check(self, query: &str, case_sensitive: bool, candidate: &str) -> bool {
match self { match self {
SearchMode::Exact if case_sensitive => candidate == query, 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 => { SearchMode::Prefix => {
query.len() <= candidate.len() && { query.len() <= candidate.len() && {
let prefix = &candidate[..query.len() as usize]; let prefix = &candidate[..query.len() as usize];
if case_sensitive { if case_sensitive {
prefix == query prefix == query
} else { } else {
prefix.eq_ignore_ascii_case(&query) prefix.eq_ignore_ascii_case(query)
} }
} }
} }

View file

@ -192,7 +192,7 @@ impl LangItems {
pub(crate) fn lang_attr(db: &dyn DefDatabase, item: AttrDefId) -> Option<LangItem> { pub(crate) fn lang_attr(db: &dyn DefDatabase, item: AttrDefId) -> Option<LangItem> {
let attrs = db.attrs(item); 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( pub(crate) fn notable_traits_in_deps(

View file

@ -1406,7 +1406,7 @@ impl DefCollector<'_> {
} }
if let errors @ [_, ..] = &*value { if let errors @ [_, ..] = &*value {
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(macro_call_id); 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); self.def_map.diagnostics.push(diag);
} }
@ -2287,7 +2287,7 @@ impl ModCollector<'_, '_> {
&MacroCall { ref path, ast_id, expand_to, call_site }: &MacroCall, &MacroCall { ref path, ast_id, expand_to, call_site }: &MacroCall,
container: ItemContainerId, 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; let db = self.def_collector.db;
// FIXME: Immediately expanding in "Case 1" is insufficient since "Case 2" may also define // FIXME: Immediately expanding in "Case 1" is insufficient since "Case 2" may also define

View file

@ -154,7 +154,7 @@ impl Path {
pub fn mod_path(&self) -> Option<&ModPath> { pub fn mod_path(&self) -> Option<&ModPath> {
match self { match self {
Path::Normal { mod_path, .. } => Some(&mod_path), Path::Normal { mod_path, .. } => Some(mod_path),
Path::LangItem(..) => None, Path::LangItem(..) => None,
} }
} }
@ -219,13 +219,13 @@ impl<'a> PathSegments<'a> {
} }
pub fn skip(&self, len: usize) -> PathSegments<'a> { pub fn skip(&self, len: usize) -> PathSegments<'a> {
PathSegments { 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..)), generic_args: self.generic_args.and_then(|it| it.get(len..)),
} }
} }
pub fn take(&self, len: usize) -> PathSegments<'a> { pub fn take(&self, len: usize) -> PathSegments<'a> {
PathSegments { 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)), generic_args: self.generic_args.map(|it| it.get(..len).unwrap_or(it)),
} }
} }

View file

@ -1439,7 +1439,7 @@ impl Adt {
resolver resolver
.generic_params() .generic_params()
.and_then(|gp| { .and_then(|gp| {
(&gp.lifetimes) gp.lifetimes
.iter() .iter()
// there should only be a single lifetime // there should only be a single lifetime
// but `Arena` requires to use an iterator // but `Arena` requires to use an iterator
@ -4286,7 +4286,7 @@ impl Type {
) -> impl Iterator<Item = SmolStr> + 'a { ) -> impl Iterator<Item = SmolStr> + 'a {
// iterate the lifetime // iterate the lifetime
self.as_adt() self.as_adt()
.and_then(|a| a.lifetime(db).map(|lt| (&lt.name).to_smol_str())) .and_then(|a| a.lifetime(db).map(|lt| lt.name.to_smol_str()))
.into_iter() .into_iter()
// add the type and const parameters // add the type and const parameters
.chain(self.type_and_const_arguments(db)) .chain(self.type_and_const_arguments(db))

View file

@ -764,7 +764,7 @@ impl Iterator for PatternIterator {
type Item = SyntaxElement; type Item = SyntaxElement;
fn next(&mut self) -> Option<SyntaxElement> { fn next(&mut self) -> Option<SyntaxElement> {
(&mut self.iter).find(|element| !element.kind().is_trivia()) self.iter.find(|element| !element.kind().is_trivia())
} }
} }