Skip to content

internal: Work through temporarily allowed clippy lints, part 1 #16404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3409645
bind_instead_of_map
Urhengulas Jan 19, 2024
b5eca5f
collapsible_if
Urhengulas Jan 19, 2024
6573768
iter_kv_map
Urhengulas Jan 19, 2024
4184c6a
collapsible_match
Urhengulas Jan 19, 2024
882289b
double_parens
Urhengulas Jan 19, 2024
2a500d5
for_kv_map
Urhengulas Jan 19, 2024
60dda08
manual_find
Urhengulas Jan 19, 2024
d8ad4af
manual_map
Urhengulas Jan 19, 2024
6a2a603
let_and_return
Urhengulas Jan 19, 2024
c629ec7
clone_on_copy
Urhengulas Jan 19, 2024
9e4f94c
no_effect
Urhengulas Jan 19, 2024
6709eab
never_loop
Urhengulas Jan 19, 2024
eb7aec5
map_clone
Urhengulas Jan 19, 2024
8982ff3
get_first
Urhengulas Jan 19, 2024
84494d1
from_str_radix_10
Urhengulas Jan 19, 2024
5753981
explicit_auto_deref
Urhengulas Jan 19, 2024
c27b6b5
filter_map_bool_then
Urhengulas Jan 19, 2024
2ae2512
if_same_then_else
Urhengulas Jan 19, 2024
add40c8
match_like_matches_macro
Urhengulas Jan 19, 2024
d351cb8
match_single_binding
Urhengulas Jan 19, 2024
3839f9a
needless_borrow
Urhengulas Jan 19, 2024
a342e93
needless_lifetimes
Urhengulas Jan 19, 2024
6699c90
needless_pass_by_value
Urhengulas Jan 19, 2024
e58b683
needless_return
Urhengulas Jan 19, 2024
e6f9f4c
nonminimal_bool
Urhengulas Jan 19, 2024
bef3551
non_minimal_cfg
Urhengulas Jan 19, 2024
0df3049
only_used_in_recursion
Urhengulas Jan 19, 2024
4858a37
op_ref
Urhengulas Jan 19, 2024
7e8568b
option_map_unit_fn
Urhengulas Jan 19, 2024
692212b
partialeq_to_none
Urhengulas Jan 19, 2024
9527e24
redundant_locals
Urhengulas Jan 19, 2024
6738edc
ptr_arg
Urhengulas Jan 19, 2024
3cf1358
question_mark
Urhengulas Jan 19, 2024
5a62a0d
redundant_closure
Urhengulas Jan 19, 2024
71d4dba
redundant_pattern_matching
Urhengulas Jan 19, 2024
159b4c9
search_is_some
Urhengulas Jan 19, 2024
9dd07f0
should_implement_trait
Urhengulas Jan 19, 2024
b1a0c9a
single_match
Urhengulas Jan 19, 2024
9e83779
redundant_locals
Urhengulas Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,59 +159,25 @@ suspicious = { level = "warn", priority = -1 }
result_unit_err = "allow"
# We don't expose public APIs that matter like this
len_without_is_empty = "allow"
# We currently prefer explicit control flow return over `...?;` statements whose result is unused
question_mark = "allow"
# We have macros that rely on this currently
enum_variant_names = "allow"
# Builder pattern disagrees
new_ret_no_self = "allow"

## Following lints should be tackled at some point
bind_instead_of_map = "allow"
borrowed_box = "allow"
borrow_deref_ref = "allow"
collapsible_if = "allow"
collapsible_match = "allow"
clone_on_copy = "allow"
derivable_impls = "allow"
derived_hash_with_manual_eq = "allow"
double_parens = "allow"
explicit_auto_deref = "allow"
field_reassign_with_default = "allow"
forget_non_drop = "allow"
format_collect = "allow"
for_kv_map = "allow"
filter_map_bool_then = "allow"
from_str_radix_10 = "allow"
get_first = "allow"
if_same_then_else = "allow"
large_enum_variant = "allow"
let_and_return = "allow"
manual_find = "allow"
manual_map = "allow"
map_clone = "allow"
match_like_matches_macro = "allow"
match_single_binding = "allow"
needless_borrow = "allow"
needless_doctest_main = "allow"
needless_lifetimes = "allow"
needless_pass_by_value = "allow"
needless_return = "allow"
new_without_default = "allow"
nonminimal_bool = "allow"
non_canonical_clone_impl = "allow"
non_canonical_partial_ord_impl = "allow"
non_minimal_cfg = "allow"
only_used_in_recursion = "allow"
op_ref = "allow"
option_map_unit_fn = "allow"
partialeq_to_none = "allow"
ptr_arg = "allow"
redundant_closure = "allow"
redundant_pattern_matching = "allow"
search_is_some = "allow"
self_named_constructors = "allow"
single_match = "allow"
skip_while_next = "allow"
too_many_arguments = "allow"
toplevel_ref_arg = "allow"
Expand Down
2 changes: 1 addition & 1 deletion crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl CrateData {
return false;
}

if let Some(_) = opts.next() {
if opts.next().is_some() {
return false;
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/hir-def/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ impl Body {
}
}
Pat::Or(args) | Pat::Tuple { args, .. } | Pat::TupleStruct { args, .. } => {
args.iter().copied().for_each(|p| f(p));
args.iter().copied().for_each(f);
}
Pat::Ref { pat, .. } => f(*pat),
Pat::Slice { prefix, slice, suffix } => {
let total_iter = prefix.iter().chain(slice.iter()).chain(suffix.iter());
total_iter.copied().for_each(|p| f(p));
total_iter.copied().for_each(f);
}
Pat::Record { args, .. } => {
args.iter().for_each(|RecordFieldPat { pat, .. }| f(*pat));
Expand Down Expand Up @@ -369,7 +369,7 @@ impl BodySourceMap {
}

pub fn label_syntax(&self, label: LabelId) -> LabelSource {
self.label_map_back[label].clone()
self.label_map_back[label]
}

pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> {
Expand All @@ -378,11 +378,11 @@ impl BodySourceMap {
}

pub fn field_syntax(&self, expr: ExprId) -> FieldSource {
self.field_map_back[&expr].clone()
self.field_map_back[&expr]
}

pub fn pat_field_syntax(&self, pat: PatId) -> PatFieldSource {
self.pat_field_map_back[&pat].clone()
self.pat_field_map_back[&pat]
}

pub fn macro_expansion_expr(&self, node: InFile<&ast::MacroExpr>) -> Option<ExprId> {
Expand Down
51 changes: 24 additions & 27 deletions crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,10 @@ impl ExprCollector<'_> {
None => self.collect_expr_opt(e.condition()),
};

let break_expr =
self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr.clone());
let break_expr = self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr);
let if_expr = self.alloc_expr(
Expr::If { condition, then_branch: body, else_branch: Some(break_expr) },
syntax_ptr.clone(),
syntax_ptr,
);
self.alloc_expr(Expr::Loop { body: if_expr, label }, syntax_ptr)
}
Expand Down Expand Up @@ -811,19 +810,19 @@ impl ExprCollector<'_> {
return self.alloc_expr(Expr::Missing, syntax_ptr);
};
let head = self.collect_expr_opt(e.iterable());
let into_iter_fn_expr = self.alloc_expr(Expr::Path(into_iter_fn), syntax_ptr.clone());
let into_iter_fn_expr = self.alloc_expr(Expr::Path(into_iter_fn), syntax_ptr);
let iterator = self.alloc_expr(
Expr::Call {
callee: into_iter_fn_expr,
args: Box::new([head]),
is_assignee_expr: false,
},
syntax_ptr.clone(),
syntax_ptr,
);
let none_arm = MatchArm {
pat: self.alloc_pat_desugared(Pat::Path(Box::new(option_none))),
guard: None,
expr: self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr.clone()),
expr: self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr),
};
let some_pat = Pat::TupleStruct {
path: Some(Box::new(option_some)),
Expand All @@ -839,27 +838,25 @@ impl ExprCollector<'_> {
}),
};
let iter_name = Name::generate_new_name();
let iter_expr =
self.alloc_expr(Expr::Path(Path::from(iter_name.clone())), syntax_ptr.clone());
let iter_expr = self.alloc_expr(Expr::Path(Path::from(iter_name.clone())), syntax_ptr);
let iter_expr_mut = self.alloc_expr(
Expr::Ref { expr: iter_expr, rawness: Rawness::Ref, mutability: Mutability::Mut },
syntax_ptr.clone(),
syntax_ptr,
);
let iter_next_fn_expr = self.alloc_expr(Expr::Path(iter_next_fn), syntax_ptr.clone());
let iter_next_fn_expr = self.alloc_expr(Expr::Path(iter_next_fn), syntax_ptr);
let iter_next_expr = self.alloc_expr(
Expr::Call {
callee: iter_next_fn_expr,
args: Box::new([iter_expr_mut]),
is_assignee_expr: false,
},
syntax_ptr.clone(),
syntax_ptr,
);
let loop_inner = self.alloc_expr(
Expr::Match { expr: iter_next_expr, arms: Box::new([none_arm, some_arm]) },
syntax_ptr.clone(),
syntax_ptr,
);
let loop_outer =
self.alloc_expr(Expr::Loop { body: loop_inner, label }, syntax_ptr.clone());
let loop_outer = self.alloc_expr(Expr::Loop { body: loop_inner, label }, syntax_ptr);
let iter_binding = self.alloc_binding(iter_name, BindingAnnotation::Mutable);
let iter_pat = self.alloc_pat_desugared(Pat::Bind { id: iter_binding, subpat: None });
self.add_definition_to_binding(iter_binding, iter_pat);
Expand All @@ -868,7 +865,7 @@ impl ExprCollector<'_> {
expr: iterator,
arms: Box::new([MatchArm { pat: iter_pat, guard: None, expr: loop_outer }]),
},
syntax_ptr.clone(),
syntax_ptr,
)
}

Expand Down Expand Up @@ -896,10 +893,10 @@ impl ExprCollector<'_> {
return self.alloc_expr(Expr::Missing, syntax_ptr);
};
let operand = self.collect_expr_opt(e.expr());
let try_branch = self.alloc_expr(Expr::Path(try_branch), syntax_ptr.clone());
let try_branch = self.alloc_expr(Expr::Path(try_branch), syntax_ptr);
let expr = self.alloc_expr(
Expr::Call { callee: try_branch, args: Box::new([operand]), is_assignee_expr: false },
syntax_ptr.clone(),
syntax_ptr,
);
let continue_name = Name::generate_new_name();
let continue_binding =
Expand All @@ -914,7 +911,7 @@ impl ExprCollector<'_> {
ellipsis: None,
}),
guard: None,
expr: self.alloc_expr(Expr::Path(Path::from(continue_name)), syntax_ptr.clone()),
expr: self.alloc_expr(Expr::Path(Path::from(continue_name)), syntax_ptr),
};
let break_name = Name::generate_new_name();
let break_binding = self.alloc_binding(break_name.clone(), BindingAnnotation::Unannotated);
Expand All @@ -928,18 +925,18 @@ impl ExprCollector<'_> {
}),
guard: None,
expr: {
let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr.clone());
let callee = self.alloc_expr(Expr::Path(try_from_residual), syntax_ptr.clone());
let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr);
let callee = self.alloc_expr(Expr::Path(try_from_residual), syntax_ptr);
let result = self.alloc_expr(
Expr::Call { callee, args: Box::new([it]), is_assignee_expr: false },
syntax_ptr.clone(),
syntax_ptr,
);
self.alloc_expr(
match self.current_try_block_label {
Some(label) => Expr::Break { expr: Some(result), label: Some(label) },
None => Expr::Return { expr: Some(result) },
},
syntax_ptr.clone(),
syntax_ptr,
)
},
};
Expand Down Expand Up @@ -1847,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 =
Expand Down Expand Up @@ -1994,7 +1991,7 @@ impl ExprCollector<'_> {
fn alloc_expr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId {
let src = self.expander.in_file(ptr);
let id = self.body.exprs.alloc(expr);
self.source_map.expr_map_back.insert(id, src.clone());
self.source_map.expr_map_back.insert(id, src);
self.source_map.expr_map.insert(src, id);
id
}
Expand Down Expand Up @@ -2022,7 +2019,7 @@ impl ExprCollector<'_> {
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
let src = self.expander.in_file(ptr);
let id = self.body.pats.alloc(pat);
self.source_map.pat_map_back.insert(id, src.clone());
self.source_map.pat_map_back.insert(id, src);
self.source_map.pat_map.insert(src, id);
id
}
Expand All @@ -2037,7 +2034,7 @@ impl ExprCollector<'_> {
fn alloc_label(&mut self, label: Label, ptr: LabelPtr) -> LabelId {
let src = self.expander.in_file(ptr);
let id = self.body.labels.alloc(label);
self.source_map.label_map_back.insert(id, src.clone());
self.source_map.label_map_back.insert(id, src);
self.source_map.label_map.insert(src, id);
id
}
Expand Down
6 changes: 2 additions & 4 deletions crates/hir-def/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,8 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: CrateId) -> bool {
None => continue,
};

let segments = tt.split(|tt| match tt {
tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ',' => true,
_ => false,
});
let segments =
tt.split(|tt| matches!(tt, tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ','));
for output in segments.skip(1) {
match output {
[tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.text == "no_std" => {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/find_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
10 changes: 4 additions & 6 deletions crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,8 @@ impl GenericParams {
params
.type_or_consts
.iter()
.filter_map(|(idx, param)| {
enabled(idx.into()).then(|| param.clone())
})
.filter(|(idx, _)| enabled((*idx).into()))
.map(|(_, param)| param.clone())
.collect()
}),
lifetimes: all_lifetimes_enabled
Expand All @@ -411,9 +410,8 @@ impl GenericParams {
params
.lifetimes
.iter()
.filter_map(|(idx, param)| {
enabled(idx.into()).then(|| param.clone())
})
.filter(|(idx, _)| enabled((*idx).into()))
.map(|(_, param)| param.clone())
.collect()
}),
where_predicates: params.where_predicates.clone(),
Expand Down
6 changes: 1 addition & 5 deletions crates/hir-def/src/hir/type_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,7 @@ impl ConstRef {
lower_ctx: &LowerCtx<'_>,
param: &ast::ConstParam,
) -> Option<Self> {
let default = param.default_val();
match default {
Some(_) => Some(Self::from_const_arg(lower_ctx, default)),
None => None,
}
param.default_val().map(|default| Self::from_const_arg(lower_ctx, Some(default)))
}

pub fn display<'a>(&'a self, db: &'a dyn ExpandDatabase) -> impl fmt::Display + 'a {
Expand Down
12 changes: 6 additions & 6 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -382,11 +382,11 @@ impl Query {
}

fn matches_assoc_mode(&self, is_trait_assoc_item: IsTraitAssocItem) -> bool {
match (is_trait_assoc_item, self.assoc_mode) {
!matches!(
(is_trait_assoc_item, self.assoc_mode),
(IsTraitAssocItem::Yes, AssocSearchMode::Exclude)
| (IsTraitAssocItem::No, AssocSearchMode::AssocItemsOnly) => false,
_ => true,
}
| (IsTraitAssocItem::No, AssocSearchMode::AssocItemsOnly)
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/lang_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl LangItems {

pub(crate) fn lang_attr(db: &dyn DefDatabase, item: AttrDefId) -> Option<LangItem> {
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(
Expand Down
4 changes: 1 addition & 3 deletions crates/hir-def/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,7 @@ pub struct InTypeConstLoc {

impl PartialEq for InTypeConstLoc {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
&& self.owner == other.owner
&& &*self.expected_ty == &*other.expected_ty
self.id == other.id && self.owner == other.owner && *self.expected_ty == *other.expected_ty
}
}

Expand Down
Loading