Skip to content

Commit 67cfbf2

Browse files
committed
Auto merge of #16404 - Urhengulas:satisfy-clippy, r=Veykril
Work through temporarily allowed clippy lints, part 1 This is the first batch of not allowing but actually fixing the clippy lints. Each commit removes one lint from the lint table and then fixes the resulting warnings. Follow-up to #16401
2 parents 2a239b9 + 9e83779 commit 67cfbf2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+377
-527
lines changed

Cargo.toml

-34
Original file line numberDiff line numberDiff line change
@@ -159,59 +159,25 @@ suspicious = { level = "warn", priority = -1 }
159159
result_unit_err = "allow"
160160
# We don't expose public APIs that matter like this
161161
len_without_is_empty = "allow"
162-
# We currently prefer explicit control flow return over `...?;` statements whose result is unused
163-
question_mark = "allow"
164162
# We have macros that rely on this currently
165163
enum_variant_names = "allow"
166164
# Builder pattern disagrees
167165
new_ret_no_self = "allow"
168166

169167
## Following lints should be tackled at some point
170-
bind_instead_of_map = "allow"
171168
borrowed_box = "allow"
172169
borrow_deref_ref = "allow"
173-
collapsible_if = "allow"
174-
collapsible_match = "allow"
175-
clone_on_copy = "allow"
176170
derivable_impls = "allow"
177171
derived_hash_with_manual_eq = "allow"
178-
double_parens = "allow"
179-
explicit_auto_deref = "allow"
180172
field_reassign_with_default = "allow"
181173
forget_non_drop = "allow"
182174
format_collect = "allow"
183-
for_kv_map = "allow"
184-
filter_map_bool_then = "allow"
185-
from_str_radix_10 = "allow"
186-
get_first = "allow"
187-
if_same_then_else = "allow"
188175
large_enum_variant = "allow"
189-
let_and_return = "allow"
190-
manual_find = "allow"
191-
manual_map = "allow"
192-
map_clone = "allow"
193-
match_like_matches_macro = "allow"
194-
match_single_binding = "allow"
195-
needless_borrow = "allow"
196176
needless_doctest_main = "allow"
197-
needless_lifetimes = "allow"
198-
needless_pass_by_value = "allow"
199-
needless_return = "allow"
200177
new_without_default = "allow"
201-
nonminimal_bool = "allow"
202178
non_canonical_clone_impl = "allow"
203179
non_canonical_partial_ord_impl = "allow"
204-
non_minimal_cfg = "allow"
205-
only_used_in_recursion = "allow"
206-
op_ref = "allow"
207-
option_map_unit_fn = "allow"
208-
partialeq_to_none = "allow"
209-
ptr_arg = "allow"
210-
redundant_closure = "allow"
211-
redundant_pattern_matching = "allow"
212-
search_is_some = "allow"
213180
self_named_constructors = "allow"
214-
single_match = "allow"
215181
skip_while_next = "allow"
216182
too_many_arguments = "allow"
217183
toplevel_ref_arg = "allow"

crates/base-db/src/input.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl CrateData {
331331
return false;
332332
}
333333

334-
if let Some(_) = opts.next() {
334+
if opts.next().is_some() {
335335
return false;
336336
}
337337
}

crates/hir-def/src/body.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ impl Body {
258258
}
259259
}
260260
Pat::Or(args) | Pat::Tuple { args, .. } | Pat::TupleStruct { args, .. } => {
261-
args.iter().copied().for_each(|p| f(p));
261+
args.iter().copied().for_each(f);
262262
}
263263
Pat::Ref { pat, .. } => f(*pat),
264264
Pat::Slice { prefix, slice, suffix } => {
265265
let total_iter = prefix.iter().chain(slice.iter()).chain(suffix.iter());
266-
total_iter.copied().for_each(|p| f(p));
266+
total_iter.copied().for_each(f);
267267
}
268268
Pat::Record { args, .. } => {
269269
args.iter().for_each(|RecordFieldPat { pat, .. }| f(*pat));
@@ -369,7 +369,7 @@ impl BodySourceMap {
369369
}
370370

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

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

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

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

388388
pub fn macro_expansion_expr(&self, node: InFile<&ast::MacroExpr>) -> Option<ExprId> {

crates/hir-def/src/body/lower.rs

+24-27
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,10 @@ impl ExprCollector<'_> {
776776
None => self.collect_expr_opt(e.condition()),
777777
};
778778

779-
let break_expr =
780-
self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr.clone());
779+
let break_expr = self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr);
781780
let if_expr = self.alloc_expr(
782781
Expr::If { condition, then_branch: body, else_branch: Some(break_expr) },
783-
syntax_ptr.clone(),
782+
syntax_ptr,
784783
);
785784
self.alloc_expr(Expr::Loop { body: if_expr, label }, syntax_ptr)
786785
}
@@ -811,19 +810,19 @@ impl ExprCollector<'_> {
811810
return self.alloc_expr(Expr::Missing, syntax_ptr);
812811
};
813812
let head = self.collect_expr_opt(e.iterable());
814-
let into_iter_fn_expr = self.alloc_expr(Expr::Path(into_iter_fn), syntax_ptr.clone());
813+
let into_iter_fn_expr = self.alloc_expr(Expr::Path(into_iter_fn), syntax_ptr);
815814
let iterator = self.alloc_expr(
816815
Expr::Call {
817816
callee: into_iter_fn_expr,
818817
args: Box::new([head]),
819818
is_assignee_expr: false,
820819
},
821-
syntax_ptr.clone(),
820+
syntax_ptr,
822821
);
823822
let none_arm = MatchArm {
824823
pat: self.alloc_pat_desugared(Pat::Path(Box::new(option_none))),
825824
guard: None,
826-
expr: self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr.clone()),
825+
expr: self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr),
827826
};
828827
let some_pat = Pat::TupleStruct {
829828
path: Some(Box::new(option_some)),
@@ -839,27 +838,25 @@ impl ExprCollector<'_> {
839838
}),
840839
};
841840
let iter_name = Name::generate_new_name();
842-
let iter_expr =
843-
self.alloc_expr(Expr::Path(Path::from(iter_name.clone())), syntax_ptr.clone());
841+
let iter_expr = self.alloc_expr(Expr::Path(Path::from(iter_name.clone())), syntax_ptr);
844842
let iter_expr_mut = self.alloc_expr(
845843
Expr::Ref { expr: iter_expr, rawness: Rawness::Ref, mutability: Mutability::Mut },
846-
syntax_ptr.clone(),
844+
syntax_ptr,
847845
);
848-
let iter_next_fn_expr = self.alloc_expr(Expr::Path(iter_next_fn), syntax_ptr.clone());
846+
let iter_next_fn_expr = self.alloc_expr(Expr::Path(iter_next_fn), syntax_ptr);
849847
let iter_next_expr = self.alloc_expr(
850848
Expr::Call {
851849
callee: iter_next_fn_expr,
852850
args: Box::new([iter_expr_mut]),
853851
is_assignee_expr: false,
854852
},
855-
syntax_ptr.clone(),
853+
syntax_ptr,
856854
);
857855
let loop_inner = self.alloc_expr(
858856
Expr::Match { expr: iter_next_expr, arms: Box::new([none_arm, some_arm]) },
859-
syntax_ptr.clone(),
857+
syntax_ptr,
860858
);
861-
let loop_outer =
862-
self.alloc_expr(Expr::Loop { body: loop_inner, label }, syntax_ptr.clone());
859+
let loop_outer = self.alloc_expr(Expr::Loop { body: loop_inner, label }, syntax_ptr);
863860
let iter_binding = self.alloc_binding(iter_name, BindingAnnotation::Mutable);
864861
let iter_pat = self.alloc_pat_desugared(Pat::Bind { id: iter_binding, subpat: None });
865862
self.add_definition_to_binding(iter_binding, iter_pat);
@@ -868,7 +865,7 @@ impl ExprCollector<'_> {
868865
expr: iterator,
869866
arms: Box::new([MatchArm { pat: iter_pat, guard: None, expr: loop_outer }]),
870867
},
871-
syntax_ptr.clone(),
868+
syntax_ptr,
872869
)
873870
}
874871

@@ -896,10 +893,10 @@ impl ExprCollector<'_> {
896893
return self.alloc_expr(Expr::Missing, syntax_ptr);
897894
};
898895
let operand = self.collect_expr_opt(e.expr());
899-
let try_branch = self.alloc_expr(Expr::Path(try_branch), syntax_ptr.clone());
896+
let try_branch = self.alloc_expr(Expr::Path(try_branch), syntax_ptr);
900897
let expr = self.alloc_expr(
901898
Expr::Call { callee: try_branch, args: Box::new([operand]), is_assignee_expr: false },
902-
syntax_ptr.clone(),
899+
syntax_ptr,
903900
);
904901
let continue_name = Name::generate_new_name();
905902
let continue_binding =
@@ -914,7 +911,7 @@ impl ExprCollector<'_> {
914911
ellipsis: None,
915912
}),
916913
guard: None,
917-
expr: self.alloc_expr(Expr::Path(Path::from(continue_name)), syntax_ptr.clone()),
914+
expr: self.alloc_expr(Expr::Path(Path::from(continue_name)), syntax_ptr),
918915
};
919916
let break_name = Name::generate_new_name();
920917
let break_binding = self.alloc_binding(break_name.clone(), BindingAnnotation::Unannotated);
@@ -928,18 +925,18 @@ impl ExprCollector<'_> {
928925
}),
929926
guard: None,
930927
expr: {
931-
let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr.clone());
932-
let callee = self.alloc_expr(Expr::Path(try_from_residual), syntax_ptr.clone());
928+
let it = self.alloc_expr(Expr::Path(Path::from(break_name)), syntax_ptr);
929+
let callee = self.alloc_expr(Expr::Path(try_from_residual), syntax_ptr);
933930
let result = self.alloc_expr(
934931
Expr::Call { callee, args: Box::new([it]), is_assignee_expr: false },
935-
syntax_ptr.clone(),
932+
syntax_ptr,
936933
);
937934
self.alloc_expr(
938935
match self.current_try_block_label {
939936
Some(label) => Expr::Break { expr: Some(result), label: Some(label) },
940937
None => Expr::Return { expr: Some(result) },
941938
},
942-
syntax_ptr.clone(),
939+
syntax_ptr,
943940
)
944941
},
945942
};
@@ -1847,8 +1844,8 @@ impl ExprCollector<'_> {
18471844
flags as u128,
18481845
Some(BuiltinUint::U32),
18491846
)));
1850-
let precision = self.make_count(&precision, argmap);
1851-
let width = self.make_count(&width, argmap);
1847+
let precision = self.make_count(precision, argmap);
1848+
let width = self.make_count(width, argmap);
18521849

18531850
let format_placeholder_new = {
18541851
let format_placeholder_new =
@@ -1994,7 +1991,7 @@ impl ExprCollector<'_> {
19941991
fn alloc_expr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId {
19951992
let src = self.expander.in_file(ptr);
19961993
let id = self.body.exprs.alloc(expr);
1997-
self.source_map.expr_map_back.insert(id, src.clone());
1994+
self.source_map.expr_map_back.insert(id, src);
19981995
self.source_map.expr_map.insert(src, id);
19991996
id
20001997
}
@@ -2022,7 +2019,7 @@ impl ExprCollector<'_> {
20222019
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
20232020
let src = self.expander.in_file(ptr);
20242021
let id = self.body.pats.alloc(pat);
2025-
self.source_map.pat_map_back.insert(id, src.clone());
2022+
self.source_map.pat_map_back.insert(id, src);
20262023
self.source_map.pat_map.insert(src, id);
20272024
id
20282025
}
@@ -2037,7 +2034,7 @@ impl ExprCollector<'_> {
20372034
fn alloc_label(&mut self, label: Label, ptr: LabelPtr) -> LabelId {
20382035
let src = self.expander.in_file(ptr);
20392036
let id = self.body.labels.alloc(label);
2040-
self.source_map.label_map_back.insert(id, src.clone());
2037+
self.source_map.label_map_back.insert(id, src);
20412038
self.source_map.label_map.insert(src, id);
20422039
id
20432040
}

crates/hir-def/src/db.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,8 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: CrateId) -> bool {
259259
None => continue,
260260
};
261261

262-
let segments = tt.split(|tt| match tt {
263-
tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ',' => true,
264-
_ => false,
265-
});
262+
let segments =
263+
tt.split(|tt| matches!(tt, tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ','));
266264
for output in segments.skip(1) {
267265
match output {
268266
[tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.text == "no_std" => {

crates/hir-def/src/find_path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fn find_path_for_module(
230230
}
231231

232232
if let value @ Some(_) =
233-
find_in_prelude(ctx.db, &root_def_map, &def_map, ItemInNs::Types(module_id.into()), from)
233+
find_in_prelude(ctx.db, &root_def_map, def_map, ItemInNs::Types(module_id.into()), from)
234234
{
235235
return value.zip(Some(Stable));
236236
}

crates/hir-def/src/generics.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,8 @@ impl GenericParams {
400400
params
401401
.type_or_consts
402402
.iter()
403-
.filter_map(|(idx, param)| {
404-
enabled(idx.into()).then(|| param.clone())
405-
})
403+
.filter(|(idx, _)| enabled((*idx).into()))
404+
.map(|(_, param)| param.clone())
406405
.collect()
407406
}),
408407
lifetimes: all_lifetimes_enabled
@@ -411,9 +410,8 @@ impl GenericParams {
411410
params
412411
.lifetimes
413412
.iter()
414-
.filter_map(|(idx, param)| {
415-
enabled(idx.into()).then(|| param.clone())
416-
})
413+
.filter(|(idx, _)| enabled((*idx).into()))
414+
.map(|(_, param)| param.clone())
417415
.collect()
418416
}),
419417
where_predicates: params.where_predicates.clone(),

crates/hir-def/src/hir/type_ref.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,7 @@ impl ConstRef {
410410
lower_ctx: &LowerCtx<'_>,
411411
param: &ast::ConstParam,
412412
) -> Option<Self> {
413-
let default = param.default_val();
414-
match default {
415-
Some(_) => Some(Self::from_const_arg(lower_ctx, default)),
416-
None => None,
417-
}
413+
param.default_val().map(|default| Self::from_const_arg(lower_ctx, Some(default)))
418414
}
419415

420416
pub fn display<'a>(&'a self, db: &'a dyn ExpandDatabase) -> impl fmt::Display + 'a {

crates/hir-def/src/import_map.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,14 @@ impl SearchMode {
294294
pub fn check(self, query: &str, case_sensitive: bool, candidate: &str) -> bool {
295295
match self {
296296
SearchMode::Exact if case_sensitive => candidate == query,
297-
SearchMode::Exact => candidate.eq_ignore_ascii_case(&query),
297+
SearchMode::Exact => candidate.eq_ignore_ascii_case(query),
298298
SearchMode::Prefix => {
299299
query.len() <= candidate.len() && {
300300
let prefix = &candidate[..query.len() as usize];
301301
if case_sensitive {
302302
prefix == query
303303
} else {
304-
prefix.eq_ignore_ascii_case(&query)
304+
prefix.eq_ignore_ascii_case(query)
305305
}
306306
}
307307
}
@@ -382,11 +382,11 @@ impl Query {
382382
}
383383

384384
fn matches_assoc_mode(&self, is_trait_assoc_item: IsTraitAssocItem) -> bool {
385-
match (is_trait_assoc_item, self.assoc_mode) {
385+
!matches!(
386+
(is_trait_assoc_item, self.assoc_mode),
386387
(IsTraitAssocItem::Yes, AssocSearchMode::Exclude)
387-
| (IsTraitAssocItem::No, AssocSearchMode::AssocItemsOnly) => false,
388-
_ => true,
389-
}
388+
| (IsTraitAssocItem::No, AssocSearchMode::AssocItemsOnly)
389+
)
390390
}
391391
}
392392

crates/hir-def/src/lang_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl LangItems {
192192

193193
pub(crate) fn lang_attr(db: &dyn DefDatabase, item: AttrDefId) -> Option<LangItem> {
194194
let attrs = db.attrs(item);
195-
attrs.by_key("lang").string_value().and_then(|it| LangItem::from_str(&it))
195+
attrs.by_key("lang").string_value().and_then(|it| LangItem::from_str(it))
196196
}
197197

198198
pub(crate) fn notable_traits_in_deps(

crates/hir-def/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,7 @@ pub struct InTypeConstLoc {
733733

734734
impl PartialEq for InTypeConstLoc {
735735
fn eq(&self, other: &Self) -> bool {
736-
self.id == other.id
737-
&& self.owner == other.owner
738-
&& &*self.expected_ty == &*other.expected_ty
736+
self.id == other.id && self.owner == other.owner && *self.expected_ty == *other.expected_ty
739737
}
740738
}
741739

0 commit comments

Comments
 (0)