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
}

0 commit comments

Comments
 (0)