diff --git a/src/tools/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/Cargo.toml index e303b3c11092c..88818580a3db6 100644 --- a/src/tools/rust-analyzer/Cargo.toml +++ b/src/tools/rust-analyzer/Cargo.toml @@ -205,6 +205,11 @@ useless_asref = "allow" assigning_clones = "allow" # Does not work with macros vec_init_then_push = "allow" +# Our tests have a lot of these +literal_string_with_formatting_args = "allow" +# This lint has been empowered but now also triggers on cases where its invalid to do so +# due to it ignoring move analysis +unnecessary_map_or = "allow" ## Following lints should be tackled at some point too_many_arguments = "allow" diff --git a/src/tools/rust-analyzer/crates/hir-def/src/attr.rs b/src/tools/rust-analyzer/crates/hir-def/src/attr.rs index 6b7b3206e049d..37e2a99e60ff1 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/attr.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/attr.rs @@ -571,7 +571,7 @@ impl<'attr> AttrQuery<'attr> { pub fn attrs(self) -> impl Iterator + Clone { let key = self.key; - self.attrs.iter().filter(move |attr| attr.path.as_ident().map_or(false, |s| *s == *key)) + self.attrs.iter().filter(move |attr| attr.path.as_ident().is_some_and(|s| *s == *key)) } /// Find string value for a specific key inside token tree diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs b/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs index eed9f9468fd96..10b84d041bde4 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs @@ -2216,11 +2216,11 @@ impl ExprCollector<'_> { }; // This needs to match `Flag` in library/core/src/fmt/rt.rs. let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32) - | ((sign == Some(FormatSign::Minus)) as u32) << 1 - | (alternate as u32) << 2 - | (zero_pad as u32) << 3 - | ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4 - | ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5; + | (((sign == Some(FormatSign::Minus)) as u32) << 1) + | ((alternate as u32) << 2) + | ((zero_pad as u32) << 3) + | (((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4) + | (((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5); let flags = self.alloc_expr_desugared(Expr::Literal(Literal::Uint( flags as u128, Some(BuiltinUint::U32), @@ -2468,7 +2468,7 @@ impl ExprCollector<'_> { fn comma_follows_token(t: Option) -> bool { (|| syntax::algo::skip_trivia_token(t?.next_token()?, syntax::Direction::Next))() - .map_or(false, |it| it.kind() == syntax::T![,]) + .is_some_and(|it| it.kind() == syntax::T![,]) } #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] diff --git a/src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs b/src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs index 22005695af638..0f73595347b12 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs @@ -90,7 +90,7 @@ pub mod keys { map.map.get::, ID>>()?.get(key) } fn is_empty(map: &DynMap) -> bool { - map.map.get::, ID>>().map_or(true, |it| it.is_empty()) + map.map.get::, ID>>().is_none_or(|it| it.is_empty()) } } } @@ -141,7 +141,7 @@ impl Policy for (K, V) { map.map.get::>()?.get(key) } fn is_empty(map: &DynMap) -> bool { - map.map.get::>().map_or(true, |it| it.is_empty()) + map.map.get::>().is_none_or(|it| it.is_empty()) } } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs index de76257587a78..d5e13f5d45f32 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs @@ -353,7 +353,7 @@ impl DefCollector<'_> { let is_cfg_enabled = item_tree .top_level_attrs(self.db, self.def_map.krate) .cfg() - .map_or(true, |cfg| self.cfg_options.check(&cfg) != Some(false)); + .is_none_or(|cfg| self.cfg_options.check(&cfg) != Some(false)); if is_cfg_enabled { self.inject_prelude(); diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs b/src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs index 519e7511753dc..c9c793d54f26c 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs @@ -107,8 +107,8 @@ impl RawAttrs { .chain(b.slice.iter().map(|it| { let mut it = it.clone(); it.id.id = (it.id.ast_index() as u32 + last_ast_index) - | (it.id.cfg_attr_index().unwrap_or(0) as u32) - << AttrId::AST_INDEX_BITS; + | ((it.id.cfg_attr_index().unwrap_or(0) as u32) + << AttrId::AST_INDEX_BITS); it })) .collect::>(); @@ -122,7 +122,7 @@ impl RawAttrs { pub fn filter(self, db: &dyn ExpandDatabase, krate: CrateId) -> RawAttrs { let has_cfg_attrs = self .iter() - .any(|attr| attr.path.as_ident().map_or(false, |name| *name == sym::cfg_attr.clone())); + .any(|attr| attr.path.as_ident().is_some_and(|name| *name == sym::cfg_attr.clone())); if !has_cfg_attrs { return self; } @@ -132,7 +132,7 @@ impl RawAttrs { self.iter() .flat_map(|attr| -> SmallVec<[_; 1]> { let is_cfg_attr = - attr.path.as_ident().map_or(false, |name| *name == sym::cfg_attr.clone()); + attr.path.as_ident().is_some_and(|name| *name == sym::cfg_attr.clone()); if !is_cfg_attr { return smallvec![attr.clone()]; } @@ -202,7 +202,7 @@ impl AttrId { } pub fn with_cfg_attr(self, idx: usize) -> AttrId { - AttrId { id: self.id | (idx as u32) << Self::AST_INDEX_BITS | Self::CFG_ATTR_SET_BITS } + AttrId { id: self.id | ((idx as u32) << Self::AST_INDEX_BITS) | Self::CFG_ATTR_SET_BITS } } } diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs b/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs index 90012dd1f77cc..ad001f72deb5a 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs @@ -109,7 +109,7 @@ pub(crate) fn fixup_syntax( } }, ast::ExprStmt(it) => { - let needs_semi = it.semicolon_token().is_none() && it.expr().map_or(false, |e| e.syntax().kind() != SyntaxKind::BLOCK_EXPR); + let needs_semi = it.semicolon_token().is_none() && it.expr().is_some_and(|e| e.syntax().kind() != SyntaxKind::BLOCK_EXPR); if needs_semi { append.insert(node.clone().into(), vec![ Leaf::Punct(Punct { diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs index ac1d1109f5354..a0c4c125db47a 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs @@ -1049,7 +1049,7 @@ impl ExpandTo { if parent.kind() == MACRO_EXPR && parent .parent() - .map_or(false, |p| matches!(p.kind(), EXPR_STMT | STMT_LIST | MACRO_STMTS)) + .is_some_and(|p| matches!(p.kind(), EXPR_STMT | STMT_LIST | MACRO_STMTS)) { return ExpandTo::Statements; } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs index aa0c9e30be10d..348f8a0f4a856 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs @@ -49,7 +49,7 @@ fn is_camel_case(name: &str) -> bool { let mut fst = None; // start with a non-lowercase letter rather than non-uppercase // ones (some scripts don't have a concept of upper/lowercase) - name.chars().next().map_or(true, |c| !c.is_lowercase()) + name.chars().next().is_none_or(|c| !c.is_lowercase()) && !name.contains("__") && !name.chars().any(|snd| { let ret = match fst { diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/expr.rs b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/expr.rs index 92404e3a10e21..7f9f0c0de197b 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/expr.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/expr.rs @@ -295,7 +295,7 @@ impl ExprValidator { path, self.body.expr_path_hygiene(scrutinee_expr), ); - value_or_partial.map_or(true, |v| !matches!(v, ValueNs::StaticId(_))) + value_or_partial.is_none_or(|v| !matches!(v, ValueNs::StaticId(_))) } Expr::Field { expr, .. } => match self.infer.type_of_expr[*expr].kind(Interner) { TyKind::Adt(adt, ..) @@ -447,7 +447,7 @@ impl ExprValidator { loop { let parent = top_if_expr.syntax().parent(); let has_parent_expr_stmt_or_stmt_list = - parent.as_ref().map_or(false, |node| { + parent.as_ref().is_some_and(|node| { ast::ExprStmt::can_cast(node.kind()) | ast::StmtList::can_cast(node.kind()) }); @@ -529,7 +529,7 @@ impl FilterMapNextChecker { let is_dyn_trait = self .prev_receiver_ty .as_ref() - .map_or(false, |it| it.strip_references().dyn_trait().is_some()); + .is_some_and(|it| it.strip_references().dyn_trait().is_some()); if *receiver_expr_id == prev_filter_map_expr_id && !is_dyn_trait { return Some(()); } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs index 5452f5c680df5..2b854310a15ec 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs @@ -314,7 +314,7 @@ impl<'db> MatchCheckCtx<'db> { } } -impl<'db> PatCx for MatchCheckCtx<'db> { +impl PatCx for MatchCheckCtx<'_> { type Error = (); type Ty = Ty; type VariantIdx = EnumVariantContiguousIndex; diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs index c59013beafbae..2523aba538334 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs @@ -992,7 +992,7 @@ impl InferenceContext<'_> { }, }, } - if self.result.pat_adjustments.get(&p).map_or(false, |it| !it.is_empty()) { + if self.result.pat_adjustments.get(&p).is_some_and(|it| !it.is_empty()) { for_mut = BorrowKind::Mut { kind: MutBorrowKind::ClosureCapture }; } self.body.walk_pats_shallow(p, |p| self.walk_pat_inner(p, update_result, for_mut)); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs index 3dccd536bef83..6b6c0348dcb4f 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs @@ -206,7 +206,7 @@ impl InferenceContext<'_> { path, self.body.expr_path_hygiene(expr), ) - .map_or(true, |res| matches!(res, ValueNs::LocalBinding(_) | ValueNs::StaticId(_))), + .is_none_or(|res| matches!(res, ValueNs::LocalBinding(_) | ValueNs::StaticId(_))), Expr::Underscore => true, Expr::UnaryOp { op: UnaryOp::Deref, .. } => true, Expr::Field { .. } | Expr::Index { .. } => true, @@ -499,7 +499,7 @@ impl InferenceContext<'_> { // if the function is unresolved, we use is_varargs=true to // suppress the arg count diagnostic here let is_varargs = - derefed_callee.callable_sig(self.db).map_or(false, |sig| sig.is_varargs) + derefed_callee.callable_sig(self.db).is_some_and(|sig| sig.is_varargs) || res.is_none(); let (param_tys, ret_ty) = match res { Some((func, params, ret_ty)) => { @@ -2043,7 +2043,7 @@ impl InferenceContext<'_> { continue; } - while skip_indices.peek().map_or(false, |i| *i < idx as u32) { + while skip_indices.peek().is_some_and(|i| *i < idx as u32) { skip_indices.next(); } if skip_indices.peek().copied() == Some(idx as u32) { diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs index d79bf9a05e835..73bcefaf2a9d6 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs @@ -315,13 +315,7 @@ impl InferenceContext<'_> { } AssocItemId::ConstId(konst) => { - if self - .db - .const_data(konst) - .name - .as_ref() - .map_or(false, |n| n == segment.name) - { + if self.db.const_data(konst).name.as_ref() == Some(segment.name) { Some(AssocItemId::ConstId(konst)) } else { None diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs index 165861c1b172e..8a8992cf372da 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs @@ -282,7 +282,7 @@ impl<'a> InferenceTable<'a> { let is_diverging = self .type_variable_table .get(iv.index() as usize) - .map_or(false, |data| data.contains(TypeVariableFlags::DIVERGING)); + .is_some_and(|data| data.contains(TypeVariableFlags::DIVERGING)); if is_diverging { return TyKind::Never.intern(Interner); } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/inhabitedness.rs b/src/tools/rust-analyzer/crates/hir-ty/src/inhabitedness.rs index 56b549436c700..d6039c548b6f5 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/inhabitedness.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/inhabitedness.rs @@ -139,7 +139,7 @@ impl UninhabitedFrom<'_> { ty: &Binders, subst: &Substitution, ) -> ControlFlow { - if vis.map_or(true, |it| it.is_visible_from(self.db.upcast(), self.target_mod)) { + if vis.is_none_or(|it| it.is_visible_from(self.db.upcast(), self.target_mod)) { let ty = ty.clone().substitute(Interner, subst); ty.visit_with(self, DebruijnIndex::INNERMOST) } else { diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/layout/tests.rs b/src/tools/rust-analyzer/crates/hir-ty/src/layout/tests.rs index 2649d88ac2c29..66159ddce2b19 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/layout/tests.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/layout/tests.rs @@ -241,31 +241,31 @@ fn recursive() { #[test] fn repr_packed() { size_and_align! { - #[repr(packed)] + #[repr(Rust, packed)] struct Goal; } size_and_align! { - #[repr(packed(2))] + #[repr(Rust, packed(2))] struct Goal; } size_and_align! { - #[repr(packed(4))] + #[repr(Rust, packed(4))] struct Goal; } size_and_align! { - #[repr(packed)] + #[repr(Rust, packed)] struct Goal(i32); } size_and_align! { - #[repr(packed(2))] + #[repr(Rust, packed(2))] struct Goal(i32); } size_and_align! { - #[repr(packed(4))] + #[repr(Rust, packed(4))] struct Goal(i32); } - check_size_and_align("#[repr(packed(5))] struct Goal(i32);", "", 4, 1); + check_size_and_align("#[repr(Rust, packed(5))] struct Goal(i32);", "", 4, 1); } #[test] diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs index b88caea8d34b0..24f67fd660208 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs @@ -2751,14 +2751,14 @@ fn fallback_bound_vars + HasInterner def_map.is_rustc_coherence_is_core(), &TyKind::Adt(AdtId(adt), _) => adt.module(db.upcast()).krate() == def_map.krate(), - TyKind::Dyn(it) => it.principal_id().map_or(false, |trait_id| { + TyKind::Dyn(it) => it.principal_id().is_some_and(|trait_id| { from_chalk_trait_id(trait_id).module(db.upcast()).krate() == def_map.krate() }), @@ -840,7 +840,7 @@ fn is_inherent_impl_coherent( .contains(StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPL), hir_def::AdtId::EnumId(it) => db.enum_data(it).rustc_has_incoherent_inherent_impls, }, - TyKind::Dyn(it) => it.principal_id().map_or(false, |trait_id| { + TyKind::Dyn(it) => it.principal_id().is_some_and(|trait_id| { db.trait_data(from_chalk_trait_id(trait_id)) .flags .contains(TraitFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS) @@ -903,7 +903,7 @@ pub fn check_orphan_rules(db: &dyn HirDatabase, impl_: ImplId) -> bool { match unwrap_fundamental(ty).kind(Interner) { &TyKind::Adt(AdtId(id), _) => is_local(id.module(db.upcast()).krate()), TyKind::Error => true, - TyKind::Dyn(it) => it.principal_id().map_or(false, |trait_id| { + TyKind::Dyn(it) => it.principal_id().is_some_and(|trait_id| { is_local(from_chalk_trait_id(trait_id).module(db.upcast()).krate()) }), _ => false, @@ -1481,7 +1481,7 @@ fn is_valid_impl_method_candidate( AssocItemId::ConstId(c) => { let db = table.db; check_that!(receiver_ty.is_none()); - check_that!(name.map_or(true, |n| db.const_data(c).name.as_ref() == Some(n))); + check_that!(name.is_none_or(|n| db.const_data(c).name.as_ref() == Some(n))); if let Some(from_module) = visible_from_module { if !db.const_visibility(c).is_visible_from(db.upcast(), from_module) { @@ -1519,7 +1519,7 @@ fn is_valid_trait_method_candidate( AssocItemId::FunctionId(fn_id) => { let data = db.function_data(fn_id); - check_that!(name.map_or(true, |n| n == &data.name)); + check_that!(name.is_none_or(|n| n == &data.name)); table.run_in_snapshot(|table| { let impl_subst = TyBuilder::subst_for_def(db, trait_id, None) @@ -1548,7 +1548,7 @@ fn is_valid_trait_method_candidate( } AssocItemId::ConstId(c) => { check_that!(receiver_ty.is_none()); - check_that!(name.map_or(true, |n| db.const_data(c).name.as_ref() == Some(n))); + check_that!(name.is_none_or(|n| db.const_data(c).name.as_ref() == Some(n))); IsValidCandidate::Yes } @@ -1569,7 +1569,7 @@ fn is_valid_impl_fn_candidate( let db = table.db; let data = db.function_data(fn_id); - check_that!(name.map_or(true, |n| n == &data.name)); + check_that!(name.is_none_or(|n| n == &data.name)); if let Some(from_module) = visible_from_module { if !db.function_visibility(fn_id).is_visible_from(db.upcast(), from_module) { cov_mark::hit!(autoderef_candidate_not_visible); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs index 632f117e02f55..dcae6877ba807 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs @@ -2113,7 +2113,7 @@ impl Evaluator<'_> { while self.heap.len() % align != 0 { self.heap.push(0); } - if size.checked_add(self.heap.len()).map_or(true, |x| x > self.memory_limit) { + if size.checked_add(self.heap.len()).is_none_or(|x| x > self.memory_limit) { return Err(MirEvalError::Panic(format!("Memory allocation of {size} bytes failed"))); } let pos = self.heap.len(); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs b/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs index 42e7edaf0f4f8..3d25c00b8974f 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs @@ -376,7 +376,7 @@ impl OpaqueInternableThing for InTypeConstIdMetadata { } fn dyn_eq(&self, other: &dyn OpaqueInternableThing) -> bool { - other.as_any().downcast_ref::().map_or(false, |x| self == x) + other.as_any().downcast_ref::() == Some(self) } fn dyn_clone(&self) -> Box { diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs index fe4b255d3c57e..00b4db5437401 100644 --- a/src/tools/rust-analyzer/crates/hir/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs @@ -699,7 +699,7 @@ impl Module { let source_map = tree_source_maps.impl_(loc.id.value).item(); let node = &tree[loc.id.value]; let file_id = loc.id.file_id(); - if file_id.macro_file().map_or(false, |it| it.is_builtin_derive(db.upcast())) { + if file_id.macro_file().is_some_and(|it| it.is_builtin_derive(db.upcast())) { // these expansion come from us, diagnosing them is a waste of resources // FIXME: Once we diagnose the inputs to builtin derives, we should at least extract those diagnostics somehow continue; @@ -724,7 +724,7 @@ impl Module { } let trait_ = impl_def.trait_(db); - let trait_is_unsafe = trait_.map_or(false, |t| t.is_unsafe(db)); + let trait_is_unsafe = trait_.is_some_and(|t| t.is_unsafe(db)); let impl_is_negative = impl_def.is_negative(db); let impl_is_unsafe = impl_def.is_unsafe(db); diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics.rs b/src/tools/rust-analyzer/crates/hir/src/semantics.rs index 7f44f396bf366..f53798b39e9ae 100644 --- a/src/tools/rust-analyzer/crates/hir/src/semantics.rs +++ b/src/tools/rust-analyzer/crates/hir/src/semantics.rs @@ -1206,7 +1206,6 @@ impl<'db> SemanticsImpl<'db> { node.original_file_range_opt(self.db.upcast()) .filter(|(_, ctx)| ctx.is_root()) .map(TupleExt::head) - .map(Into::into) } /// Attempts to map the node out of macro expanded files. @@ -1500,7 +1499,7 @@ impl<'db> SemanticsImpl<'db> { pub fn is_proc_macro_call(&self, macro_call: &ast::MacroCall) -> bool { self.resolve_macro_call(macro_call) - .map_or(false, |m| matches!(m.id, MacroId::ProcMacroId(..))) + .is_some_and(|m| matches!(m.id, MacroId::ProcMacroId(..))) } pub fn resolve_macro_call_arm(&self, macro_call: &ast::MacroCall) -> Option { diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs b/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs index 08333c2d76c06..b5cc440fc22ed 100644 --- a/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs +++ b/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs @@ -408,7 +408,7 @@ impl SourceToDefCtx<'_, '_> { } pub(super) fn has_derives(&mut self, adt: InFile<&ast::Adt>) -> bool { - self.dyn_map(adt).as_ref().map_or(false, |map| !map[keys::DERIVE_MACRO_CALL].is_empty()) + self.dyn_map(adt).as_ref().is_some_and(|map| !map[keys::DERIVE_MACRO_CALL].is_empty()) } fn to_def( diff --git a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs index 2f21685fb59d6..b699ccde4128e 100644 --- a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs +++ b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs @@ -949,7 +949,7 @@ impl SourceAnalyzer { .map(|it| (it, None)), }; } - if parent().map_or(false, |it| ast::Visibility::can_cast(it.kind())) { + if parent().is_some_and(|it| ast::Visibility::can_cast(it.kind())) { // No substitution because only modules can be inside visibilities, and those have no generics. resolve_hir_path_qualifier(db, &self.resolver, &hir_path, &types_map) .map(|it| (it, None)) diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_lifetime_to_type.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_lifetime_to_type.rs index 12213c8455c77..43c0a72fa4774 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_lifetime_to_type.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_lifetime_to_type.rs @@ -28,7 +28,7 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext<'_>) - let node = ctx.find_node_at_offset::()?; let has_lifetime = node .generic_param_list() - .map_or(false, |gen_list| gen_list.lifetime_params().next().is_some()); + .is_some_and(|gen_list| gen_list.lifetime_params().next().is_some()); if has_lifetime { return None; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs index b022baf4cb5b5..24b34f140bd03 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs @@ -220,7 +220,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) .arms() .find(|arm| matches!(arm.pat(), Some(ast::Pat::WildcardPat(_)))); if let Some(arm) = catch_all_arm { - let is_empty_expr = arm.expr().map_or(true, |e| match e { + let is_empty_expr = arm.expr().is_none_or(|e| match e { ast::Expr::BlockExpr(b) => { b.statements().next().is_none() && b.tail_expr().is_none() } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs index c30f3e1c3b2b4..ea2752b881857 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs @@ -63,7 +63,7 @@ pub(crate) fn convert_nested_function_to_closure( /// Returns whether the given function is nested within the body of another function. fn is_nested_function(function: &ast::Fn) -> bool { - function.syntax().ancestors().skip(1).find_map(ast::Item::cast).map_or(false, |it| { + function.syntax().ancestors().skip(1).find_map(ast::Item::cast).is_some_and(|it| { matches!(it, ast::Item::Fn(_) | ast::Item::Static(_) | ast::Item::Const(_)) }) } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_struct_binding.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_struct_binding.rs index 22a1efdbea735..e34e50904875d 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_struct_binding.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/destructure_struct_binding.rs @@ -96,8 +96,7 @@ fn collect_data(ident_pat: ast::IdentPat, ctx: &AssistContext<'_>) -> Option( fn find_lifetime(text: &str) -> impl Fn(&&ast::GenericParam) -> bool + '_ { move |gp: &&ast::GenericParam| match gp { ast::GenericParam::LifetimeParam(lp) => { - lp.lifetime().map_or(false, |lt| lt.text() == text) + lp.lifetime().is_some_and(|lt| lt.text() == text) } _ => false, } @@ -118,7 +118,7 @@ fn collect_used_generics<'gp>( ast::GenericParam::TypeParam(tp) => tp.name(), _ => None, } - .map_or(false, |n| n.text() == name_ref.text()) + .is_some_and(|n| n.text() == name_ref.text()) }) { generics.push(param); } @@ -165,7 +165,7 @@ fn collect_used_generics<'gp>( if let Some(name_ref) = path.as_single_name_ref() { if let Some(param) = known_generics.iter().find(|gp| { if let ast::GenericParam::ConstParam(cp) = gp { - cp.name().map_or(false, |n| n.text() == name_ref.text()) + cp.name().is_some_and(|n| n.text() == name_ref.text()) } else { false } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_variable.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_variable.rs index 49753550a5758..0cc807aff6428 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_variable.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_variable.rs @@ -99,7 +99,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op let parent = to_extract.syntax().parent().and_then(ast::Expr::cast); // Any expression that autoderefs may need adjustment. - let mut needs_adjust = parent.as_ref().map_or(false, |it| match it { + let mut needs_adjust = parent.as_ref().is_some_and(|it| match it { ast::Expr::FieldExpr(_) | ast::Expr::MethodCallExpr(_) | ast::Expr::CallExpr(_) diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_param.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_param.rs index 376243c26815f..75120768da0fe 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_param.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_param.rs @@ -47,7 +47,7 @@ pub(crate) fn remove_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> .parent() // AssocItemList .and_then(|x| x.parent()) .and_then(ast::Impl::cast) - .map_or(false, |imp| imp.trait_().is_some()) + .is_some_and(|imp| imp.trait_().is_some()) { cov_mark::hit!(trait_impl); return None; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_if_let_with_match.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_if_let_with_match.rs index 4313cc1ac9dcf..b31d45e6d4502 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_if_let_with_match.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_if_let_with_match.rs @@ -135,7 +135,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext<' }; let has_preceding_if_expr = - if_expr.syntax().parent().map_or(false, |it| ast::IfExpr::can_cast(it.kind())); + if_expr.syntax().parent().is_some_and(|it| ast::IfExpr::can_cast(it.kind())); let expr = if has_preceding_if_expr { // make sure we replace the `else if let ...` with a block so we don't end up with `else expr` make::block_expr(None, Some(match_expr)).into() @@ -241,7 +241,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext<' ast::Pat::LiteralPat(p) if p.literal() .map(|it| it.token().kind()) - .map_or(false, |it| it == T![true] || it == T![false]) => + .is_some_and(|it| it == T![true] || it == T![false]) => { "" } @@ -265,12 +265,12 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext<' let condition = match if_let_pat { ast::Pat::LiteralPat(p) - if p.literal().map_or(false, |it| it.token().kind() == T![true]) => + if p.literal().is_some_and(|it| it.token().kind() == T![true]) => { scrutinee } ast::Pat::LiteralPat(p) - if p.literal().map_or(false, |it| it.token().kind() == T![false]) => + if p.literal().is_some_and(|it| it.token().kind() == T![false]) => { make::expr_prefix(T![!], scrutinee) } @@ -339,10 +339,10 @@ fn binds_name(sema: &hir::Semantics<'_, RootDatabase>, pat: &ast::Pat) -> bool { ast::Pat::TupleStructPat(it) => it.fields().any(binds_name_v), ast::Pat::RecordPat(it) => it .record_pat_field_list() - .map_or(false, |rpfl| rpfl.fields().flat_map(|rpf| rpf.pat()).any(binds_name_v)), - ast::Pat::RefPat(pat) => pat.pat().map_or(false, binds_name_v), - ast::Pat::BoxPat(pat) => pat.pat().map_or(false, binds_name_v), - ast::Pat::ParenPat(pat) => pat.pat().map_or(false, binds_name_v), + .is_some_and(|rpfl| rpfl.fields().flat_map(|rpf| rpf.pat()).any(binds_name_v)), + ast::Pat::RefPat(pat) => pat.pat().is_some_and(binds_name_v), + ast::Pat::BoxPat(pat) => pat.pat().is_some_and(binds_name_v), + ast::Pat::ParenPat(pat) => pat.pat().is_some_and(binds_name_v), _ => false, } } @@ -350,7 +350,7 @@ fn binds_name(sema: &hir::Semantics<'_, RootDatabase>, pat: &ast::Pat) -> bool { fn is_sad_pat(sema: &hir::Semantics<'_, RootDatabase>, pat: &ast::Pat) -> bool { sema.type_of_pat(pat) .and_then(|ty| TryEnum::from_ty(sema, &ty.adjusted())) - .map_or(false, |it| does_pat_match_variant(pat, &it.sad_pattern())) + .is_some_and(|it| does_pat_match_variant(pat, &it.sad_pattern())) } #[cfg(test)] diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs index 1101c20f1b785..f026b3230dd6d 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs @@ -159,7 +159,7 @@ fn path_eq_no_generics(lhs: ast::Path, rhs: ast::Path) -> bool { && lhs .name_ref() .zip(rhs.name_ref()) - .map_or(false, |(lhs, rhs)| lhs.text() == rhs.text()) => {} + .is_some_and(|(lhs, rhs)| lhs.text() == rhs.text()) => {} _ => return false, } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_match_arm.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_match_arm.rs index 648bf358b4bb6..c6cffb5434a5c 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_match_arm.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_match_arm.rs @@ -65,7 +65,7 @@ pub(crate) fn unmerge_match_arm(acc: &mut Assists, ctx: &AssistContext<'_>) -> O let mut pipe_index = pipe_token.index(); if pipe_token .prev_sibling_or_token() - .map_or(false, |it| it.kind() == SyntaxKind::WHITESPACE) + .is_some_and(|it| it.kind() == SyntaxKind::WHITESPACE) { pipe_index -= 1; } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_use.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_use.rs index 52df30d9623fe..38ca572fa6609 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_use.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unmerge_use.rs @@ -66,7 +66,7 @@ fn resolve_full_path(tree: &ast::UseTree) -> Option { .filter_map(|t| t.path()); let final_path = paths.reduce(|prev, next| make::path_concat(next, prev))?; - if final_path.segment().map_or(false, |it| it.self_token().is_some()) { + if final_path.segment().is_some_and(|it| it.self_token().is_some()) { final_path.qualifier() } else { Some(final_path) diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs b/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs index ce0bd46e6f3fb..e20c4ef09e8ce 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs @@ -321,8 +321,8 @@ pub(crate) fn does_pat_variant_nested_or_literal(ctx: &AssistContext<'_>, pat: & } fn check_pat_variant_from_enum(ctx: &AssistContext<'_>, pat: &ast::Pat) -> bool { - ctx.sema.type_of_pat(pat).map_or(true, |ty: hir::TypeInfo| { - ty.adjusted().as_adt().map_or(false, |adt| matches!(adt, hir::Adt::Enum(_))) + ctx.sema.type_of_pat(pat).is_none_or(|ty: hir::TypeInfo| { + ty.adjusted().as_adt().is_some_and(|adt| matches!(adt, hir::Adt::Enum(_))) }) } @@ -345,10 +345,10 @@ fn check_pat_variant_nested_or_literal_with_depth( | ast::Pat::BoxPat(_) | ast::Pat::ConstBlockPat(_) => true, - ast::Pat::IdentPat(ident_pat) => ident_pat.pat().map_or(false, |pat| { + ast::Pat::IdentPat(ident_pat) => ident_pat.pat().is_some_and(|pat| { check_pat_variant_nested_or_literal_with_depth(ctx, &pat, depth_after_refutable) }), - ast::Pat::ParenPat(paren_pat) => paren_pat.pat().map_or(true, |pat| { + ast::Pat::ParenPat(paren_pat) => paren_pat.pat().is_none_or(|pat| { check_pat_variant_nested_or_literal_with_depth(ctx, &pat, depth_after_refutable) }), ast::Pat::TuplePat(tuple_pat) => tuple_pat.fields().any(|pat| { @@ -357,9 +357,9 @@ fn check_pat_variant_nested_or_literal_with_depth( ast::Pat::RecordPat(record_pat) => { let adjusted_next_depth = depth_after_refutable + if check_pat_variant_from_enum(ctx, pat) { 1 } else { 0 }; - record_pat.record_pat_field_list().map_or(true, |pat| { + record_pat.record_pat_field_list().is_none_or(|pat| { pat.fields().any(|pat| { - pat.pat().map_or(true, |pat| { + pat.pat().is_none_or(|pat| { check_pat_variant_nested_or_literal_with_depth( ctx, &pat, @@ -381,8 +381,8 @@ fn check_pat_variant_nested_or_literal_with_depth( } ast::Pat::SlicePat(slice_pat) => { let mut pats = slice_pat.pats(); - pats.next() // Edge case for `[..]` - .map_or(true, |pat| !matches!(pat, ast::Pat::RestPat(_)) || pats.next().is_some()) + pats.next() + .is_none_or(|pat| !matches!(pat, ast::Pat::RestPat(_)) || pats.next().is_some()) } } } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/utils/gen_trait_fn_body.rs b/src/tools/rust-analyzer/crates/ide-assists/src/utils/gen_trait_fn_body.rs index c5a91e478bf8a..75caf6d49f758 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/utils/gen_trait_fn_body.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/utils/gen_trait_fn_body.rs @@ -32,7 +32,7 @@ pub(crate) fn gen_trait_fn_body( /// Generate a `Clone` impl based on the fields and members of the target type. fn gen_clone_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { - stdx::always!(func.name().map_or(false, |name| name.text() == "clone")); + stdx::always!(func.name().is_some_and(|name| name.text() == "clone")); fn gen_clone_call(target: ast::Expr) -> ast::Expr { let method = make::name_ref("clone"); make::expr_method_call(target, method, make::arg_list(None)) @@ -344,7 +344,7 @@ fn gen_default_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { /// Generate a `Hash` impl based on the fields and members of the target type. fn gen_hash_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { - stdx::always!(func.name().map_or(false, |name| name.text() == "hash")); + stdx::always!(func.name().is_some_and(|name| name.text() == "hash")); fn gen_hash_call(target: ast::Expr) -> ast::Stmt { let method = make::name_ref("hash"); let arg = make::expr_path(make::ext::ident_path("state")); @@ -400,7 +400,7 @@ fn gen_hash_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { /// Generate a `PartialEq` impl based on the fields and members of the target type. fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn, trait_ref: Option) -> Option<()> { - stdx::always!(func.name().map_or(false, |name| name.text() == "eq")); + stdx::always!(func.name().is_some_and(|name| name.text() == "eq")); fn gen_eq_chain(expr: Option, cmp: ast::Expr) -> Option { match expr { Some(expr) => Some(make::expr_bin_op(expr, BinaryOp::LogicOp(LogicOp::And), cmp)), @@ -592,7 +592,7 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn, trait_ref: Option) - } fn gen_partial_ord(adt: &ast::Adt, func: &ast::Fn, trait_ref: Option) -> Option<()> { - stdx::always!(func.name().map_or(false, |name| name.text() == "partial_cmp")); + stdx::always!(func.name().is_some_and(|name| name.text() == "partial_cmp")); fn gen_partial_eq_match(match_target: ast::Expr) -> Option { let mut arms = vec![]; diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs index c9013d1d17d43..0b6790d42a610 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs @@ -43,7 +43,7 @@ pub(crate) fn complete_cargo_env_vars( .sema .hir_file_for(&expanded.syntax().parent()?) .macro_file() - .map_or(false, |it| it.is_env_or_option_env(ctx.sema.db)); + .is_some_and(|it| it.is_env_or_option_env(ctx.sema.db)); if !is_in_env_expansion { let call = macro_call_for_string_token(expanded)?; let makro = ctx.sema.resolve_macro_call(&call)?; diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs index 847fa4cf889d2..bcfda928c4da5 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs @@ -46,7 +46,7 @@ pub(crate) fn complete_extern_abi( ctx: &CompletionContext<'_>, expanded: &ast::String, ) -> Option<()> { - if !expanded.syntax().parent().map_or(false, |it| ast::Abi::can_cast(it.kind())) { + if !expanded.syntax().parent().is_some_and(|it| ast::Abi::can_cast(it.kind())) { return None; } let abi_str = expanded; diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/fn_param.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/fn_param.rs index ee3b817ee8cfb..e86eaad4d0f24 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/fn_param.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/fn_param.rs @@ -167,7 +167,7 @@ fn should_add_self_completions( return false; } match param_list.params().next() { - Some(first) => first.pat().map_or(false, |pat| pat.syntax().text_range().contains(cursor)), + Some(first) => first.pat().is_some_and(|pat| pat.syntax().text_range().contains(cursor)), None => true, } } diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/record.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/record.rs index 117a5e3d9359b..d0c4c24d060f8 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/record.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/record.rs @@ -93,7 +93,7 @@ pub(crate) fn add_default_update( let default_trait = ctx.famous_defs().core_default_Default(); let impls_default_trait = default_trait .zip(ty.as_ref()) - .map_or(false, |(default_trait, ty)| ty.original.impls_trait(ctx.db, default_trait, &[])); + .is_some_and(|(default_trait, ty)| ty.original.impls_trait(ctx.db, default_trait, &[])); if impls_default_trait { // FIXME: This should make use of scope_def like completions so we get all the other goodies // that is we should handle this like actually completing the default function diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/use_.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/use_.rs index 45704549e6090..9d62622add206 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/use_.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/use_.rs @@ -101,7 +101,7 @@ pub(crate) fn complete_use_path( ScopeDef::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(e))) => { // exclude prelude enum let is_builtin = - res.krate(ctx.db).map_or(false, |krate| krate.is_builtin(ctx.db)); + res.krate(ctx.db).is_some_and(|krate| krate.is_builtin(ctx.db)); if !is_builtin { let item = CompletionItem::new( diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs b/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs index 1c4cbb25b1fdd..1979755ee5078 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs @@ -456,7 +456,7 @@ fn analyze( && p.ancestors().any(|it| it.kind() == SyntaxKind::META) { let colon_prefix = previous_non_trivia_token(self_token.clone()) - .map_or(false, |it| T![:] == it.kind()); + .is_some_and(|it| T![:] == it.kind()); CompletionAnalysis::UnexpandedAttrTT { fake_attribute_under_caret: fake_ident_token @@ -643,7 +643,7 @@ fn expected_type_and_name( // match foo { $0 } // match foo { ..., pat => $0 } ast::MatchExpr(it) => { - let on_arrow = previous_non_trivia_token(token.clone()).map_or(false, |it| T![=>] == it.kind()); + let on_arrow = previous_non_trivia_token(token.clone()).is_some_and(|it| T![=>] == it.kind()); let ty = if on_arrow { // match foo { ..., pat => $0 } @@ -780,7 +780,7 @@ fn classify_name_ref( if let Some(record_field) = ast::RecordExprField::for_field_name(&name_ref) { let dot_prefix = previous_non_trivia_token(name_ref.syntax().clone()) - .map_or(false, |it| T![.] == it.kind()); + .is_some_and(|it| T![.] == it.kind()); return find_node_in_file_compensated( sema, @@ -814,7 +814,7 @@ fn classify_name_ref( let receiver_is_ambiguous_float_literal = match &receiver { Some(ast::Expr::Literal(l)) => matches! { l.kind(), - ast::LiteralKind::FloatNumber { .. } if l.syntax().last_token().map_or(false, |it| it.text().ends_with('.')) + ast::LiteralKind::FloatNumber { .. } if l.syntax().last_token().is_some_and(|it| it.text().ends_with('.')) }, _ => false, }; @@ -846,7 +846,7 @@ fn classify_name_ref( let receiver = find_opt_node_in_file(original_file, method.receiver()); let kind = NameRefKind::DotAccess(DotAccess { receiver_ty: receiver.as_ref().and_then(|it| sema.type_of_expr(it)), - kind: DotAccessKind::Method { has_parens: method.arg_list().map_or(false, |it| it.l_paren_token().is_some()) }, + kind: DotAccessKind::Method { has_parens: method.arg_list().is_some_and(|it| it.l_paren_token().is_some()) }, receiver, ctx: DotAccessExprCtx { in_block_expr: is_in_block(method.syntax()), in_breakable: is_in_breakable(method.syntax()) } }); @@ -1193,13 +1193,13 @@ fn classify_name_ref( let incomplete_let = it .parent() .and_then(ast::LetStmt::cast) - .map_or(false, |it| it.semicolon_token().is_none()); + .is_some_and(|it| it.semicolon_token().is_none()); let impl_ = fetch_immediate_impl(sema, original_file, expr.syntax()); let in_match_guard = match it.parent().and_then(ast::MatchArm::cast) { Some(arm) => arm .fat_arrow_token() - .map_or(true, |arrow| it.text_range().start() < arrow.text_range().start()), + .is_none_or(|arrow| it.text_range().start() < arrow.text_range().start()), None => false, }; @@ -1329,7 +1329,7 @@ fn classify_name_ref( } } - path_ctx.has_call_parens = it.syntax().parent().map_or(false, |it| ast::CallExpr::can_cast(it.kind())); + path_ctx.has_call_parens = it.syntax().parent().is_some_and(|it| ast::CallExpr::can_cast(it.kind())); make_path_kind_expr(it.into()) }, @@ -1358,7 +1358,7 @@ fn classify_name_ref( match parent { ast::PathType(it) => make_path_kind_type(it.into()), ast::PathExpr(it) => { - path_ctx.has_call_parens = it.syntax().parent().map_or(false, |it| ast::CallExpr::can_cast(it.kind())); + path_ctx.has_call_parens = it.syntax().parent().is_some_and(|it| ast::CallExpr::can_cast(it.kind())); make_path_kind_expr(it.into()) }, @@ -1612,8 +1612,7 @@ fn pattern_context_for( &pat, ast::Pat::IdentPat(it) if it.syntax() - .parent() - .map_or(false, |node| { + .parent().is_some_and(|node| { let kind = node.kind(); ast::LetStmt::can_cast(kind) || ast::Param::can_cast(kind) }) diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/item.rs b/src/tools/rust-analyzer/crates/ide-completion/src/item.rs index 9608eed99d8fd..b91f915619d74 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/item.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/item.rs @@ -631,7 +631,7 @@ impl Builder { self.set_documentation(Some(docs)) } pub(crate) fn set_documentation(&mut self, docs: Option) -> &mut Builder { - self.documentation = docs.map(Into::into); + self.documentation = docs; self } pub(crate) fn set_deprecated(&mut self, deprecated: bool) -> &mut Builder { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/render.rs b/src/tools/rust-analyzer/crates/ide-completion/src/render.rs index baa30b286308e..c239ca512da3f 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/render.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/render.rs @@ -86,11 +86,7 @@ impl<'a> RenderContext<'a> { fn is_immediately_after_macro_bang(&self) -> bool { self.completion.token.kind() == SyntaxKind::BANG - && self - .completion - .token - .parent() - .map_or(false, |it| it.kind() == SyntaxKind::MACRO_CALL) + && self.completion.token.parent().is_some_and(|it| it.kind() == SyntaxKind::MACRO_CALL) } fn is_deprecated(&self, def: impl HasAttrs) -> bool { @@ -636,7 +632,7 @@ fn compute_type_match( } fn compute_exact_name_match(ctx: &CompletionContext<'_>, completion_name: &str) -> bool { - ctx.expected_name.as_ref().map_or(false, |name| name.text() == completion_name) + ctx.expected_name.as_ref().is_some_and(|name| name.text() == completion_name) } fn compute_ref_match( @@ -778,7 +774,7 @@ mod tests { relevance.postfix_match == Some(CompletionRelevancePostfixMatch::Exact), "snippet", ), - (relevance.trait_.map_or(false, |it| it.is_op_method), "op_method"), + (relevance.trait_.is_some_and(|it| it.is_op_method), "op_method"), (relevance.requires_import, "requires_import"), ] .into_iter() diff --git a/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs b/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs index 42a80d63b1af5..7482491fc6346 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs @@ -48,7 +48,7 @@ pub fn callable_for_token( let parent = token.parent()?; let calling_node = parent.ancestors().filter_map(ast::CallableExpr::cast).find(|it| { it.arg_list() - .map_or(false, |it| it.syntax().text_range().contains(token.text_range().start())) + .is_some_and(|it| it.syntax().text_range().contains(token.text_range().start())) })?; callable_for_node(sema, &calling_node, &token) @@ -136,7 +136,7 @@ pub fn generic_def_for_node( let first_arg_is_non_lifetime = generic_arg_list .generic_args() .next() - .map_or(false, |arg| !matches!(arg, ast::GenericArg::LifetimeArg(_))); + .is_some_and(|arg| !matches!(arg, ast::GenericArg::LifetimeArg(_))); Some((def, active_param, first_arg_is_non_lifetime, variant)) } diff --git a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs index cef292a528aa7..2d30bb412735a 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs @@ -335,7 +335,7 @@ fn find_std_module( let std_crate = famous_defs.std()?; let std_root_module = std_crate.root_module(); std_root_module.children(db).find(|module| { - module.name(db).map_or(false, |module| module.display(db, edition).to_string() == name) + module.name(db).is_some_and(|module| module.display(db, edition).to_string() == name) }) } diff --git a/src/tools/rust-analyzer/crates/ide-db/src/documentation.rs b/src/tools/rust-analyzer/crates/ide-db/src/documentation.rs index b52a325790b18..a0ef0f90a65b1 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/documentation.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/documentation.rs @@ -226,9 +226,8 @@ impl HasDocs for hir::AssocItem { impl HasDocs for hir::ExternCrateDecl { fn docs(self, db: &dyn HirDatabase) -> Option { - let crate_docs = - docs_from_attrs(&self.resolved_crate(db)?.root_module().attrs(db)).map(String::from); - let decl_docs = docs_from_attrs(&self.attrs(db)).map(String::from); + let crate_docs = docs_from_attrs(&self.resolved_crate(db)?.root_module().attrs(db)); + let decl_docs = docs_from_attrs(&self.attrs(db)); match (decl_docs, crate_docs) { (None, None) => None, (Some(decl_docs), None) => Some(decl_docs), diff --git a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs index dab36bf20b9b4..8f0be1d90354d 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs @@ -706,7 +706,7 @@ fn path_import_candidate( Some(match qualifier { Some(qualifier) => match sema.resolve_path(&qualifier) { Some(PathResolution::Def(ModuleDef::BuiltinType(_))) | None => { - if qualifier.first_qualifier().map_or(true, |it| sema.resolve_path(&it).is_none()) { + if qualifier.first_qualifier().is_none_or(|it| sema.resolve_path(&it).is_none()) { let qualifier = qualifier .segments() .map(|seg| seg.name_ref().map(|name| SmolStr::new(name.text()))) diff --git a/src/tools/rust-analyzer/crates/ide-db/src/imports/insert_use.rs b/src/tools/rust-analyzer/crates/ide-db/src/imports/insert_use.rs index fc86d169a2431..8e25ad3472d3b 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/imports/insert_use.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/imports/insert_use.rs @@ -72,9 +72,7 @@ impl ImportScope { fn from(syntax: SyntaxNode) -> Option { use syntax::match_ast; fn contains_cfg_attr(attrs: &dyn HasAttrs) -> bool { - attrs - .attrs() - .any(|attr| attr.as_simple_call().map_or(false, |(ident, _)| ident == "cfg")) + attrs.attrs().any(|attr| attr.as_simple_call().is_some_and(|(ident, _)| ident == "cfg")) } match_ast! { match syntax { @@ -102,9 +100,7 @@ impl ImportScope { sema: &Semantics<'_, RootDatabase>, ) -> Option { fn contains_cfg_attr(attrs: &dyn HasAttrs) -> bool { - attrs - .attrs() - .any(|attr| attr.as_simple_call().map_or(false, |(ident, _)| ident == "cfg")) + attrs.attrs().any(|attr| attr.as_simple_call().is_some_and(|(ident, _)| ident == "cfg")) } // Walk up the ancestor tree searching for a suitable node to do insertions on @@ -487,7 +483,7 @@ fn insert_use_(scope: &ImportScope, use_item: ast::Use, group_imports: bool) { .contains(&token.kind()) } }) - .filter(|child| child.as_token().map_or(true, |t| t.kind() != SyntaxKind::WHITESPACE)) + .filter(|child| child.as_token().is_none_or(|t| t.kind() != SyntaxKind::WHITESPACE)) .last() { cov_mark::hit!(insert_empty_inner_attr); diff --git a/src/tools/rust-analyzer/crates/ide-db/src/imports/merge_imports.rs b/src/tools/rust-analyzer/crates/ide-db/src/imports/merge_imports.rs index 4c197b453381b..9e89dfe87abe5 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/imports/merge_imports.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/imports/merge_imports.rs @@ -290,7 +290,7 @@ pub fn try_normalize_use_tree_mut( fn recursive_normalize(use_tree: &ast::UseTree, style: NormalizationStyle) -> Option<()> { let use_tree_list = use_tree.use_tree_list()?; let merge_subtree_into_parent_tree = |single_subtree: &ast::UseTree| { - let subtree_is_only_self = single_subtree.path().as_ref().map_or(false, path_is_self); + let subtree_is_only_self = single_subtree.path().as_ref().is_some_and(path_is_self); let merged_path = match (use_tree.path(), single_subtree.path()) { // If the subtree is `{self}` then we cannot merge: `use diff --git a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs index 1f77ea1ec66c1..b3105e6524d5b 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs @@ -320,7 +320,7 @@ impl<'a> Ranker<'a> { let same_text = tok.text() == self.text; // anything that mapped into a token tree has likely no semantic information let no_tt_parent = - tok.parent().map_or(false, |it| it.kind() != parser::SyntaxKind::TOKEN_TREE); + tok.parent().is_some_and(|it| it.kind() != parser::SyntaxKind::TOKEN_TREE); (both_idents as usize) | ((exact_same_kind as usize) << 1) | ((same_text as usize) << 2) diff --git a/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs b/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs index 156f21b784e59..a045c22c2dff1 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs @@ -285,7 +285,7 @@ impl Ctx<'_> { if path.qualifier().is_some() { return None; } - if path.segment().map_or(false, |s| { + if path.segment().is_some_and(|s| { s.parenthesized_arg_list().is_some() || (s.self_token().is_some() && path.parent_path().is_none()) }) { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/search.rs b/src/tools/rust-analyzer/crates/ide-db/src/search.rs index 24b4d26ec7204..68199dd871189 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/search.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/search.rs @@ -1356,12 +1356,12 @@ fn is_name_ref_in_import(name_ref: &ast::NameRef) -> bool { .parent() .and_then(ast::PathSegment::cast) .and_then(|it| it.parent_path().top_path().syntax().parent()) - .map_or(false, |it| it.kind() == SyntaxKind::USE_TREE) + .is_some_and(|it| it.kind() == SyntaxKind::USE_TREE) } fn is_name_ref_in_test(sema: &Semantics<'_, RootDatabase>, name_ref: &ast::NameRef) -> bool { name_ref.syntax().ancestors().any(|node| match ast::Fn::cast(node) { - Some(it) => sema.to_def(&it).map_or(false, |func| func.is_test(sema.db)), + Some(it) => sema.to_def(&it).is_some_and(|func| func.is_test(sema.db)), None => false, }) } diff --git a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs index 91e0b4495f5f1..74c0b8e2baace 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs @@ -220,7 +220,7 @@ pub fn vis_eq(this: &ast::Visibility, other: &ast::Visibility) -> bool { match (this.kind(), other.kind()) { (VisibilityKind::In(this), VisibilityKind::In(other)) => { stdx::iter_eq_by(this.segments(), other.segments(), |lhs, rhs| { - lhs.kind().zip(rhs.kind()).map_or(false, |it| match it { + lhs.kind().zip(rhs.kind()).is_some_and(|it| match it { (PathSegmentKind::CrateKw, PathSegmentKind::CrateKw) | (PathSegmentKind::SelfKw, PathSegmentKind::SelfKw) | (PathSegmentKind::SuperKw, PathSegmentKind::SuperKw) => true, @@ -259,7 +259,7 @@ pub fn is_pattern_cond(expr: ast::Expr) -> bool { .or_else(|| expr.rhs().map(is_pattern_cond)) .unwrap_or(false) } - ast::Expr::ParenExpr(expr) => expr.expr().map_or(false, is_pattern_cond), + ast::Expr::ParenExpr(expr) => expr.expr().is_some_and(is_pattern_cond), ast::Expr::LetExpr(_) => true, _ => false, } @@ -408,7 +408,7 @@ fn for_each_break_expr( } pub fn eq_label_lt(lt1: &Option, lt2: &Option) -> bool { - lt1.as_ref().zip(lt2.as_ref()).map_or(false, |(lt, lbl)| lt.text() == lbl.text()) + lt1.as_ref().zip(lt2.as_ref()).is_some_and(|(lt, lbl)| lt.text() == lbl.text()) } struct TreeWithDepthIterator { diff --git a/src/tools/rust-analyzer/crates/ide/src/doc_links/intra_doc_links.rs b/src/tools/rust-analyzer/crates/ide/src/doc_links/intra_doc_links.rs index ebdd4add177eb..6cc240d652499 100644 --- a/src/tools/rust-analyzer/crates/ide/src/doc_links/intra_doc_links.rs +++ b/src/tools/rust-analyzer/crates/ide/src/doc_links/intra_doc_links.rs @@ -25,7 +25,7 @@ pub(super) fn parse_intra_doc_link(s: &str) -> (&str, Option) { .find_map(|(ns, (prefixes, suffixes))| { if let Some(prefix) = prefixes.iter().find(|&&prefix| { s.starts_with(prefix) - && s.chars().nth(prefix.len()).map_or(false, |c| c == '@' || c == ' ') + && s.chars().nth(prefix.len()).is_some_and(|c| c == '@' || c == ' ') }) { Some((&s[prefix.len() + 1..], ns)) } else { @@ -41,7 +41,7 @@ pub(super) fn strip_prefixes_suffixes(s: &str) -> &str { .find_map(|(prefixes, suffixes)| { if let Some(prefix) = prefixes.iter().find(|&&prefix| { s.starts_with(prefix) - && s.chars().nth(prefix.len()).map_or(false, |c| c == '@' || c == ' ') + && s.chars().nth(prefix.len()).is_some_and(|c| c == '@' || c == ' ') }) { Some(&s[prefix.len() + 1..]) } else { diff --git a/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs b/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs index 4690416e0596f..4002cbebad6c0 100644 --- a/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs +++ b/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs @@ -307,7 +307,7 @@ fn hl_exit_points( let range = match &expr { ast::Expr::TryExpr(try_) => try_.question_mark_token().map(|token| token.text_range()), ast::Expr::MethodCallExpr(_) | ast::Expr::CallExpr(_) | ast::Expr::MacroExpr(_) - if sema.type_of_expr(&expr).map_or(false, |ty| ty.original.is_never()) => + if sema.type_of_expr(&expr).is_some_and(|ty| ty.original.is_never()) => { Some(expr.syntax().text_range()) } diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs index d72acad09fbf8..8fbd445d9624d 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs +++ b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs @@ -336,8 +336,8 @@ pub(super) fn try_for_lint(attr: &ast::Attr, token: &SyntaxToken) -> Option (bool, // - `dummy_expr` is the original expression wrapped in the operator we want (`*`/`.*`) // - `expr` is the clone of the original expression (with `dummy_expr` as the parent) - let needs_outer_parens = parent.map_or(false, |p| dummy_expr.needs_parens_in(p)); + let needs_outer_parens = parent.is_some_and(|p| dummy_expr.needs_parens_in(p)); let needs_inner_parens = expr.needs_parens_in(dummy_expr.syntax().clone()); (needs_outer_parens, needs_inner_parens) diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/discriminant.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/discriminant.rs index cd77c3ec3e905..8f2949cb38798 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/discriminant.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/discriminant.rs @@ -32,7 +32,7 @@ pub(super) fn enum_hints( return None; } // data carrying enums without a primitive repr have no stable discriminants - if data_carrying && def.repr(sema.db).map_or(true, |r| r.int.is_none()) { + if data_carrying && def.repr(sema.db).is_none_or(|r| r.int.is_none()) { return None; } for variant in enum_.variant_list()?.variants() { diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs index 28b0fa6dd4d1a..a03ff6a52b4c2 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs @@ -153,7 +153,7 @@ fn is_param_name_suffix_of_fn_name( .len() .checked_sub(param_name.len()) .and_then(|at| function.is_char_boundary(at).then(|| function.split_at(at))) - .map_or(false, |(prefix, suffix)| { + .is_some_and(|(prefix, suffix)| { suffix.eq_ignore_ascii_case(param_name) && prefix.ends_with('_') }) } diff --git a/src/tools/rust-analyzer/crates/ide/src/lib.rs b/src/tools/rust-analyzer/crates/ide/src/lib.rs index 22a9ee52079c0..6e7c718953cc9 100644 --- a/src/tools/rust-analyzer/crates/ide/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide/src/lib.rs @@ -675,9 +675,7 @@ impl Analysis { position: FilePosition, trigger_character: Option, ) -> Cancellable>> { - self.with_db(|db| { - ide_completion::completions(db, config, position, trigger_character).map(Into::into) - }) + self.with_db(|db| ide_completion::completions(db, config, position, trigger_character)) } /// Resolves additional completion data at the position given. diff --git a/src/tools/rust-analyzer/crates/ide/src/parent_module.rs b/src/tools/rust-analyzer/crates/ide/src/parent_module.rs index 74c50fcac3528..b51a5cc4f4c16 100644 --- a/src/tools/rust-analyzer/crates/ide/src/parent_module.rs +++ b/src/tools/rust-analyzer/crates/ide/src/parent_module.rs @@ -34,7 +34,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec { refs.for_each(|it| { - it.retain(|reference| reference.name.as_name_ref().map_or(false, is_lit_name_ref)) + it.retain(|reference| reference.name.as_name_ref().is_some_and(is_lit_name_ref)) }); usages.references.retain(|_, it| !it.is_empty()); } diff --git a/src/tools/rust-analyzer/crates/ide/src/rename.rs b/src/tools/rust-analyzer/crates/ide/src/rename.rs index b146df6d0b4f9..11bbd99110b45 100644 --- a/src/tools/rust-analyzer/crates/ide/src/rename.rs +++ b/src/tools/rust-analyzer/crates/ide/src/rename.rs @@ -227,8 +227,7 @@ fn find_definitions( ast::NameLike::Name(name) if name .syntax() - .parent() - .map_or(false, |it| ast::Rename::can_cast(it.kind())) + .parent().is_some_and(|it| ast::Rename::can_cast(it.kind())) // FIXME: uncomment this once we resolve to usages to extern crate declarations // && name // .syntax() @@ -264,8 +263,7 @@ fn find_definitions( .and_then(|def| { // if the name differs from the definitions name it has to be an alias if def - .name(sema.db) - .map_or(false, |it| !it.eq_ident(name_ref.text().as_str())) + .name(sema.db).is_some_and(|it| !it.eq_ident(name_ref.text().as_str())) { Err(format_err!("Renaming aliases is currently unsupported")) } else { diff --git a/src/tools/rust-analyzer/crates/ide/src/runnables.rs b/src/tools/rust-analyzer/crates/ide/src/runnables.rs index e89a6339026bd..3e39c750b13b1 100644 --- a/src/tools/rust-analyzer/crates/ide/src/runnables.rs +++ b/src/tools/rust-analyzer/crates/ide/src/runnables.rs @@ -560,7 +560,7 @@ fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool { const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] = &["", "rust", "should_panic", "edition2015", "edition2018", "edition2021"]; - docs_from_attrs(attrs).map_or(false, |doc| { + docs_from_attrs(attrs).is_some_and(|doc| { let mut in_code_block = false; for line in doc.lines() { diff --git a/src/tools/rust-analyzer/crates/ide/src/signature_help.rs b/src/tools/rust-analyzer/crates/ide/src/signature_help.rs index 516f64959cefa..84ccadc8c4ee3 100644 --- a/src/tools/rust-analyzer/crates/ide/src/signature_help.rs +++ b/src/tools/rust-analyzer/crates/ide/src/signature_help.rs @@ -165,7 +165,7 @@ fn signature_help_for_call( if let Some(callable) = ast::CallableExpr::cast(nodes.next()?) { let inside_callable = callable .arg_list() - .map_or(false, |it| it.syntax().text_range().contains(token.text_range().start())); + .is_some_and(|it| it.syntax().text_range().contains(token.text_range().start())); if inside_callable { break callable; } @@ -650,7 +650,7 @@ fn signature_help_for_tuple_pat_ish( ) -> SignatureHelp { let rest_pat = field_pats.find(|it| matches!(it, ast::Pat::RestPat(_))); let is_left_of_rest_pat = - rest_pat.map_or(true, |it| token.text_range().start() < it.syntax().text_range().end()); + rest_pat.is_none_or(|it| token.text_range().start() < it.syntax().text_range().end()); let commas = pat .children_with_tokens() diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs index 0747d1b404b4f..f53f0aec09842 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs @@ -346,7 +346,7 @@ fn traverse( macro_highlighter = MacroHighlighter::default(); } Some(item) - if attr_or_derive_item.as_ref().map_or(false, |it| *it.item() == item) => + if attr_or_derive_item.as_ref().is_some_and(|it| *it.item() == item) => { attr_or_derive_item = None; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs index 89510e7062eb9..4f3d5d9d00c26 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs @@ -155,7 +155,7 @@ fn punctuation( if parent .as_ref() .and_then(SyntaxNode::parent) - .map_or(false, |it| it.kind() == MACRO_RULES) => + .is_some_and(|it| it.kind() == MACRO_RULES) => { return HlOperator::Other.into() } @@ -193,7 +193,7 @@ fn keyword( T![for] if parent_matches::(&token) => h | HlMod::ControlFlow, T![unsafe] => h | HlMod::Unsafe, T![const] - if token.parent().map_or(false, |it| { + if token.parent().is_some_and(|it| { matches!( it.kind(), SyntaxKind::CONST @@ -253,7 +253,7 @@ fn highlight_name_ref( && !sema .hir_file_for(name_ref.syntax()) .macro_file() - .map_or(false, |it| it.is_derive_attr_pseudo_expansion(sema.db)) => + .is_some_and(|it| it.is_derive_attr_pseudo_expansion(sema.db)) => { return HlTag::Symbol(SymbolKind::Attribute).into(); } @@ -275,7 +275,7 @@ fn highlight_name_ref( } Definition::Trait(trait_) if trait_.is_unsafe(db) => { if ast::Impl::for_trait_name_ref(&name_ref) - .map_or(false, |impl_| impl_.unsafe_token().is_some()) + .is_some_and(|impl_| impl_.unsafe_token().is_some()) { h |= HlMod::Unsafe; } @@ -550,7 +550,7 @@ pub(super) fn highlight_def( let def_crate = def.krate(db); let is_from_other_crate = def_crate != Some(krate); - let is_from_builtin_crate = def_crate.map_or(false, |def_crate| def_crate.is_builtin(db)); + let is_from_builtin_crate = def_crate.is_some_and(|def_crate| def_crate.is_builtin(db)); let is_builtin = matches!( def, Definition::BuiltinType(_) | Definition::BuiltinLifetime(_) | Definition::BuiltinAttr(_) @@ -688,7 +688,7 @@ fn highlight_name_ref_by_syntax( let h = HlTag::Symbol(SymbolKind::Field); let is_union = ast::FieldExpr::cast(parent) .and_then(|field_expr| sema.resolve_field(&field_expr)) - .map_or(false, |field| match field { + .is_some_and(|field| match field { Either::Left(field) => { matches!(field.parent_def(sema.db), hir::VariantDef::Union(_)) } @@ -764,5 +764,5 @@ fn parents_match(mut node: NodeOrToken, mut kinds: &[Sy } fn parent_matches(token: &SyntaxToken) -> bool { - token.parent().map_or(false, |it| N::can_cast(it.kind())) + token.parent().is_some_and(|it| N::can_cast(it.kind())) } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/inject.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/inject.rs index 5583f1bc8df92..0a157c157c388 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/inject.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/inject.rs @@ -28,7 +28,7 @@ pub(super) fn ra_fixture( expanded: &ast::String, ) -> Option<()> { let active_parameter = ActiveParameter::at_token(sema, expanded.syntax().clone())?; - if !active_parameter.ident().map_or(false, |name| name.text().starts_with("ra_fixture")) { + if !active_parameter.ident().is_some_and(|name| name.text().starts_with("ra_fixture")) { return None; } let value = literal.value().ok()?; @@ -279,9 +279,7 @@ fn find_doc_string_in_attr(attr: &hir::Attr, it: &ast::Attr) -> Option None, } diff --git a/src/tools/rust-analyzer/crates/ide/src/typing.rs b/src/tools/rust-analyzer/crates/ide/src/typing.rs index d37318ff45706..8998934e0e89e 100644 --- a/src/tools/rust-analyzer/crates/ide/src/typing.rs +++ b/src/tools/rust-analyzer/crates/ide/src/typing.rs @@ -174,7 +174,7 @@ fn on_delimited_node_typed( kinds: &[fn(SyntaxKind) -> bool], ) -> Option { let t = reparsed.syntax().token_at_offset(offset).right_biased()?; - if t.prev_token().map_or(false, |t| t.kind().is_any_identifier()) { + if t.prev_token().is_some_and(|t| t.kind().is_any_identifier()) { return None; } let (filter, node) = t diff --git a/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs b/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs index 68e9fad23218c..3aacfd120c6b7 100644 --- a/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs +++ b/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs @@ -390,7 +390,7 @@ fn expand_var( let mut span = id; marker(&mut span); let wrap_in_parens = !matches!(sub.flat_tokens(), [tt::TokenTree::Leaf(_)]) - && sub.try_into_subtree().map_or(true, |it| { + && sub.try_into_subtree().is_none_or(|it| { it.top_subtree().delimiter.kind == tt::DelimiterKind::Invisible }); if wrap_in_parens { diff --git a/src/tools/rust-analyzer/crates/parser/src/input.rs b/src/tools/rust-analyzer/crates/parser/src/input.rs index 9504bd4d9ec83..c90b358cfbb44 100644 --- a/src/tools/rust-analyzer/crates/parser/src/input.rs +++ b/src/tools/rust-analyzer/crates/parser/src/input.rs @@ -72,7 +72,7 @@ impl Input { } pub(crate) fn is_joint(&self, n: usize) -> bool { let (idx, b_idx) = self.bit_index(n); - self.joint[idx] & 1 << b_idx != 0 + self.joint[idx] & (1 << b_idx) != 0 } } diff --git a/src/tools/rust-analyzer/crates/parser/src/output.rs b/src/tools/rust-analyzer/crates/parser/src/output.rs index 41d4c68b2d748..386d03a62cc1a 100644 --- a/src/tools/rust-analyzer/crates/parser/src/output.rs +++ b/src/tools/rust-analyzer/crates/parser/src/output.rs @@ -85,7 +85,7 @@ impl Output { } pub(crate) fn float_split_hack(&mut self, ends_in_dot: bool) { - let e = (Self::SPLIT_EVENT as u32) << Self::TAG_SHIFT + let e = ((Self::SPLIT_EVENT as u32) << Self::TAG_SHIFT) | ((ends_in_dot as u32) << Self::N_INPUT_TOKEN_SHIFT) | Self::EVENT_MASK; self.event.push(e); @@ -99,7 +99,7 @@ impl Output { } pub(crate) fn leave_node(&mut self) { - let e = (Self::EXIT_EVENT as u32) << Self::TAG_SHIFT | Self::EVENT_MASK; + let e = ((Self::EXIT_EVENT as u32) << Self::TAG_SHIFT) | Self::EVENT_MASK; self.event.push(e) } diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs b/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs index 78f5fb965fe5e..c194f301714fc 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs @@ -450,13 +450,13 @@ impl<'a, S: InternableSpan> Writer<'a, '_, S> { }), suffix, }); - idx << 2 | 0b01 + (idx << 2) | 0b01 } tt::Leaf::Punct(punct) => { let idx = self.punct.len() as u32; let id = self.token_id_of(punct.span); self.punct.push(PunctRepr { char: punct.char, spacing: punct.spacing, id }); - idx << 2 | 0b10 + (idx << 2) | 0b10 } tt::Leaf::Ident(ident) => { let idx = self.ident.len() as u32; @@ -469,7 +469,7 @@ impl<'a, S: InternableSpan> Writer<'a, '_, S> { self.intern(ident.sym.as_str()) }; self.ident.push(IdentRepr { id, text, is_raw: ident.is_raw.yes() }); - idx << 2 | 0b11 + (idx << 2) | 0b11 } }, }; diff --git a/src/tools/rust-analyzer/crates/project-model/src/manifest_path.rs b/src/tools/rust-analyzer/crates/project-model/src/manifest_path.rs index a72dab607525f..73a4e6e121691 100644 --- a/src/tools/rust-analyzer/crates/project-model/src/manifest_path.rs +++ b/src/tools/rust-analyzer/crates/project-model/src/manifest_path.rs @@ -46,7 +46,7 @@ impl ManifestPath { } pub fn is_rust_manifest(&self) -> bool { - self.file.extension().map_or(false, |ext| ext == "rs") + self.file.extension() == Some("rs") } } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/rustc_tests.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/rustc_tests.rs index e45492e17ed69..a4be277da6d62 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/rustc_tests.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/rustc_tests.rs @@ -301,7 +301,7 @@ impl flags::RustcTests { continue; } } - if p.extension().map_or(true, |x| x != "rs") { + if p.extension().is_none_or(|x| x != "rs") { continue; } if let Err(e) = std::panic::catch_unwind({ diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs index 36870851a8bb3..6ca7d9ac057e0 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs @@ -448,7 +448,7 @@ impl SymbolGenerator { .identifier .description .get(moniker.identifier.description.len() - 2) - .map_or(false, |descriptor| { + .is_some_and(|descriptor| { descriptor.desc == MonikerDescriptorKind::Type && descriptor.name == "impl" }), diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs index 35987ebea3d35..64ce1248353af 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs @@ -895,7 +895,7 @@ impl Config { if let Some(mut json) = change.client_config_change { tracing::info!("updating config from JSON: {:#}", json); - if !(json.is_null() || json.as_object().map_or(false, |it| it.is_empty())) { + if !(json.is_null() || json.as_object().is_some_and(|it| it.is_empty())) { let mut json_errors = vec![]; let detached_files = get_field_json::>( &mut json, diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics/to_proto.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics/to_proto.rs index c3ab7f3ae7156..fafffa043f988 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -500,7 +500,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( fn rustc_code_description(code: Option<&str>) -> Option { code.filter(|code| { let mut chars = code.chars(); - chars.next().map_or(false, |c| c == 'E') + chars.next() == Some('E') && chars.by_ref().take(4).all(|c| c.is_ascii_digit()) && chars.next().is_none() }) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs index 2a1fe7c41e28a..ba06d97040e37 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs @@ -462,7 +462,7 @@ impl FlycheckActor { if let Some(manifest_path) = &self.manifest_path { cmd.arg("--manifest-path"); cmd.arg(manifest_path); - if manifest_path.extension().map_or(false, |ext| ext == "rs") { + if manifest_path.extension() == Some("rs") { cmd.arg("-Zscript"); } } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs index 4533755bb4f32..fe4d02dcb4fc5 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs @@ -561,8 +561,7 @@ pub(crate) fn inlay_hint( let text_edits = if snap .config .visual_studio_code_version() - // https://github.com/microsoft/vscode/issues/193124 - .map_or(true, |version| VersionReq::parse(">=1.86.0").unwrap().matches(version)) + .is_none_or(|version| VersionReq::parse(">=1.86.0").unwrap().matches(version)) && resolve_range_and_hash.is_some() && fields_to_resolve.resolve_text_edits { diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/edit_in_place.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/edit_in_place.rs index ffe9f16cfd526..291fc646e2161 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/edit_in_place.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/edit_in_place.rs @@ -751,7 +751,7 @@ impl ast::MatchArmList { ted::insert_all(position, elements); fn needs_comma(arm: &ast::MatchArm) -> bool { - arm.expr().map_or(false, |e| !e.is_block_like()) && arm.comma_token().is_none() + arm.expr().is_some_and(|e| !e.is_block_like()) && arm.comma_token().is_none() } } } diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/expr_ext.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/expr_ext.rs index f3053f59836f6..9466755576b6c 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/expr_ext.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/expr_ext.rs @@ -393,7 +393,7 @@ impl ast::BlockExpr { FOR_EXPR | IF_EXPR => parent .children() .find(|it| ast::Expr::can_cast(it.kind())) - .map_or(true, |it| it == *self.syntax()), + .is_none_or(|it| it == *self.syntax()), LET_ELSE | FN | WHILE_EXPR | LOOP_EXPR | CONST_BLOCK_PAT => false, _ => true, } diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs index f77ca7ff068a5..282cbc4b3a4a2 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs @@ -819,7 +819,7 @@ pub fn match_arm_with_guard( pub fn match_arm_list(arms: impl IntoIterator) -> ast::MatchArmList { let arms_str = arms.into_iter().fold(String::new(), |mut acc, arm| { - let needs_comma = arm.expr().map_or(true, |it| !it.is_block_like()); + let needs_comma = arm.expr().is_none_or(|it| !it.is_block_like()); let comma = if needs_comma { "," } else { "" }; let arm = arm.syntax(); format_to_acc!(acc, " {arm}{comma}\n") diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs index 6ec73e76f78d0..81c7e15bcbc49 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs @@ -333,7 +333,7 @@ impl ast::Path { impl ast::Use { pub fn is_simple_glob(&self) -> bool { - self.use_tree().map_or(false, |use_tree| { + self.use_tree().is_some_and(|use_tree| { use_tree.use_tree_list().is_none() && use_tree.star_token().is_some() }) } @@ -387,7 +387,7 @@ impl ast::UseTreeList { if let Some((single_subtree,)) = u.use_trees().collect_tuple() { // We have a single subtree, check whether it is self. - let is_self = single_subtree.path().as_ref().map_or(false, |path| { + let is_self = single_subtree.path().as_ref().is_some_and(|path| { path.segment().and_then(|seg| seg.self_token()).is_some() && path.qualifier().is_none() }); diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/token_ext.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/token_ext.rs index df017ddde6432..7d5ca2704354d 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/token_ext.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/token_ext.rs @@ -116,7 +116,7 @@ impl CommentKind { impl ast::Whitespace { pub fn spans_multiple_lines(&self) -> bool { let text = self.text(); - text.find('\n').map_or(false, |idx| text[idx + 1..].contains('\n')) + text.find('\n').is_some_and(|idx| text[idx + 1..].contains('\n')) } } diff --git a/src/tools/rust-analyzer/crates/syntax/src/syntax_editor/edits.rs b/src/tools/rust-analyzer/crates/syntax/src/syntax_editor/edits.rs index 8069fdd06f74d..450d601615ee9 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/syntax_editor/edits.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/syntax_editor/edits.rs @@ -24,7 +24,7 @@ impl SyntaxEditor { if last_param .syntax() .next_sibling_or_token() - .map_or(false, |it| it.kind() == SyntaxKind::COMMA) + .is_some_and(|it| it.kind() == SyntaxKind::COMMA) { self.insert( Position::after(last_param.syntax()), diff --git a/src/tools/rust-analyzer/crates/toolchain/src/lib.rs b/src/tools/rust-analyzer/crates/toolchain/src/lib.rs index 33578e056ee64..325b94cc33bae 100644 --- a/src/tools/rust-analyzer/crates/toolchain/src/lib.rs +++ b/src/tools/rust-analyzer/crates/toolchain/src/lib.rs @@ -116,7 +116,6 @@ fn lookup_in_path(exec: &str) -> Option { let paths = env::var_os("PATH").unwrap_or_default(); env::split_paths(&paths) .map(|path| path.join(exec)) - .map(PathBuf::from) .map(Utf8PathBuf::try_from) .filter_map(Result::ok) .find_map(probe_for_binary) diff --git a/src/tools/rust-analyzer/xtask/src/codegen/grammar.rs b/src/tools/rust-analyzer/xtask/src/codegen/grammar.rs index 035891dcbeef9..d5fe32367899e 100644 --- a/src/tools/rust-analyzer/xtask/src/codegen/grammar.rs +++ b/src/tools/rust-analyzer/xtask/src/codegen/grammar.rs @@ -884,7 +884,7 @@ fn lower_separated_list( if !matches!( repeat.as_slice(), [comma, nt_] - if trailing_sep.map_or(true, |it| comma == &**it) && match (nt, nt_) { + if trailing_sep.is_none_or(|it| comma == &**it) && match (nt, nt_) { (Either::Left(node), Rule::Node(nt_)) => node == nt_, (Either::Right(token), Rule::Token(nt_)) => token == nt_, _ => false,