Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 22ab7e3

Browse files
authored
Merge pull request rust-lang#18846 from Veykril/push-kmspklwynynu
minor: New clippy lints
2 parents d0db503 + 0b832bf commit 22ab7e3

File tree

92 files changed

+180
-201
lines changed

Some content is hidden

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

92 files changed

+180
-201
lines changed

src/tools/rust-analyzer/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ useless_asref = "allow"
205205
assigning_clones = "allow"
206206
# Does not work with macros
207207
vec_init_then_push = "allow"
208+
# Our tests have a lot of these
209+
literal_string_with_formatting_args = "allow"
210+
# This lint has been empowered but now also triggers on cases where its invalid to do so
211+
# due to it ignoring move analysis
212+
unnecessary_map_or = "allow"
208213

209214
## Following lints should be tackled at some point
210215
too_many_arguments = "allow"

src/tools/rust-analyzer/crates/hir-def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ impl<'attr> AttrQuery<'attr> {
571571

572572
pub fn attrs(self) -> impl Iterator<Item = &'attr Attr> + Clone {
573573
let key = self.key;
574-
self.attrs.iter().filter(move |attr| attr.path.as_ident().map_or(false, |s| *s == *key))
574+
self.attrs.iter().filter(move |attr| attr.path.as_ident().is_some_and(|s| *s == *key))
575575
}
576576

577577
/// Find string value for a specific key inside token tree

src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,11 +2216,11 @@ impl ExprCollector<'_> {
22162216
};
22172217
// This needs to match `Flag` in library/core/src/fmt/rt.rs.
22182218
let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
2219-
| ((sign == Some(FormatSign::Minus)) as u32) << 1
2220-
| (alternate as u32) << 2
2221-
| (zero_pad as u32) << 3
2222-
| ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
2223-
| ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
2219+
| (((sign == Some(FormatSign::Minus)) as u32) << 1)
2220+
| ((alternate as u32) << 2)
2221+
| ((zero_pad as u32) << 3)
2222+
| (((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4)
2223+
| (((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5);
22242224
let flags = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
22252225
flags as u128,
22262226
Some(BuiltinUint::U32),
@@ -2468,7 +2468,7 @@ impl ExprCollector<'_> {
24682468

24692469
fn comma_follows_token(t: Option<syntax::SyntaxToken>) -> bool {
24702470
(|| syntax::algo::skip_trivia_token(t?.next_token()?, syntax::Direction::Next))()
2471-
.map_or(false, |it| it.kind() == syntax::T![,])
2471+
.is_some_and(|it| it.kind() == syntax::T![,])
24722472
}
24732473

24742474
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]

src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub mod keys {
9090
map.map.get::<FxHashMap<AstPtr<AST>, ID>>()?.get(key)
9191
}
9292
fn is_empty(map: &DynMap) -> bool {
93-
map.map.get::<FxHashMap<AstPtr<AST>, ID>>().map_or(true, |it| it.is_empty())
93+
map.map.get::<FxHashMap<AstPtr<AST>, ID>>().is_none_or(|it| it.is_empty())
9494
}
9595
}
9696
}
@@ -141,7 +141,7 @@ impl<K: Hash + Eq + 'static, V: 'static> Policy for (K, V) {
141141
map.map.get::<FxHashMap<K, V>>()?.get(key)
142142
}
143143
fn is_empty(map: &DynMap) -> bool {
144-
map.map.get::<FxHashMap<K, V>>().map_or(true, |it| it.is_empty())
144+
map.map.get::<FxHashMap<K, V>>().is_none_or(|it| it.is_empty())
145145
}
146146
}
147147

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl DefCollector<'_> {
353353
let is_cfg_enabled = item_tree
354354
.top_level_attrs(self.db, self.def_map.krate)
355355
.cfg()
356-
.map_or(true, |cfg| self.cfg_options.check(&cfg) != Some(false));
356+
.is_none_or(|cfg| self.cfg_options.check(&cfg) != Some(false));
357357
if is_cfg_enabled {
358358
self.inject_prelude();
359359

src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl RawAttrs {
107107
.chain(b.slice.iter().map(|it| {
108108
let mut it = it.clone();
109109
it.id.id = (it.id.ast_index() as u32 + last_ast_index)
110-
| (it.id.cfg_attr_index().unwrap_or(0) as u32)
111-
<< AttrId::AST_INDEX_BITS;
110+
| ((it.id.cfg_attr_index().unwrap_or(0) as u32)
111+
<< AttrId::AST_INDEX_BITS);
112112
it
113113
}))
114114
.collect::<Vec<_>>();
@@ -122,7 +122,7 @@ impl RawAttrs {
122122
pub fn filter(self, db: &dyn ExpandDatabase, krate: CrateId) -> RawAttrs {
123123
let has_cfg_attrs = self
124124
.iter()
125-
.any(|attr| attr.path.as_ident().map_or(false, |name| *name == sym::cfg_attr.clone()));
125+
.any(|attr| attr.path.as_ident().is_some_and(|name| *name == sym::cfg_attr.clone()));
126126
if !has_cfg_attrs {
127127
return self;
128128
}
@@ -132,7 +132,7 @@ impl RawAttrs {
132132
self.iter()
133133
.flat_map(|attr| -> SmallVec<[_; 1]> {
134134
let is_cfg_attr =
135-
attr.path.as_ident().map_or(false, |name| *name == sym::cfg_attr.clone());
135+
attr.path.as_ident().is_some_and(|name| *name == sym::cfg_attr.clone());
136136
if !is_cfg_attr {
137137
return smallvec![attr.clone()];
138138
}
@@ -202,7 +202,7 @@ impl AttrId {
202202
}
203203

204204
pub fn with_cfg_attr(self, idx: usize) -> AttrId {
205-
AttrId { id: self.id | (idx as u32) << Self::AST_INDEX_BITS | Self::CFG_ATTR_SET_BITS }
205+
AttrId { id: self.id | ((idx as u32) << Self::AST_INDEX_BITS) | Self::CFG_ATTR_SET_BITS }
206206
}
207207
}
208208

src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub(crate) fn fixup_syntax(
109109
}
110110
},
111111
ast::ExprStmt(it) => {
112-
let needs_semi = it.semicolon_token().is_none() && it.expr().map_or(false, |e| e.syntax().kind() != SyntaxKind::BLOCK_EXPR);
112+
let needs_semi = it.semicolon_token().is_none() && it.expr().is_some_and(|e| e.syntax().kind() != SyntaxKind::BLOCK_EXPR);
113113
if needs_semi {
114114
append.insert(node.clone().into(), vec![
115115
Leaf::Punct(Punct {

src/tools/rust-analyzer/crates/hir-expand/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ impl ExpandTo {
10491049
if parent.kind() == MACRO_EXPR
10501050
&& parent
10511051
.parent()
1052-
.map_or(false, |p| matches!(p.kind(), EXPR_STMT | STMT_LIST | MACRO_STMTS))
1052+
.is_some_and(|p| matches!(p.kind(), EXPR_STMT | STMT_LIST | MACRO_STMTS))
10531053
{
10541054
return ExpandTo::Statements;
10551055
}

src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn is_camel_case(name: &str) -> bool {
4949
let mut fst = None;
5050
// start with a non-lowercase letter rather than non-uppercase
5151
// ones (some scripts don't have a concept of upper/lowercase)
52-
name.chars().next().map_or(true, |c| !c.is_lowercase())
52+
name.chars().next().is_none_or(|c| !c.is_lowercase())
5353
&& !name.contains("__")
5454
&& !name.chars().any(|snd| {
5555
let ret = match fst {

src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl ExprValidator {
295295
path,
296296
self.body.expr_path_hygiene(scrutinee_expr),
297297
);
298-
value_or_partial.map_or(true, |v| !matches!(v, ValueNs::StaticId(_)))
298+
value_or_partial.is_none_or(|v| !matches!(v, ValueNs::StaticId(_)))
299299
}
300300
Expr::Field { expr, .. } => match self.infer.type_of_expr[*expr].kind(Interner) {
301301
TyKind::Adt(adt, ..)
@@ -447,7 +447,7 @@ impl ExprValidator {
447447
loop {
448448
let parent = top_if_expr.syntax().parent();
449449
let has_parent_expr_stmt_or_stmt_list =
450-
parent.as_ref().map_or(false, |node| {
450+
parent.as_ref().is_some_and(|node| {
451451
ast::ExprStmt::can_cast(node.kind())
452452
| ast::StmtList::can_cast(node.kind())
453453
});
@@ -529,7 +529,7 @@ impl FilterMapNextChecker {
529529
let is_dyn_trait = self
530530
.prev_receiver_ty
531531
.as_ref()
532-
.map_or(false, |it| it.strip_references().dyn_trait().is_some());
532+
.is_some_and(|it| it.strip_references().dyn_trait().is_some());
533533
if *receiver_expr_id == prev_filter_map_expr_id && !is_dyn_trait {
534534
return Some(());
535535
}

src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl<'db> MatchCheckCtx<'db> {
314314
}
315315
}
316316

317-
impl<'db> PatCx for MatchCheckCtx<'db> {
317+
impl PatCx for MatchCheckCtx<'_> {
318318
type Error = ();
319319
type Ty = Ty;
320320
type VariantIdx = EnumVariantContiguousIndex;

src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ impl InferenceContext<'_> {
992992
},
993993
},
994994
}
995-
if self.result.pat_adjustments.get(&p).map_or(false, |it| !it.is_empty()) {
995+
if self.result.pat_adjustments.get(&p).is_some_and(|it| !it.is_empty()) {
996996
for_mut = BorrowKind::Mut { kind: MutBorrowKind::ClosureCapture };
997997
}
998998
self.body.walk_pats_shallow(p, |p| self.walk_pat_inner(p, update_result, for_mut));

src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl InferenceContext<'_> {
206206
path,
207207
self.body.expr_path_hygiene(expr),
208208
)
209-
.map_or(true, |res| matches!(res, ValueNs::LocalBinding(_) | ValueNs::StaticId(_))),
209+
.is_none_or(|res| matches!(res, ValueNs::LocalBinding(_) | ValueNs::StaticId(_))),
210210
Expr::Underscore => true,
211211
Expr::UnaryOp { op: UnaryOp::Deref, .. } => true,
212212
Expr::Field { .. } | Expr::Index { .. } => true,
@@ -499,7 +499,7 @@ impl InferenceContext<'_> {
499499
// if the function is unresolved, we use is_varargs=true to
500500
// suppress the arg count diagnostic here
501501
let is_varargs =
502-
derefed_callee.callable_sig(self.db).map_or(false, |sig| sig.is_varargs)
502+
derefed_callee.callable_sig(self.db).is_some_and(|sig| sig.is_varargs)
503503
|| res.is_none();
504504
let (param_tys, ret_ty) = match res {
505505
Some((func, params, ret_ty)) => {
@@ -2043,7 +2043,7 @@ impl InferenceContext<'_> {
20432043
continue;
20442044
}
20452045

2046-
while skip_indices.peek().map_or(false, |i| *i < idx as u32) {
2046+
while skip_indices.peek().is_some_and(|i| *i < idx as u32) {
20472047
skip_indices.next();
20482048
}
20492049
if skip_indices.peek().copied() == Some(idx as u32) {

src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,7 @@ impl InferenceContext<'_> {
315315
}
316316

317317
AssocItemId::ConstId(konst) => {
318-
if self
319-
.db
320-
.const_data(konst)
321-
.name
322-
.as_ref()
323-
.map_or(false, |n| n == segment.name)
324-
{
318+
if self.db.const_data(konst).name.as_ref() == Some(segment.name) {
325319
Some(AssocItemId::ConstId(konst))
326320
} else {
327321
None

src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<'a> InferenceTable<'a> {
282282
let is_diverging = self
283283
.type_variable_table
284284
.get(iv.index() as usize)
285-
.map_or(false, |data| data.contains(TypeVariableFlags::DIVERGING));
285+
.is_some_and(|data| data.contains(TypeVariableFlags::DIVERGING));
286286
if is_diverging {
287287
return TyKind::Never.intern(Interner);
288288
}

src/tools/rust-analyzer/crates/hir-ty/src/inhabitedness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl UninhabitedFrom<'_> {
139139
ty: &Binders<Ty>,
140140
subst: &Substitution,
141141
) -> ControlFlow<VisiblyUninhabited> {
142-
if vis.map_or(true, |it| it.is_visible_from(self.db.upcast(), self.target_mod)) {
142+
if vis.is_none_or(|it| it.is_visible_from(self.db.upcast(), self.target_mod)) {
143143
let ty = ty.clone().substitute(Interner, subst);
144144
ty.visit_with(self, DebruijnIndex::INNERMOST)
145145
} else {

src/tools/rust-analyzer/crates/hir-ty/src/layout/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,31 +241,31 @@ fn recursive() {
241241
#[test]
242242
fn repr_packed() {
243243
size_and_align! {
244-
#[repr(packed)]
244+
#[repr(Rust, packed)]
245245
struct Goal;
246246
}
247247
size_and_align! {
248-
#[repr(packed(2))]
248+
#[repr(Rust, packed(2))]
249249
struct Goal;
250250
}
251251
size_and_align! {
252-
#[repr(packed(4))]
252+
#[repr(Rust, packed(4))]
253253
struct Goal;
254254
}
255255
size_and_align! {
256-
#[repr(packed)]
256+
#[repr(Rust, packed)]
257257
struct Goal(i32);
258258
}
259259
size_and_align! {
260-
#[repr(packed(2))]
260+
#[repr(Rust, packed(2))]
261261
struct Goal(i32);
262262
}
263263
size_and_align! {
264-
#[repr(packed(4))]
264+
#[repr(Rust, packed(4))]
265265
struct Goal(i32);
266266
}
267267

268-
check_size_and_align("#[repr(packed(5))] struct Goal(i32);", "", 4, 1);
268+
check_size_and_align("#[repr(Rust, packed(5))] struct Goal(i32);", "", 4, 1);
269269
}
270270

271271
#[test]

src/tools/rust-analyzer/crates/hir-ty/src/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,14 +2751,14 @@ fn fallback_bound_vars<T: TypeFoldable<Interner> + HasInterner<Interner = Intern
27512751
crate::fold_free_vars(
27522752
s,
27532753
|bound, binders| {
2754-
if bound.index_if_innermost().map_or(true, is_allowed) {
2754+
if bound.index_if_innermost().is_none_or(is_allowed) {
27552755
bound.shifted_in_from(binders).to_ty(Interner)
27562756
} else {
27572757
TyKind::Error.intern(Interner)
27582758
}
27592759
},
27602760
|ty, bound, binders| {
2761-
if bound.index_if_innermost().map_or(true, is_allowed) {
2761+
if bound.index_if_innermost().is_none_or(is_allowed) {
27622762
bound.shifted_in_from(binders).to_const(Interner, ty)
27632763
} else {
27642764
unknown_const(ty)

src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub(crate) fn incoherent_inherent_impl_crates(
377377

378378
for krate in crate_graph.transitive_deps(krate) {
379379
let impls = db.inherent_impls_in_crate(krate);
380-
if impls.map.get(&fp).map_or(false, |v| !v.is_empty()) {
380+
if impls.map.get(&fp).is_some_and(|v| !v.is_empty()) {
381381
res.push(krate);
382382
}
383383
}
@@ -811,7 +811,7 @@ fn is_inherent_impl_coherent(
811811
| TyKind::Scalar(_) => def_map.is_rustc_coherence_is_core(),
812812

813813
&TyKind::Adt(AdtId(adt), _) => adt.module(db.upcast()).krate() == def_map.krate(),
814-
TyKind::Dyn(it) => it.principal_id().map_or(false, |trait_id| {
814+
TyKind::Dyn(it) => it.principal_id().is_some_and(|trait_id| {
815815
from_chalk_trait_id(trait_id).module(db.upcast()).krate() == def_map.krate()
816816
}),
817817

@@ -840,7 +840,7 @@ fn is_inherent_impl_coherent(
840840
.contains(StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPL),
841841
hir_def::AdtId::EnumId(it) => db.enum_data(it).rustc_has_incoherent_inherent_impls,
842842
},
843-
TyKind::Dyn(it) => it.principal_id().map_or(false, |trait_id| {
843+
TyKind::Dyn(it) => it.principal_id().is_some_and(|trait_id| {
844844
db.trait_data(from_chalk_trait_id(trait_id))
845845
.flags
846846
.contains(TraitFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS)
@@ -903,7 +903,7 @@ pub fn check_orphan_rules(db: &dyn HirDatabase, impl_: ImplId) -> bool {
903903
match unwrap_fundamental(ty).kind(Interner) {
904904
&TyKind::Adt(AdtId(id), _) => is_local(id.module(db.upcast()).krate()),
905905
TyKind::Error => true,
906-
TyKind::Dyn(it) => it.principal_id().map_or(false, |trait_id| {
906+
TyKind::Dyn(it) => it.principal_id().is_some_and(|trait_id| {
907907
is_local(from_chalk_trait_id(trait_id).module(db.upcast()).krate())
908908
}),
909909
_ => false,
@@ -1481,7 +1481,7 @@ fn is_valid_impl_method_candidate(
14811481
AssocItemId::ConstId(c) => {
14821482
let db = table.db;
14831483
check_that!(receiver_ty.is_none());
1484-
check_that!(name.map_or(true, |n| db.const_data(c).name.as_ref() == Some(n)));
1484+
check_that!(name.is_none_or(|n| db.const_data(c).name.as_ref() == Some(n)));
14851485

14861486
if let Some(from_module) = visible_from_module {
14871487
if !db.const_visibility(c).is_visible_from(db.upcast(), from_module) {
@@ -1519,7 +1519,7 @@ fn is_valid_trait_method_candidate(
15191519
AssocItemId::FunctionId(fn_id) => {
15201520
let data = db.function_data(fn_id);
15211521

1522-
check_that!(name.map_or(true, |n| n == &data.name));
1522+
check_that!(name.is_none_or(|n| n == &data.name));
15231523

15241524
table.run_in_snapshot(|table| {
15251525
let impl_subst = TyBuilder::subst_for_def(db, trait_id, None)
@@ -1548,7 +1548,7 @@ fn is_valid_trait_method_candidate(
15481548
}
15491549
AssocItemId::ConstId(c) => {
15501550
check_that!(receiver_ty.is_none());
1551-
check_that!(name.map_or(true, |n| db.const_data(c).name.as_ref() == Some(n)));
1551+
check_that!(name.is_none_or(|n| db.const_data(c).name.as_ref() == Some(n)));
15521552

15531553
IsValidCandidate::Yes
15541554
}
@@ -1569,7 +1569,7 @@ fn is_valid_impl_fn_candidate(
15691569
let db = table.db;
15701570
let data = db.function_data(fn_id);
15711571

1572-
check_that!(name.map_or(true, |n| n == &data.name));
1572+
check_that!(name.is_none_or(|n| n == &data.name));
15731573
if let Some(from_module) = visible_from_module {
15741574
if !db.function_visibility(fn_id).is_visible_from(db.upcast(), from_module) {
15751575
cov_mark::hit!(autoderef_candidate_not_visible);

src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ impl Evaluator<'_> {
21132113
while self.heap.len() % align != 0 {
21142114
self.heap.push(0);
21152115
}
2116-
if size.checked_add(self.heap.len()).map_or(true, |x| x > self.memory_limit) {
2116+
if size.checked_add(self.heap.len()).is_none_or(|x| x > self.memory_limit) {
21172117
return Err(MirEvalError::Panic(format!("Memory allocation of {size} bytes failed")));
21182118
}
21192119
let pos = self.heap.len();

src/tools/rust-analyzer/crates/hir-ty/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl OpaqueInternableThing for InTypeConstIdMetadata {
373373
}
374374

375375
fn dyn_eq(&self, other: &dyn OpaqueInternableThing) -> bool {
376-
other.as_any().downcast_ref::<Self>().map_or(false, |x| self == x)
376+
other.as_any().downcast_ref::<Self>() == Some(self)
377377
}
378378

379379
fn dyn_clone(&self) -> Box<dyn OpaqueInternableThing> {

0 commit comments

Comments
 (0)