diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f705d00442227..a81d449420acb 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2282,10 +2282,10 @@ pub struct FnDecl { impl FnDecl { pub fn has_self(&self) -> bool { - self.inputs.get(0).map_or(false, Param::is_self) + self.inputs.get(0).is_some_and(|p| p.is_self()) } pub fn c_variadic(&self) -> bool { - self.inputs.last().map_or(false, |arg| matches!(arg.ty.kind, TyKind::CVarArgs)) + self.inputs.last().is_some_and(|arg| matches!(arg.ty.kind, TyKind::CVarArgs)) } } diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 988918b0505e0..3887e5591eabb 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -57,7 +57,7 @@ impl NestedMetaItem { /// Returns `true` if this list item is a MetaItem with a name of `name`. pub fn has_name(&self, name: Symbol) -> bool { - self.meta_item().map_or(false, |meta_item| meta_item.has_name(name)) + self.meta_item().is_some_and(|meta_item| meta_item.has_name(name)) } /// For a single-segment meta item, returns its name; otherwise, returns `None`. @@ -101,7 +101,7 @@ impl NestedMetaItem { /// Returns `true` if `self` is a `MetaItem` and the meta item is a word. pub fn is_word(&self) -> bool { - self.meta_item().map_or(false, |meta_item| meta_item.is_word()) + self.meta_item().is_some_and(|meta_item| meta_item.is_word()) } /// See [`MetaItem::name_value_literal_span`]. @@ -266,7 +266,7 @@ impl Attribute { } pub fn may_have_doc_links(&self) -> bool { - self.doc_str().map_or(false, |s| comments::may_have_doc_links(s.as_str())) + self.doc_str().is_some_and(|s| comments::may_have_doc_links(s.as_str())) } pub fn get_normal_item(&self) -> &AttrItem { diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 4b94ec0d6d8f4..7a837867b547d 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -13,6 +13,7 @@ #![feature(const_default_impls)] #![feature(const_trait_impl)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(label_break_value)] #![feature(let_chains)] #![feature(min_specialization)] diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 85d9687c600dc..2827ea694c3e5 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -524,7 +524,7 @@ impl Token { /// Returns `true` if the token is an identifier whose name is the given /// string slice. pub fn is_ident_named(&self, name: Symbol) -> bool { - self.ident().map_or(false, |(ident, _)| ident.name == name) + self.ident().is_some_and(|(ident, _)| ident.name == name) } /// Returns `true` if the token is an interpolated path. diff --git a/compiler/rustc_ast/src/util/literal.rs b/compiler/rustc_ast/src/util/literal.rs index 9c18f55c03b4d..fb72d207b4dda 100644 --- a/compiler/rustc_ast/src/util/literal.rs +++ b/compiler/rustc_ast/src/util/literal.rs @@ -329,8 +329,7 @@ fn integer_lit(symbol: Symbol, suffix: Option) -> Result= base)); + let from_lexer = base < 10 && s.chars().any(|c| c.to_digit(10).is_some_and(|d| d >= base)); if from_lexer { LitError::LexerError } else { LitError::IntTooLarge } }) } diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 9e02e7ed3b9cf..1c3628c33ceb9 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -40,7 +40,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } ExprKind::Tup(ref elts) => hir::ExprKind::Tup(self.lower_exprs(elts)), ExprKind::Call(ref f, ref args) => { - if e.attrs.get(0).map_or(false, |a| a.has_name(sym::rustc_box)) { + if e.attrs.get(0).is_some_and(|a| a.has_name(sym::rustc_box)) { if let [inner] = &args[..] && e.attrs.len() == 1 { let kind = hir::ExprKind::Box(self.lower_expr(&inner)); let hir_id = self.lower_node_id(e.id); diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 2dcbd0782ef72..81cd45c2a116c 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -31,6 +31,7 @@ //! in the HIR, especially for multiple identifiers. #![feature(box_patterns)] +#![feature(is_some_with)] #![feature(let_chains)] #![feature(let_else)] #![feature(never_type)] diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index fd2dd6cf6c7f1..95c38540a5a57 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -531,8 +531,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { match i.kind { ast::ForeignItemKind::Fn(..) | ast::ForeignItemKind::Static(..) => { let link_name = self.sess.first_attr_value_str_by_name(&i.attrs, sym::link_name); - let links_to_llvm = - link_name.map_or(false, |val| val.as_str().starts_with("llvm.")); + let links_to_llvm = link_name.is_some_and(|val| val.as_str().starts_with("llvm.")); if links_to_llvm { gate_feature_post!( &self, diff --git a/compiler/rustc_ast_passes/src/lib.rs b/compiler/rustc_ast_passes/src/lib.rs index 9d52c32885db0..1fa48ec6bda5e 100644 --- a/compiler/rustc_ast_passes/src/lib.rs +++ b/compiler/rustc_ast_passes/src/lib.rs @@ -7,6 +7,7 @@ #![allow(rustc::potential_query_instability)] #![feature(box_patterns)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(iter_is_partitioned)] #![feature(let_chains)] #![feature(let_else)] diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 230ccf5199066..01f5a6ecec583 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -87,7 +87,7 @@ impl<'tcx> BorrowExplanation<'tcx> { let path_span = path_span.unwrap(); // path_span is only present in the case of closure capture assert!(matches!(later_use_kind, LaterUseKind::ClosureCapture)); - if !borrow_span.map_or(false, |sp| sp.overlaps(var_or_use_span)) { + if !borrow_span.is_some_and(|sp| sp.overlaps(var_or_use_span)) { let path_label = "used here by closure"; let capture_kind_label = message; err.span_label( @@ -429,7 +429,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { use_location: Location, ) -> bool { let back_edge = self.reach_through_backedge(borrow_location, use_location); - back_edge.map_or(false, |back_edge| self.can_reach_head_of_loop(use_location, back_edge)) + back_edge.is_some_and(|back_edge| self.can_reach_head_of_loop(use_location, back_edge)) } /// Returns the outmost back edge if `from` location can reach `to` location passing through diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 2ed35062da129..eaadbc7fd5218 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -2,6 +2,7 @@ #![allow(rustc::potential_query_instability)] #![feature(box_patterns)] +#![feature(is_some_with)] #![feature(let_chains)] #![feature(let_else)] #![feature(min_specialization)] diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index c81ef10f7c740..050d18296df44 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -155,7 +155,7 @@ impl LivenessValues { /// Returns `true` if the region `r` contains the given element. pub(crate) fn contains(&self, row: N, location: Location) -> bool { let index = self.elements.point_from_location(location); - self.points.row(row).map_or(false, |r| r.contains(index)) + self.points.row(row).is_some_and(|r| r.contains(index)) } /// Returns an iterator of all the elements contained by the region `r` diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index 89b2c329236d4..c023ba9e52bd9 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -118,7 +118,7 @@ impl<'ast> visit::Visitor<'ast> for CfgFinder { self.has_cfg_or_cfg_attr = self.has_cfg_or_cfg_attr || attr .ident() - .map_or(false, |ident| ident.name == sym::cfg || ident.name == sym::cfg_attr); + .is_some_and(|ident| ident.name == sym::cfg || ident.name == sym::cfg_attr); } } diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 11565ba72d755..6b5e3a4d37962 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -7,6 +7,7 @@ #![feature(box_patterns)] #![feature(decl_macro)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(is_sorted)] #![feature(let_chains)] #![feature(let_else)] diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 58f391692c49c..77728774842aa 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -175,7 +175,7 @@ impl CoverageMapGenerator { counter_regions.sort_unstable_by_key(|(_counter, region)| *region); for (counter, region) in counter_regions { let CodeRegion { file_name, start_line, start_col, end_line, end_col } = *region; - let same_file = current_file_name.as_ref().map_or(false, |p| *p == file_name); + let same_file = current_file_name.is_some_and(|p| p == file_name); if !same_file { if current_file_name.is_some() { current_file_id += 1; diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index a7dd8e16d28eb..a7aa3a0ea1455 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -9,6 +9,7 @@ #![feature(let_chains)] #![feature(let_else)] #![feature(extern_types)] +#![feature(is_some_with)] #![feature(once_cell)] #![feature(iter_intersperse)] #![recursion_limit = "256"] diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 4be3ae11e4e5b..1ebedabbf31bf 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -1,5 +1,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(box_patterns)] +#![feature(is_some_with)] #![feature(try_blocks)] #![feature(let_else)] #![feature(once_cell)] diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index b8e3cb32ef633..215f56811f353 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -880,7 +880,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { }); let needs_location = - instance.map_or(false, |i| i.def.requires_caller_location(self.cx.tcx())); + instance.is_some_and(|i| i.def.requires_caller_location(self.cx.tcx())); if needs_location { let mir_args = if let Some(num_untupled) = num_untupled { first_args.len() + num_untupled diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 08102585a7b74..04dc301e1116e 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -555,7 +555,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' if M::enforce_number_no_provenance(self.ecx) { // As a special exception we *do* match on a `Scalar` here, since we truly want // to know its underlying representation (and *not* cast it to an integer). - let is_ptr = value.check_init().map_or(false, |v| matches!(v, Scalar::Ptr(..))); + let is_ptr = value.check_init().is_ok_and(|v| matches!(v, Scalar::Ptr(..))); if is_ptr { throw_validation_failure!(self.path, { "{:x}", value } expected { "plain (non-pointer) bytes" } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 3dcd96df33cf5..540e8e5d51372 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -917,7 +917,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { // have no `rustc_const_stable` attributes to be const-unstable as well. This // should be fixed later. let callee_is_unstable_unmarked = tcx.lookup_const_stability(callee).is_none() - && tcx.lookup_stability(callee).map_or(false, |s| s.is_unstable()); + && tcx.lookup_stability(callee).is_some_and(|s| s.is_unstable()); if callee_is_unstable_unmarked { trace!("callee_is_unstable_unmarked"); // We do not use `const` modifiers for intrinsic "functions", as intrinsics are diff --git a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs index 25b420bed1766..6685c5654b6c9 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs @@ -128,5 +128,5 @@ fn is_parent_const_stable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool { return false; } - tcx.lookup_const_stability(parent.owner).map_or(false, |stab| stab.is_const_stable()) + tcx.lookup_const_stability(parent.owner).is_some_and(|stab| stab.is_const_stable()) } diff --git a/compiler/rustc_const_eval/src/util/call_kind.rs b/compiler/rustc_const_eval/src/util/call_kind.rs index a7a480dd1d790..52f6688ecc817 100644 --- a/compiler/rustc_const_eval/src/util/call_kind.rs +++ b/compiler/rustc_const_eval/src/util/call_kind.rs @@ -135,7 +135,7 @@ pub fn call_kind<'tcx>( ty::Adt(def, ..) => Some(def.did()), _ => None, }); - let is_option_or_result = parent_self_ty.map_or(false, |def_id| { + let is_option_or_result = parent_self_ty.is_some_and(|def_id| { matches!(tcx.get_diagnostic_name(def_id), Some(sym::Option | sym::Result)) }); CallKind::Normal { self_arg, desugaring, is_option_or_result } diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 0a2d2b4070904..988885331df0a 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -16,6 +16,7 @@ #![feature(let_else)] #![feature(hash_raw_entry)] #![feature(hasher_prefixfree_extras)] +#![feature(is_some_with)] #![feature(maybe_uninit_uninit_array)] #![feature(min_specialization)] #![feature(never_type)] diff --git a/compiler/rustc_data_structures/src/obligation_forest/mod.rs b/compiler/rustc_data_structures/src/obligation_forest/mod.rs index 07a96dd7dbbf1..81fba726ced7a 100644 --- a/compiler/rustc_data_structures/src/obligation_forest/mod.rs +++ b/compiler/rustc_data_structures/src/obligation_forest/mod.rs @@ -348,7 +348,7 @@ impl ObligationForest { && self .error_cache .get(&obligation_tree_id) - .map_or(false, |errors| errors.contains(v.key())); + .is_some_and(|errors| errors.contains(v.key())); if already_failed { Err(()) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index b71cdad718a27..c2bd6839cdcfe 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -5,6 +5,7 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(is_some_with)] #![feature(let_else)] #![feature(once_cell)] #![recursion_limit = "256"] @@ -1213,7 +1214,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { } // If backtraces are enabled, also print the query stack - let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0"); + let backtrace = env::var_os("RUST_BACKTRACE").is_some_and(|x| x != "0"); let num_frames = if backtrace { None } else { Some(2) }; diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index ffe4ecebb2e36..1e1630d7e0cb2 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -6,6 +6,7 @@ #![feature(drain_filter)] #![feature(backtrace)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(let_else)] #![feature(never_type)] #![feature(adt_const_params)] @@ -1226,7 +1227,7 @@ impl HandlerInner { fn treat_err_as_bug(&self) -> bool { self.flags .treat_err_as_bug - .map_or(false, |c| self.err_count() + self.lint_err_count >= c.get()) + .is_some_and(|c| self.err_count() + self.lint_err_count >= c.get()) } fn print_error_count(&mut self, registry: &Registry) { @@ -1268,7 +1269,7 @@ impl HandlerInner { .iter() .filter_map(|x| match &x { DiagnosticId::Error(s) - if registry.try_find_description(s).map_or(false, |o| o.is_some()) => + if matches!(registry.try_find_description(s), Ok(Some(_))) => { Some(s.clone()) } @@ -1344,7 +1345,7 @@ impl HandlerInner { // This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before // incrementing `err_count` by one, so we need to +1 the comparing. // FIXME: Would be nice to increment err_count in a more coherent way. - if self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() + 1 >= c.get()) { + if self.flags.treat_err_as_bug.is_some_and(|c| self.err_count() + 1 >= c.get()) { // FIXME: don't abort here if report_delayed_bugs is off self.span_bug(sp, msg); } diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 978f87b1d136e..59d2739e7bd14 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1546,7 +1546,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { cfg_pos = Some(pos); // a cfg attr found, no need to search anymore break; } else if attr_pos.is_none() - && !name.map_or(false, rustc_feature::is_builtin_attr_name) + && !name.is_some_and(|name| rustc_feature::is_builtin_attr_name(name)) { attr_pos = Some(pos); // a non-cfg attr found, still may find a cfg attr } @@ -1594,7 +1594,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span }; span = Some(current_span); - if attrs.peek().map_or(false, |next_attr| next_attr.doc_str().is_some()) { + if attrs.peek().is_some_and(|next_attr| next_attr.doc_str().is_some()) { continue; } @@ -1883,6 +1883,6 @@ impl<'feat> ExpansionConfig<'feat> { } fn proc_macro_hygiene(&self) -> bool { - self.features.map_or(false, |features| features.proc_macro_hygiene) + self.features.is_some_and(|features| features.proc_macro_hygiene) } } diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index c18147592dc70..0d43dfd0d1038 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -3,6 +3,7 @@ #![feature(associated_type_bounds)] #![feature(associated_type_defaults)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(let_chains)] #![feature(let_else)] #![feature(macro_metavar_expr)] diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 6fcdfe44d8f64..74d199e14a7f7 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -806,7 +806,7 @@ pub fn is_builtin_attr_name(name: Symbol) -> bool { } pub fn is_builtin_only_local(name: Symbol) -> bool { - BUILTIN_ATTRIBUTE_MAP.get(&name).map_or(false, |attr| attr.only_local) + BUILTIN_ATTRIBUTE_MAP.get(&name).is_some_and(|attr| attr.only_local) } pub static BUILTIN_ATTRIBUTE_MAP: LazyLock> = diff --git a/compiler/rustc_feature/src/lib.rs b/compiler/rustc_feature/src/lib.rs index efb83052768bc..9bd604ba57049 100644 --- a/compiler/rustc_feature/src/lib.rs +++ b/compiler/rustc_feature/src/lib.rs @@ -12,6 +12,7 @@ //! symbol to the `accepted` or `removed` modules respectively. #![feature(once_cell)] +#![feature(is_some_with)] mod accepted; mod active; @@ -83,12 +84,11 @@ impl UnstableFeatures { // `true` if this is a feature-staged build, i.e., on the beta or stable channel. let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some(); // Returns whether `krate` should be counted as unstable - let is_unstable_crate = |var: &str| { - krate.map_or(false, |name| var.split(',').any(|new_krate| new_krate == name)) - }; + let is_unstable_crate = + |var: &str| krate.is_some_and(|name| var.split(',').any(|new_krate| new_krate == name)); // `true` if we should enable unstable features for bootstrapping. - let bootstrap = std::env::var("RUSTC_BOOTSTRAP") - .map_or(false, |var| var == "1" || is_unstable_crate(&var)); + let bootstrap = + std::env::var("RUSTC_BOOTSTRAP").is_ok_and(|var| var == "1" || is_unstable_crate(&var)); match (disable_unstable_features, bootstrap) { (_, true) => UnstableFeatures::Cheat, (true, _) => UnstableFeatures::Disallow, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 04f585df34cc2..399f011159ac8 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -759,7 +759,7 @@ pub struct WhereBoundPredicate<'hir> { impl<'hir> WhereBoundPredicate<'hir> { /// Returns `true` if `param_def_id` matches the `bounded_ty` of this predicate. pub fn is_param_bound(&self, param_def_id: DefId) -> bool { - self.bounded_ty.as_generic_param().map_or(false, |(def_id, _)| def_id == param_def_id) + self.bounded_ty.as_generic_param().is_some_and(|(def_id, _)| def_id == param_def_id) } } diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 0f9e6fa7b9895..0342b3c5b92d7 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -6,6 +6,7 @@ #![feature(closure_track_caller)] #![feature(const_btree_new)] #![feature(let_else)] +#![feature(is_some_with)] #![feature(once_cell)] #![feature(min_specialization)] #![feature(never_type)] diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index 5b664e19c18c0..37506ca5343be 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -1544,7 +1544,7 @@ impl GrowableBitSet { #[inline] pub fn contains(&self, elem: T) -> bool { let (word_index, mask) = word_index_and_mask(elem); - self.bit_set.words.get(word_index).map_or(false, |word| (word & mask) != 0) + self.bit_set.words.get(word_index).is_some_and(|word| (word & mask) != 0) } #[inline] @@ -1818,7 +1818,7 @@ impl SparseBitMatrix { /// if the matrix represents (transitive) reachability, can /// `row` reach `column`? pub fn contains(&self, row: R, column: C) -> bool { - self.row(row).map_or(false, |r| r.contains(column)) + self.row(row).is_some_and(|r| r.contains(column)) } /// Adds the bits from row `read` to the bits from row `write`, and diff --git a/compiler/rustc_index/src/interval.rs b/compiler/rustc_index/src/interval.rs index 3592fb33077d9..5b5ba5295d404 100644 --- a/compiler/rustc_index/src/interval.rs +++ b/compiler/rustc_index/src/interval.rs @@ -226,7 +226,7 @@ impl IntervalSet { fn check_invariants(&self) -> bool { let mut current: Option = None; for (start, end) in &self.map { - if start > end || current.map_or(false, |x| x + 1 >= *start) { + if start > end || current.is_some_and(|x| x + 1 >= *start) { return false; } current = Some(*end); @@ -300,6 +300,6 @@ impl SparseIntervalMatrix { } pub fn contains(&self, row: R, point: C) -> bool { - self.row(row).map_or(false, |r| r.contains(point)) + self.row(row).is_some_and(|r| r.contains(point)) } } diff --git a/compiler/rustc_index/src/lib.rs b/compiler/rustc_index/src/lib.rs index 33c3c536f119b..3d3e6c88454ed 100644 --- a/compiler/rustc_index/src/lib.rs +++ b/compiler/rustc_index/src/lib.rs @@ -1,6 +1,7 @@ #![feature(allow_internal_unstable)] #![feature(bench_black_box)] #![feature(extend_one)] +#![feature(is_some_with)] #![feature(let_else)] #![feature(min_specialization)] #![feature(new_uninit)] diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 05556f7d0f956..9b53f66588759 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1665,7 +1665,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { (false, _) => "".to_string(), }; if !(values.expected.is_simple_text() && values.found.is_simple_text()) - || (exp_found.map_or(false, |ef| { + || (exp_found.is_some_and(|ef| { // This happens when the type error is a subset of the expectation, // like when you have two references but one is `usize` and the other // is `f32`. In those cases we still want to show the `note`. If the @@ -1710,7 +1710,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let exp_found = match terr { // `terr` has more accurate type information than `exp_found` in match expressions. ty::error::TypeError::Sorts(terr) - if exp_found.map_or(false, |ef| terr.found == ef.found) => + if exp_found.is_some_and(|ef| terr.found == ef.found) => { Some(*terr) } diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 4d29fc469462c..551a8154537a2 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -542,7 +542,8 @@ impl<'tcx> InferSource<'tcx> { receiver.span.from_expansion() } InferSourceKind::ClosureReturn { data, should_wrap_expr, .. } => { - data.span().from_expansion() || should_wrap_expr.map_or(false, Span::from_expansion) + data.span().from_expansion() + || should_wrap_expr.is_some_and(|span| span.from_expansion()) } }; source_from_expansion || self.span.from_expansion() diff --git a/compiler/rustc_infer/src/lib.rs b/compiler/rustc_infer/src/lib.rs index 7769a68ba2a66..60d762c55e246 100644 --- a/compiler/rustc_infer/src/lib.rs +++ b/compiler/rustc_infer/src/lib.rs @@ -17,6 +17,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(extend_one)] +#![feature(is_some_with)] #![feature(label_break_value)] #![feature(let_chains)] #![feature(let_else)] diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index a0472f98d7204..f853ce0543de1 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -593,10 +593,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { let doc_hidden = self.doc_hidden() || attrs.iter().any(|attr| { attr.has_name(sym::doc) - && match attr.meta_item_list() { - None => false, - Some(l) => attr::list_contains_name(&l, sym::hidden), - } + && attr + .meta_item_list() + .is_some_and(|l| attr::list_contains_name(&l, sym::hidden)) }); self.doc_hidden_stack.push(doc_hidden); } @@ -1021,7 +1020,7 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: & Some(sugared_span.map_or(attr.span, |span| span.with_hi(attr.span.hi()))); } - if attrs.peek().map_or(false, |next_attr| next_attr.is_doc_comment()) { + if attrs.peek().is_some_and(|next_attr| next_attr.is_doc_comment()) { continue; } diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index aaee0caa070e7..9791ba0f9fae5 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -31,6 +31,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(iter_intersperse)] #![feature(iter_order_by)] #![feature(let_chains)] diff --git a/compiler/rustc_lint/src/non_fmt_panic.rs b/compiler/rustc_lint/src/non_fmt_panic.rs index cdad2d2e8f93e..7de274e7caf04 100644 --- a/compiler/rustc_lint/src/non_fmt_panic.rs +++ b/compiler/rustc_lint/src/non_fmt_panic.rs @@ -129,7 +129,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc l.emit(); return; } - if arg_macro.map_or(false, |id| cx.tcx.is_diagnostic_item(sym::format_macro, id)) { + if arg_macro.is_some_and(|id| cx.tcx.is_diagnostic_item(sym::format_macro, id)) { // A case of `panic!(format!(..))`. l.note(fluent::lint::supports_fmt_note); if let Some((open, close, _)) = find_delimiters(cx, arg_span) { diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index be4843c7ff153..477e096582261 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -684,7 +684,7 @@ pub fn transparent_newtype_field<'a, 'tcx>( let param_env = tcx.param_env(variant.def_id); variant.fields.iter().find(|field| { let field_ty = tcx.type_of(field.did); - let is_zst = tcx.layout_of(param_env.and(field_ty)).map_or(false, |layout| layout.is_zst()); + let is_zst = tcx.layout_of(param_env.and(field_ty)).is_ok_and(|layout| layout.is_zst()); !is_zst }) } diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 53269d1852703..f7ebad64a2990 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -524,8 +524,8 @@ trait UnusedDelimLint { _ => return, }; let keep_space = ( - left_pos.map_or(false, |s| s >= value.span.lo()), - right_pos.map_or(false, |s| s <= value.span.hi()), + left_pos.is_some_and(|s| s >= value.span.lo()), + right_pos.is_some_and(|s| s <= value.span.hi()), ); self.emit_unused_delims(cx, spans, ctx.into(), keep_space); } diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index cb50c0fb7385f..c8f96d24446ce 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -373,7 +373,7 @@ impl<'a> CrateLoader<'a> { let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash()); let private_dep = - self.sess.opts.externs.get(name.as_str()).map_or(false, |e| e.is_private_dep); + self.sess.opts.externs.get(name.as_str()).is_some_and(|e| e.is_private_dep); // Claim this crate number and cache it let cnum = self.cstore.alloc_new_crate_num(); diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 5ad16398695b2..7671e4bd96df2 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -3,6 +3,7 @@ #![feature(drain_filter)] #![feature(generators)] #![feature(generic_associated_types)] +#![feature(is_some_with)] #![feature(iter_from_generator)] #![feature(let_chains)] #![feature(let_else)] diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index dbe53224e2aaa..810b10ec893d9 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -539,7 +539,7 @@ impl<'a> CrateLocator<'a> { let mut err_data: Option> = None; for (lib, kind) in m { info!("{} reading metadata from: {}", flavor, lib.display()); - if flavor == CrateFlavor::Rmeta && lib.metadata().map_or(false, |m| m.len() == 0) { + if flavor == CrateFlavor::Rmeta && lib.metadata().is_ok_and(|m| m.len() == 0) { // Empty files will cause get_metadata_section to fail. Rmeta // files can be empty, for example with binaries (which can // often appear with `cargo check` when checking a library as @@ -574,7 +574,7 @@ impl<'a> CrateLocator<'a> { } }; // If we see multiple hashes, emit an error about duplicate candidates. - if slot.as_ref().map_or(false, |s| s.0 != hash) { + if slot.as_ref().is_some_and(|s| s.0 != hash) { if let Some(candidates) = err_data { return Err(CrateError::MultipleCandidates( self.crate_name, diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 3e99ba5742a4b..1cb28b8221b58 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -63,10 +63,7 @@ pub fn associated_body<'hir>(node: Node<'hir>) -> Option { } fn is_body_owner<'hir>(node: Node<'hir>, hir_id: HirId) -> bool { - match associated_body(node) { - Some(b) => b.hir_id == hir_id, - None => false, - } + associated_body(node).is_some_and(|b| b.hir_id == hir_id) } #[derive(Copy, Clone)] @@ -410,7 +407,7 @@ impl<'hir> Map<'hir> { /// item (possibly associated), a closure, or a `hir::AnonConst`. pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId { let parent = self.get_parent_node(hir_id); - assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id))); + assert!(self.find(parent).is_some_and(|n| is_body_owner(n, hir_id))); parent } diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 46c34247d4027..fc63251b255e1 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -34,6 +34,7 @@ #![feature(get_mut_unchecked)] #![feature(generic_associated_types)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(map_first_last)] #![feature(negative_impls)] #![feature(never_type)] diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 802b7852bace1..2b966088a7675 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -358,7 +358,7 @@ impl<'tcx> TyCtxt<'tcx> { let parent_def_id = self.hir().get_parent_item(id); let skip = self .lookup_deprecation_entry(parent_def_id.to_def_id()) - .map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry)); + .is_some_and(|parent_depr| parent_depr.same_origin(&depr_entry)); // #[deprecated] doesn't emit a notice if we're not on the // topmost deprecation. For example, if a struct is deprecated, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a594dab2e20a3..0a08ab9633b3c 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2905,7 +2905,7 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn is_late_bound(self, id: HirId) -> bool { - self.is_late_bound_map(id.owner).map_or(false, |set| { + self.is_late_bound_map(id.owner).is_some_and(|set| { let def_id = self.hir().local_def_id(id); set.contains(&def_id) }) @@ -3014,6 +3014,6 @@ pub fn provide(providers: &mut ty::query::Providers) { providers.has_panic_handler = |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); // We want to check if the panic handler was defined in this crate - tcx.lang_items().panic_impl().map_or(false, |did| did.is_local()) + tcx.lang_items().panic_impl().is_some_and(|did| did.is_local()) }; } diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 84547dca45363..408d15fbec9eb 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -260,7 +260,7 @@ impl<'tcx> Generics { .iter() .rev() .take_while(|param| { - param.default_value(tcx).map_or(false, |default| { + param.default_value(tcx).is_some_and(|default| { default.subst(tcx, substs) == substs[param.index as usize] }) }) diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 391abdbe84c5a..29aaf34851396 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -636,7 +636,7 @@ fn polymorphize<'tcx>( } else { None }; - let has_upvars = upvars_ty.map_or(false, |ty| !ty.tuple_fields().is_empty()); + let has_upvars = upvars_ty.is_some_and(|ty| !ty.tuple_fields().is_empty()); debug!("polymorphize: upvars_ty={:?} has_upvars={:?}", upvars_ty, has_upvars); struct PolymorphizationFolder<'tcx> { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index f15108fb7501a..f3067f5f59c5e 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2015,8 +2015,8 @@ impl<'tcx> TyCtxt<'tcx> { ) -> Option { // If either trait impl references an error, they're allowed to overlap, // as one of them essentially doesn't exist. - if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.references_error()) - || self.impl_trait_ref(def_id2).map_or(false, |tr| tr.references_error()) + if self.impl_trait_ref(def_id1).is_some_and(|tr| tr.references_error()) + || self.impl_trait_ref(def_id2).is_some_and(|tr| tr.references_error()) { return Some(ImplOverlapKind::Permitted { marker: false }); } @@ -2046,7 +2046,7 @@ impl<'tcx> TyCtxt<'tcx> { let is_marker_overlap = { let is_marker_impl = |def_id: DefId| -> bool { let trait_ref = self.impl_trait_ref(def_id); - trait_ref.map_or(false, |tr| self.trait_def(tr.def_id).is_marker) + trait_ref.is_some_and(|tr| self.trait_def(tr.def_id).is_marker) }; is_marker_impl(def_id1) && is_marker_impl(def_id2) }; diff --git a/compiler/rustc_mir_build/src/build/block.rs b/compiler/rustc_mir_build/src/build/block.rs index a83328c0cabc6..425d9def13bec 100644 --- a/compiler/rustc_mir_build/src/build/block.rs +++ b/compiler/rustc_mir_build/src/build/block.rs @@ -168,7 +168,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } let popped = this.block_context.pop(); - assert!(popped.map_or(false, |bf| bf.is_statement())); + assert!(popped.is_some_and(|bf| bf.is_statement())); } // Then, the block may have an optional trailing expression which is a “return” value @@ -184,7 +184,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { unpack!(block = this.expr_into_dest(destination, block, expr)); let popped = this.block_context.pop(); - assert!(popped.map_or(false, |bf| bf.is_tail_expr())); + assert!(popped.is_some_and(|bf| bf.is_tail_expr())); } else { // If a block has no trailing expression, then it is given an implicit return type. // This return type is usually `()`, unless the block is diverging, in which case the diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index b9fd8c50e6a04..0decf2bfb7b31 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -324,10 +324,10 @@ impl DropTree { entry_points.sort(); for (drop_idx, drop_data) in self.drops.iter_enumerated().rev() { - if entry_points.last().map_or(false, |entry_point| entry_point.0 == drop_idx) { + if entry_points.last().is_some_and(|entry_point| entry_point.0 == drop_idx) { let block = *blocks[drop_idx].get_or_insert_with(|| T::make_block(cfg)); needs_block[drop_idx] = Block::Own; - while entry_points.last().map_or(false, |entry_point| entry_point.0 == drop_idx) { + while entry_points.last().is_some_and(|entry_point| entry_point.0 == drop_idx) { let entry_block = entry_points.pop().unwrap().1; T::add_entry(cfg, entry_block, block); } @@ -739,7 +739,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn leave_top_scope(&mut self, block: BasicBlock) -> BasicBlock { // If we are emitting a `drop` statement, we need to have the cached // diverge cleanup pads ready in case that drop panics. - let needs_cleanup = self.scopes.scopes.last().map_or(false, |scope| scope.needs_cleanup()); + let needs_cleanup = self.scopes.scopes.last().is_some_and(|scope| scope.needs_cleanup()); let is_generator = self.generator_kind.is_some(); let unwind_to = if needs_cleanup { self.diverge_cleanup() } else { DropIdx::MAX }; diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 94b2722dca86d..cc9d432a60155 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -433,7 +433,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { // To avoid semver hazard, we only consider `Copy` and `ManuallyDrop` non-dropping. if !(assigned_ty .ty_adt_def() - .map_or(false, |adt| adt.is_manually_drop()) + .is_some_and(|adt| adt.is_manually_drop()) || assigned_ty .is_copy_modulo_regions(self.tcx.at(expr.span), self.param_env)) { diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index 11cd2a9aa4dea..2b51bb00257eb 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -5,6 +5,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(let_chains)] #![feature(let_else)] #![feature(min_specialization)] diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 4bc3d216a40d6..f62b6b6646d75 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -898,7 +898,7 @@ impl<'tcx> Cx<'tcx> { let is_upvar = self .tcx .upvars_mentioned(self.body_owner) - .map_or(false, |upvars| upvars.contains_key(&var_hir_id)); + .is_some_and(|upvars| upvars.contains_key(&var_hir_id)); debug!( "convert_var({:?}): is_upvar={}, body_owner={:?}", diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs index 1f73b7da815c5..89491029d0a97 100644 --- a/compiler/rustc_mir_transform/src/check_unsafety.rs +++ b/compiler/rustc_mir_transform/src/check_unsafety.rs @@ -220,9 +220,8 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> { // old value is being dropped. let assigned_ty = place.ty(&self.body.local_decls, self.tcx).ty; // To avoid semver hazard, we only consider `Copy` and `ManuallyDrop` non-dropping. - let manually_drop = assigned_ty - .ty_adt_def() - .map_or(false, |adt_def| adt_def.is_manually_drop()); + let manually_drop = + assigned_ty.ty_adt_def().is_some_and(|adt_def| adt_def.is_manually_drop()); let nodrop = manually_drop || assigned_ty.is_copy_modulo_regions( self.tcx.at(self.source_info.span), diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index fb5423dd157c2..d22541a615007 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -524,7 +524,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let right_size = r.layout.size; let r_bits = r.to_scalar().ok(); let r_bits = r_bits.and_then(|r| r.to_bits(right_size).ok()); - if r_bits.map_or(false, |b| b >= left_size.bits() as u128) { + if r_bits.is_some_and(|b| b >= left_size.bits() as u128) { return None; } } diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 09a5cb8280f35..da401cf87092f 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -592,7 +592,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let right_size = r.layout.size; let r_bits = r.to_scalar().ok(); let r_bits = r_bits.and_then(|r| r.to_bits(right_size).ok()); - if r_bits.map_or(false, |b| b >= left_size.bits() as u128) { + if r_bits.is_some_and(|b| b >= left_size.bits() as u128) { debug!("check_binary_op: reporting assert for {:?}", source_info); self.report_assert_as_lint( lint::builtin::ARITHMETIC_OVERFLOW, diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index 759ea7cd32820..2255de338f025 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -540,7 +540,7 @@ impl TraverseCoverageGraphWithLoops { ); while let Some(next_bcb) = { // Strip contexts with empty worklists from the top of the stack - while self.context_stack.last().map_or(false, |context| context.worklist.is_empty()) { + while self.context_stack.last().is_some_and(|context| context.worklist.is_empty()) { self.context_stack.pop(); } // Pop the next bcb off of the current context_stack. If none, all BCBs were visited. diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 0887775aae5ed..f075f3a069a23 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -1,5 +1,6 @@ #![allow(rustc::potential_query_instability)] #![feature(box_patterns)] +#![feature(is_some_with)] #![feature(let_chains)] #![feature(let_else)] #![feature(map_try_insert)] diff --git a/compiler/rustc_mir_transform/src/nrvo.rs b/compiler/rustc_mir_transform/src/nrvo.rs index bb063915f55a9..d1e86c5fce7ca 100644 --- a/compiler/rustc_mir_transform/src/nrvo.rs +++ b/compiler/rustc_mir_transform/src/nrvo.rs @@ -107,7 +107,7 @@ fn local_eligible_for_nrvo(body: &mut mir::Body<'_>) -> Option { // If multiple different locals are copied to the return place. We can't pick a // single one to rename. - if copied_to_return_place.map_or(false, |old| old != returned_local) { + if copied_to_return_place.is_some_and(|old| old != returned_local) { return None; } diff --git a/compiler/rustc_mir_transform/src/simplify_try.rs b/compiler/rustc_mir_transform/src/simplify_try.rs index fca9f7eeb2461..c7aafe84add25 100644 --- a/compiler/rustc_mir_transform/src/simplify_try.rs +++ b/compiler/rustc_mir_transform/src/simplify_try.rs @@ -115,7 +115,7 @@ fn get_arm_identity_info<'a, 'tcx>( test: impl Fn(&'a Statement<'tcx>) -> bool, mut action: impl FnMut(usize, &'a Statement<'tcx>), ) { - while stmt_iter.peek().map_or(false, |(_, stmt)| test(stmt)) { + while stmt_iter.peek().is_some_and(|(_, stmt)| test(stmt)) { let (idx, stmt) = stmt_iter.next().unwrap(); action(idx, stmt); diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 113af328a91fa..93f5e15d97d96 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -3,6 +3,7 @@ #![feature(array_windows)] #![feature(box_patterns)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(let_chains)] #![feature(let_else)] #![feature(never_type)] diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index 6c750ff428f53..841de0d7af0f0 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -71,7 +71,7 @@ fn has_cfg_or_cfg_attr(attrs: &[Attribute]) -> bool { // Therefore, the absence of a literal `cfg` or `cfg_attr` guarantees that // we don't need to do any eager expansion. attrs.iter().any(|attr| { - attr.ident().map_or(false, |ident| ident.name == sym::cfg || ident.name == sym::cfg_attr) + attr.ident().is_some_and(|ident| ident.name == sym::cfg || ident.name == sym::cfg_attr) }) } diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 63055c56c5c6d..1c9e7119b5a71 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -882,7 +882,7 @@ impl<'a> Parser<'a> { // // `x.foo::>>(3)` let parsed_angle_bracket_args = - segment.args.as_ref().map_or(false, |args| args.is_angle_bracketed()); + segment.args.as_ref().is_some_and(|args| args.is_angle_bracketed()); debug!( "check_trailing_angle_brackets: parsed_angle_bracket_args={:?}", diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 2c43563b10474..37af329f1b1ab 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -872,7 +872,7 @@ impl<'a> Parser<'a> { // If type ascription is "likely an error", the user will already be getting a useful // help message, and doesn't need a second. - if self.last_type_ascription.map_or(false, |last_ascription| last_ascription.1) { + if self.last_type_ascription.is_some_and(|last_ascription| last_ascription.1) { self.maybe_annotate_with_ascription(&mut err, false); } else if let Some(ascription_span) = maybe_ascription_span { let is_nightly = self.sess.unstable_features.is_nightly_build(); @@ -2724,7 +2724,7 @@ impl<'a> Parser<'a> { // We might have a `=>` -> `=` or `->` typo (issue #89396). if TokenKind::FatArrow .similar_tokens() - .map_or(false, |similar_tokens| similar_tokens.contains(&this.token.kind)) + .is_some_and(|similar_tokens| similar_tokens.contains(&this.token.kind)) { err.span_suggestion( this.token.span, diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d0723c68a77e8..a8c281bf94ed5 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1889,7 +1889,7 @@ impl CheckAttrVisitor<'_> { || (is_simd && is_c) || (int_reprs == 1 && is_c - && item.map_or(false, |item| { + && item.is_some_and(|item| { if let ItemLike::Item(item) = item { return is_c_like_enum(item); } @@ -2208,7 +2208,7 @@ impl CheckAttrVisitor<'_> { | sym::feature | sym::repr | sym::target_feature - ) && attr.meta_item_list().map_or(false, |list| list.is_empty()) + ) && attr.meta_item_list().is_some_and(|list| list.is_empty()) { format!( "attribute `{}` with an empty list has no effect", diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index 497c0931c2182..13814e77f6835 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -6,6 +6,7 @@ #![allow(rustc::potential_query_instability)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(is_some_with)] #![feature(iter_intersperse)] #![feature(let_else)] #![feature(let_chains)] diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 12050dceb60a6..e0a4805887ae2 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -532,10 +532,8 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { let is_const = self.tcx.is_const_fn(def_id.to_def_id()) || self.tcx.is_const_trait_impl_raw(def_id.to_def_id()); - let is_stable = self - .tcx - .lookup_stability(def_id) - .map_or(false, |stability| stability.level.is_stable()); + let is_stable = + self.tcx.lookup_stability(def_id).is_some_and(|stability| stability.level.is_stable()); let missing_const_stability_attribute = self.tcx.lookup_const_stability(def_id).is_none(); let is_reachable = self.access_levels.is_reachable(def_id); @@ -746,7 +744,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { // needs to have an error emitted. if features.const_trait_impl && *constness == hir::Constness::Const - && const_stab.map_or(false, |(stab, _)| stab.is_const_stable()) + && const_stab.is_some_and(|(stab, _)| stab.is_const_stable()) { self.tcx .sess @@ -776,7 +774,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { let param_env = self.tcx.param_env(item.def_id); for field in &adt_def.non_enum_variant().fields { let field_ty = field.ty(self.tcx, substs); - if !field_ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop()) + if !field_ty.ty_adt_def().is_some_and(|adt_def| adt_def.is_manually_drop()) && !field_ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), param_env) { if field_ty.needs_drop(self.tcx, param_env) { diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs index 1fa085926767d..5c191d53ea602 100644 --- a/compiler/rustc_query_system/src/ich/impls_syntax.rs +++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs @@ -24,7 +24,7 @@ impl<'a> HashStable> for [ast::Attribute] { .iter() .filter(|attr| { !attr.is_doc_comment() - && !attr.ident().map_or(false, |ident| hcx.is_ignored_attr(ident.name)) + && !attr.ident().is_some_and(|ident| hcx.is_ignored_attr(ident.name)) }) .collect(); @@ -38,7 +38,7 @@ impl<'a> HashStable> for [ast::Attribute] { impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> { fn hash_attr(&mut self, attr: &ast::Attribute, hasher: &mut StableHasher) { // Make sure that these have been filtered out. - debug_assert!(!attr.ident().map_or(false, |ident| self.is_ignored_attr(ident.name))); + debug_assert!(!attr.ident().is_some_and(|ident| self.is_ignored_attr(ident.name))); debug_assert!(!attr.is_doc_comment()); let ast::Attribute { kind, id: _, style, span } = attr; diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index 68284dcaa0be8..47a6604ff06d1 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -1,6 +1,7 @@ #![feature(assert_matches)] #![feature(core_intrinsics)] #![feature(hash_raw_entry)] +#![feature(is_some_with)] #![feature(let_else)] #![feature(min_specialization)] #![feature(extern_types)] diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 9f5779194afcb..55176d329c1a6 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -563,10 +563,10 @@ pub(crate) fn report_cycle<'a>( entry .query .def_kind - .map_or(false, |def_kind| matches!(def_kind, DefKind::TyAlias | DefKind::TraitAlias)) + .is_some_and(|def_kind| matches!(def_kind, DefKind::TyAlias | DefKind::TraitAlias)) }) { if stack.iter().all(|entry| { - entry.query.def_kind.map_or(false, |def_kind| matches!(def_kind, DefKind::TyAlias)) + entry.query.def_kind.is_some_and(|def_kind| matches!(def_kind, DefKind::TyAlias)) }) { err.note("type aliases cannot be recursive"); err.help("consider using a struct, enum, or union instead to break the cycle"); diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 6631470f2191b..a61c0618447df 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -149,7 +149,7 @@ impl<'a> Resolver<'a> { self.cstore().module_expansion_untracked(def_id, &self.session), self.cstore().get_span_untracked(def_id, &self.session), // FIXME: Account for `#[no_implicit_prelude]` attributes. - parent.map_or(false, |module| module.no_implicit_prelude), + parent.is_some_and(|module| module.no_implicit_prelude), )) } _ => None, diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 18ffe9528f565..c08d0b7dbc947 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1946,7 +1946,7 @@ impl<'a> Resolver<'a> { (msg, None) } else if ident.name == kw::SelfUpper { ("`Self` is only available in impls, traits, and type definitions".to_string(), None) - } else if ident.name.as_str().chars().next().map_or(false, |c| c.is_ascii_uppercase()) { + } else if ident.name.as_str().chars().next().is_some_and(|c| c.is_ascii_uppercase()) { // Check whether the name refers to an item in the value namespace. let binding = if let Some(ribs) = ribs { self.resolve_ident_in_lexical_scope( diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 03cb1cfcfc9ef..eccdb42b1be29 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -358,7 +358,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { // The current function has a `self' parameter, but we were unable to resolve // a reference to `self`. This can only happen if the `self` identifier we // are resolving came from a different hygiene context. - if fn_kind.decl().inputs.get(0).map_or(false, |p| p.is_self()) { + if fn_kind.decl().inputs.get(0).is_some_and(|p| p.is_self()) { err.span_label(*span, "this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters"); } else { let doesnt = if is_assoc_fn { @@ -1727,7 +1727,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { } } else { let needs_placeholder = |def_id: DefId, kind: CtorKind| { - let has_no_fields = self.r.field_names.get(&def_id).map_or(false, |f| f.is_empty()); + let has_no_fields = self.r.field_names.get(&def_id).is_some_and(|f| f.is_empty()); match kind { CtorKind::Const => false, CtorKind::Fn | CtorKind::Fictive if has_no_fields => false, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 8968179c92e4b..c0ae573045255 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -10,6 +10,7 @@ #![feature(box_patterns)] #![feature(drain_filter)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(let_chains)] #![feature(let_else)] #![feature(never_type)] @@ -1526,7 +1527,7 @@ impl<'a> Resolver<'a> { } fn is_builtin_macro(&mut self, res: Res) -> bool { - self.get_macro(res).map_or(false, |macro_data| macro_data.ext.builtin_name.is_some()) + self.get_macro(res).is_some_and(|macro_data| macro_data.ext.builtin_name.is_some()) } fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId { diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index 0a0c674d179e9..25d7df642576d 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -1,5 +1,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(let_else)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] @@ -653,7 +654,7 @@ impl<'tcx> SaveContext<'tcx> { ) -> Option { // Returns true if the path is function type sugar, e.g., `Fn(A) -> B`. fn fn_type(seg: &hir::PathSegment<'_>) -> bool { - seg.args.map_or(false, |args| args.parenthesized) + seg.args.is_some_and(|args| args.parenthesized) } let res = self.get_path_res(id); diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index b7da0f229420b..21fa1e832d84d 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1779,7 +1779,7 @@ fn collect_print_requests( error_format: ErrorOutputType, ) -> Vec { let mut prints = Vec::::new(); - if cg.target_cpu.as_ref().map_or(false, |s| s == "help") { + if cg.target_cpu.as_ref().is_some_and(|s| s == "help") { prints.push(PrintRequest::TargetCPUs); cg.target_cpu = None; }; diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 7353c1ca0e208..f543d30614914 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -1,4 +1,5 @@ #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(let_chains)] #![feature(let_else)] #![feature(min_specialization)] diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 1cccef2f64fec..b1005ecfc8d45 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1244,7 +1244,7 @@ pub fn build_session( .map(|&(_, ref level)| *level == lint::Allow) .last() .unwrap_or(false); - let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow); + let cap_lints_allow = sopts.lint_cap.is_some_and(|cap| cap == lint::Allow); let can_emit_warnings = !(warnings_allow || cap_lints_allow); let write_dest = match diagnostics_output { diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index a1f34287a5f36..66a1d845792ed 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -17,6 +17,7 @@ #![feature(array_windows)] #![feature(let_else)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(negative_impls)] #![feature(min_specialization)] #![feature(rustc_attrs)] @@ -709,7 +710,7 @@ impl Span { self.ctxt() .outer_expn_data() .allow_internal_unstable - .map_or(false, |features| features.iter().any(|&f| f == feature)) + .is_some_and(|features| features.iter().any(|&f| f == feature)) } /// Checks if this span arises from a compiler desugaring of kind `kind`. diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index 282ee632ce581..65ed2831289df 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -16,6 +16,7 @@ #![feature(control_flow_enum)] #![feature(drain_filter)] #![feature(hash_drain_filter)] +#![feature(is_some_with)] #![feature(label_break_value)] #![feature(let_chains)] #![feature(let_else)] diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index aa1c91362891b..468ea2bda855e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -181,7 +181,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // 1) strictly implied by another error. // 2) implied by an error with a smaller index. for error2 in error_set { - if error2.index.map_or(false, |index2| is_suppressed[index2]) { + if error2.index.is_some_and(|index2| is_suppressed[index2]) { // Avoid errors being suppressed by already-suppressed // errors, to prevent all errors from being suppressed // at once. diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 33585de600130..bfb99bcea9dc3 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1406,7 +1406,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { "; - let has_dyn = snippet.split_whitespace().next().map_or(false, |s| s == "dyn"); + let has_dyn = snippet.split_whitespace().next().is_some_and(|s| s == "dyn"); let trait_obj = if has_dyn { &snippet[4..] } else { &snippet }; if only_never_return { // No return paths, probably using `panic!()` or similar. @@ -2427,7 +2427,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { "note_obligation_cause_code: check for async fn" ); if is_future - && obligated_types.last().map_or(false, |ty| match ty.kind() { + && obligated_types.last().is_some_and(|ty| match ty.kind() { ty::Opaque(last_def_id, _) => { tcx.parent(*last_def_id) == from_generator } diff --git a/compiler/rustc_trait_selection/src/traits/relationships.rs b/compiler/rustc_trait_selection/src/traits/relationships.rs index 56bdeafeecae4..c98646c85fd25 100644 --- a/compiler/rustc_trait_selection/src/traits/relationships.rs +++ b/compiler/rustc_trait_selection/src/traits/relationships.rs @@ -14,7 +14,7 @@ pub(crate) fn update<'tcx, T>( // (*) binder skipped if let ty::PredicateKind::Trait(tpred) = obligation.predicate.kind().skip_binder() && let Some(ty) = infcx.shallow_resolve(tpred.self_ty()).ty_vid().map(|t| infcx.root_var(t)) - && infcx.tcx.lang_items().sized_trait().map_or(false, |st| st != tpred.trait_ref.def_id) + && infcx.tcx.lang_items().sized_trait().is_some_and(|st| st != tpred.trait_ref.def_id) { let new_self_ty = infcx.tcx.types.unit; diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index b205ca8fa1169..ed4e83d430292 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1564,7 +1564,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()), nested_obligations.into_iter().chain(obligations), ) - .map_or(false, |res| res.may_apply()) + .is_ok_and(|res| res.may_apply()) }); if is_match { diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 0a2b54eec47cd..1081371a24d7b 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -375,7 +375,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { return (tcx.intern_substs(&[]), arg_count); } - let is_object = self_ty.map_or(false, |ty| ty == self.tcx().types.trait_object_dummy_self); + let is_object = self_ty.is_some_and(|ty| ty == self.tcx().types.trait_object_dummy_self); struct SubstsForAstPathCtxt<'a, 'tcx> { astconv: &'a (dyn AstConv<'tcx> + 'a), @@ -3005,7 +3005,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .. }) = tcx.hir().get_by_def_id(parent_id) && self_ty.hir_id == impl_self_ty.hir_id { - if !of_trait_ref.trait_def_id().map_or(false, |def_id| def_id.is_local()) { + if !of_trait_ref.trait_def_id().is_some_and(|def_id| def_id.is_local()) { return; } let of_trait_span = of_trait_ref.path.span; @@ -3043,8 +3043,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .sess .source_map() .span_to_prev_source(self_ty.span) - .ok() - .map_or(false, |s| s.trim_end().ends_with('<')); + .is_ok_and(|s| s.trim_end().ends_with('<')); let is_global = poly_trait_ref.trait_ref.path.is_global(); let sugg = Vec::from_iter([ diff --git a/compiler/rustc_typeck/src/check/cast.rs b/compiler/rustc_typeck/src/check/cast.rs index 66dd558249052..b6ac43dd32ef6 100644 --- a/compiler/rustc_typeck/src/check/cast.rs +++ b/compiler/rustc_typeck/src/check/cast.rs @@ -455,7 +455,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { .sess .source_map() .span_to_snippet(self.expr_span) - .map_or(false, |snip| snip.starts_with('(')); + .is_ok_and(|snip| snip.starts_with('(')); // Very crude check to see whether the expression must be wrapped // in parentheses for the suggestion to work (issue #89497). diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index e9709b64d930e..5da82f4f2163d 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -1067,7 +1067,7 @@ fn check_impl_items_against_trait<'tcx>( for &trait_item_id in tcx.associated_item_def_ids(impl_trait_ref.def_id) { let is_implemented = ancestors .leaf_def(tcx, trait_item_id) - .map_or(false, |node_item| node_item.item.defaultness.has_value()); + .is_some_and(|node_item| node_item.item.defaultness.has_value()); if !is_implemented && tcx.impl_defaultness(impl_id).is_final() { missing_items.push(tcx.associated_item(trait_item_id)); @@ -1077,7 +1077,7 @@ fn check_impl_items_against_trait<'tcx>( // true if this item is specifically implemented in this impl let is_implemented_here = ancestors .leaf_def(tcx, trait_item_id) - .map_or(false, |node_item| !node_item.defining_node.is_from_trait()); + .is_some_and(|node_item| !node_item.defining_node.is_from_trait()); if is_implemented_here { let trait_item = tcx.associated_item(trait_item_id); @@ -1325,8 +1325,8 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD let layout = tcx.layout_of(param_env.and(ty)); // We are currently checking the type this field came from, so it must be local let span = tcx.hir().span_if_local(field.did).unwrap(); - let zst = layout.map_or(false, |layout| layout.is_zst()); - let align1 = layout.map_or(false, |layout| layout.align.abi.bytes() == 1); + let zst = layout.is_ok_and(|layout| layout.is_zst()); + let align1 = layout.is_ok_and(|layout| layout.align.abi.bytes() == 1); (span, zst, align1) }); diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index acd7e4a92dcc9..f70cfd75bdf1c 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -1684,7 +1684,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { .span_to_snippet(return_sp) .unwrap_or_else(|_| "dyn Trait".to_string()); let mut snippet_iter = snippet.split_whitespace(); - let has_impl = snippet_iter.next().map_or(false, |s| s == "impl"); + let has_impl = snippet_iter.next().is_some_and(|s| s == "impl"); // Only suggest `Box` if `Trait` in `impl Trait` is object safe. let mut is_object_safe = false; if let hir::FnRetTy::Return(ty) = fn_output @@ -1704,9 +1704,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { bound .trait_ref() .and_then(|t| t.trait_def_id()) - .map_or(false, |def_id| { - fcx.tcx.object_safety_violations(def_id).is_empty() - }) + .is_some_and(|def_id| fcx.tcx.object_safety_violations(def_id).is_empty()) }) } }; diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 45ea04f234288..bf3118ec4f65b 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -498,7 +498,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .borrow() .adjustments() .get(base.hir_id) - .map_or(false, |x| x.iter().any(|adj| matches!(adj.kind, Adjust::Deref(_)))) + .is_some_and(|x| x.iter().any(|adj| matches!(adj.kind, Adjust::Deref(_)))) }); if !is_named { self.tcx.sess.emit_err(AddressOfTemporaryTaken { span: oprnd.span }); diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index cf7de1dc016c8..60ad5d71bcb14 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -436,7 +436,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { traits::BinOp { rhs_span: opt_input_expr.map(|expr| expr.span), is_lit: opt_input_expr - .map_or(false, |expr| matches!(expr.kind, ExprKind::Lit(_))), + .is_some_and(|expr| matches!(expr.kind, ExprKind::Lit(_))), }, ), self.param_env, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 1794446e92aa5..26b3031d5035f 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -1680,7 +1680,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // within one of the args. if arg.span.contains(error.obligation.cause.span) { let references_arg = - typeck_results.expr_ty_opt(arg).map_or(false, &ty_matches_self) + typeck_results.expr_ty_opt(arg).is_some_and(|ty| ty_matches_self(ty)) || expected_tys.get(idx).copied().map_or(false, &ty_matches_self); if references_arg && !arg.span.from_expansion() { error.obligation.cause.map_code(|parent_code| { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 863a981134f24..a86ab251127b9 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -832,8 +832,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let results = self.typeck_results.borrow(); // First, look for a `Clone::clone` call if segment.ident.name == sym::clone - && results.type_dependent_def_id(expr.hir_id).map_or( - false, + && results.type_dependent_def_id(expr.hir_id).is_some_and( |did| { self.tcx.associated_item(did).container == ty::AssocItemContainer::TraitContainer(clone_trait_did) diff --git a/compiler/rustc_typeck/src/check/generator_interior/drop_ranges.rs b/compiler/rustc_typeck/src/check/generator_interior/drop_ranges.rs index 887c791af76c2..2d52e74d20af3 100644 --- a/compiler/rustc_typeck/src/check/generator_interior/drop_ranges.rs +++ b/compiler/rustc_typeck/src/check/generator_interior/drop_ranges.rs @@ -195,8 +195,7 @@ impl DropRanges { self.tracked_value_map .get(&TrackedValue::Temporary(hir_id)) .or(self.tracked_value_map.get(&TrackedValue::Variable(hir_id))) - .cloned() - .map_or(false, |tracked_value_id| { + .is_some_and(|&tracked_value_id| { self.expect_node(location.into()).drop_state.contains(tracked_value_id) }) } diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index e29f0275bf48d..f4197600b296d 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -346,7 +346,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { traits::BinOp { rhs_span: opt_input_expr.map(|expr| expr.span), is_lit: opt_input_expr - .map_or(false, |expr| matches!(expr.kind, hir::ExprKind::Lit(_))), + .is_some_and(|expr| matches!(expr.kind, hir::ExprKind::Lit(_))), }, ), self.param_env, @@ -503,7 +503,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { traits::BinOp { rhs_span: opt_input_expr.map(|expr| expr.span), is_lit: opt_input_expr - .map_or(false, |expr| matches!(expr.kind, hir::ExprKind::Lit(_))), + .is_some_and(|expr| matches!(expr.kind, hir::ExprKind::Lit(_))), }, ) } else { diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index e9b91414a07ab..f9715ae3e9032 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1162,7 +1162,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { pick.autoderefs += 1; pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref { mutbl, - unsize: pick.autoref_or_ptr_adjustment.map_or(false, |a| a.get_unsize()), + unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()), }) } diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 7bf167426f748..b4a1fb2eb631d 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -1833,7 +1833,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // implement the `AsRef` trait. let skip = skippable.contains(&did) || (("Pin::new" == *pre) && (sym::as_ref == item_name.name)) - || inputs_len.map_or(false, |inputs_len| pick.item.kind == ty::AssocKind::Fn && self.tcx.fn_sig(pick.item.def_id).skip_binder().inputs().len() != inputs_len); + || inputs_len.is_some_and(|inputs_len| pick.item.kind == ty::AssocKind::Fn && self.tcx.fn_sig(pick.item.def_id).skip_binder().inputs().len() != inputs_len); // Make sure the method is defined for the *actual* receiver: we don't // want to treat `Box` as a receiver if it only works because of // an autoderef to `&self` @@ -1911,18 +1911,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::TraitFn::Required([ident, ..]) => { ident.name == kw::SelfLower } - hir::TraitFn::Provided(body_id) => { - self.tcx.hir().body(*body_id).params.first().map_or( - false, - |param| { - matches!( - param.pat.kind, - hir::PatKind::Binding(_, _, ident, _) - if ident.name == kw::SelfLower - ) - }, - ) - } + hir::TraitFn::Provided(body_id) => self + .tcx + .hir() + .body(*body_id) + .params + .first() + .is_some_and(|param| { + matches!( + param.pat.kind, + hir::PatKind::Binding(_, _, ident, _) + if ident.name == kw::SelfLower + ) + }), _ => false, }; @@ -2089,7 +2090,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let imp = self.tcx.impl_trait_ref(imp_did).unwrap(); let imp_simp = simplify_type(self.tcx, imp.self_ty(), TreatParams::AsPlaceholder); - imp_simp.map_or(false, |s| s == simp_rcvr_ty) + imp_simp.is_some_and(|s| s == simp_rcvr_ty) }) { explicitly_negative.push(candidate); @@ -2170,7 +2171,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match ty.kind() { ty::Adt(def, _) => def.did().is_local(), ty::Foreign(did) => did.is_local(), - ty::Dynamic(tr, ..) => tr.principal().map_or(false, |d| d.def_id().is_local()), + ty::Dynamic(tr, ..) => tr.principal().is_some_and(|d| d.def_id().is_local()), ty::Param(_) => true, // Everything else (primitive types, etc.) is effectively diff --git a/compiler/rustc_typeck/src/check/place_op.rs b/compiler/rustc_typeck/src/check/place_op.rs index 2e0f37eba232d..b8ae9c1cafd45 100644 --- a/compiler/rustc_typeck/src/check/place_op.rs +++ b/compiler/rustc_typeck/src/check/place_op.rs @@ -328,7 +328,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514). // This helps avoid accidental drops. if inside_union - && source.ty_adt_def().map_or(false, |adt| adt.is_manually_drop()) + && source.ty_adt_def().is_some_and(|adt| adt.is_manually_drop()) { let mut err = self.tcx.sess.struct_span_err( expr.span, diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index f93f567fb2054..5439cef70598c 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -130,7 +130,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) { hir::ItemKind::Impl(ref impl_) => { let is_auto = tcx .impl_trait_ref(item.def_id) - .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id)); + .is_some_and(|trait_ref| tcx.trait_is_auto(trait_ref.def_id)); if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) { let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span); let mut err = diff --git a/compiler/rustc_typeck/src/check_unused.rs b/compiler/rustc_typeck/src/check_unused.rs index 4a3cfa1ca376a..e46342975ddb3 100644 --- a/compiler/rustc_typeck/src/check_unused.rs +++ b/compiler/rustc_typeck/src/check_unused.rs @@ -140,7 +140,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { // If the extern crate isn't in the extern prelude, // there is no way it can be written as a `use`. let orig_name = extern_crate.orig_name.unwrap_or(item.ident.name); - if !extern_prelude.get(&orig_name).map_or(false, |from_item| !from_item) { + if !extern_prelude.get(&orig_name).is_some_and(|from_item| !from_item) { continue; } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 44b9c8392f86b..bd87510078922 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -982,7 +982,7 @@ fn convert_variant( parent_did.to_def_id(), recovered, adt_kind == AdtKind::Struct && tcx.has_attr(parent_did.to_def_id(), sym::non_exhaustive) - || variant_did.map_or(false, |variant_did| { + || variant_did.is_some_and(|variant_did| { tcx.has_attr(variant_did.to_def_id(), sym::non_exhaustive) }), ) @@ -1795,7 +1795,7 @@ fn is_suggestable_infer_ty(ty: &hir::Ty<'_>) -> bool { is_suggestable_infer_ty(ty) || are_suggestable_generic_args(segment.args().args) } Path(hir::QPath::Resolved(ty_opt, hir::Path { segments, .. })) => { - ty_opt.map_or(false, is_suggestable_infer_ty) + ty_opt.is_some_and(|ty| is_suggestable_infer_ty(ty)) || segments.iter().any(|segment| are_suggestable_generic_args(segment.args().args)) } _ => false, diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 08c194ec0b605..cdd4974e63115 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -62,6 +62,7 @@ This API is completely unstable and subject to change. #![feature(drain_filter)] #![feature(hash_drain_filter)] #![feature(if_let_guard)] +#![feature(is_some_with)] #![feature(is_sorted)] #![feature(iter_intersperse)] #![feature(label_break_value)] diff --git a/compiler/rustc_typeck/src/mem_categorization.rs b/compiler/rustc_typeck/src/mem_categorization.rs index ced919f66db41..f7452c5ed5862 100644 --- a/compiler/rustc_typeck/src/mem_categorization.rs +++ b/compiler/rustc_typeck/src/mem_categorization.rs @@ -413,7 +413,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { } Res::Local(var_id) => { - if self.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) { + if self.upvars.is_some_and(|upvars| upvars.contains_key(&var_id)) { self.cat_upvar(hir_id, var_id) } else { Ok(PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Local(var_id), Vec::new())) diff --git a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs index 72a32dade4eef..cc0cf7ee3f494 100644 --- a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs @@ -370,7 +370,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { ) -> String { let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(fn_sig); let is_used_in_input = |def_id| { - fn_sig.map_or(false, |fn_sig| { + fn_sig.is_some_and(|fn_sig| { fn_sig.decl.inputs.iter().any(|ty| match ty.kind { hir::TyKind::Path(hir::QPath::Resolved( None, diff --git a/library/core/src/option.rs b/library/core/src/option.rs index bca73cb770fbb..159810aa48bee 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -562,19 +562,22 @@ impl Option { /// #![feature(is_some_with)] /// /// let x: Option = Some(2); - /// assert_eq!(x.is_some_and(|&x| x > 1), true); + /// assert_eq!(x.is_some_and(|x| x > 1), true); /// /// let x: Option = Some(0); - /// assert_eq!(x.is_some_and(|&x| x > 1), false); + /// assert_eq!(x.is_some_and(|x| x > 1), false); /// /// let x: Option = None; - /// assert_eq!(x.is_some_and(|&x| x > 1), false); + /// assert_eq!(x.is_some_and(|x| x > 1), false); /// ``` #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_some_and(&self, f: impl FnOnce(&T) -> bool) -> bool { - matches!(self, Some(x) if f(x)) + pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool { + match self { + None => false, + Some(x) => f(x), + } } /// Returns `true` if the option is a [`None`] value. diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 8a68cdf7d651b..4a0b726f83b31 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -551,19 +551,22 @@ impl Result { /// #![feature(is_some_with)] /// /// let x: Result = Ok(2); - /// assert_eq!(x.is_ok_and(|&x| x > 1), true); + /// assert_eq!(x.is_ok_and(|x| x > 1), true); /// /// let x: Result = Ok(0); - /// assert_eq!(x.is_ok_and(|&x| x > 1), false); + /// assert_eq!(x.is_ok_and(|x| x > 1), false); /// /// let x: Result = Err("hey"); - /// assert_eq!(x.is_ok_and(|&x| x > 1), false); + /// assert_eq!(x.is_ok_and(|x| x > 1), false); /// ``` #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool { - matches!(self, Ok(x) if f(x)) + pub fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool { + match self { + Err(_) => false, + Ok(x) => f(x), + } } /// Returns `true` if the result is [`Err`]. @@ -607,8 +610,11 @@ impl Result { #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool { - matches!(self, Err(x) if f(x)) + pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool { + match self { + Ok(_) => false, + Err(e) => f(e), + } } ///////////////////////////////////////////////////////////////////////// diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 81aa8c6cf8e19..8574734895161 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -559,7 +559,7 @@ impl Item { } pub(crate) fn is_crate(&self) -> bool { - self.is_mod() && self.item_id.as_def_id().map_or(false, |did| did.is_crate_root()) + self.is_mod() && self.item_id.as_def_id().is_some_and(|did| did.is_crate_root()) } pub(crate) fn is_mod(&self) -> bool { self.type_() == ItemType::Module @@ -2359,7 +2359,7 @@ impl ConstantKind { pub(crate) fn is_literal(&self, tcx: TyCtxt<'_>) -> bool { match *self { ConstantKind::TyConst { .. } => false, - ConstantKind::Extern { def_id } => def_id.as_local().map_or(false, |def_id| { + ConstantKind::Extern { def_id } => def_id.as_local().is_some_and(|def_id| { is_literal_expr(tcx, tcx.hir().local_def_id_to_hir_id(def_id)) }), ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => { diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 22b1e2335fd84..48d8ef29b42c6 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -557,9 +557,8 @@ pub(crate) fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Opti /// This function exists because it runs on `hir::Attributes` whereas the other is a /// `clean::Attributes` method. pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool { - tcx.get_attrs(did, sym::doc).any(|attr| { - attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag)) - }) + tcx.get_attrs(did, sym::doc) + .any(|attr| attr.meta_item_list().is_some_and(|l| rustc_attr::list_contains_name(&l, flag))) } /// A link to `doc.rust-lang.org` that includes the channel name. Use this instead of manual links diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 272188f82994c..1029292b2ed7b 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -772,7 +772,7 @@ impl Options { /// Returns `true` if the file given as `self.input` is a Markdown file. pub(crate) fn markdown_input(&self) -> bool { - self.input.extension().map_or(false, |e| e == "md" || e == "markdown") + self.input.extension().is_some_and(|e| e == "md" || e == "markdown") } } diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index d7276a427c468..aed9662fc77fc 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -213,10 +213,10 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { if self.cache.masked_crates.contains(&item.item_id.krate()) || i.trait_ .as_ref() - .map_or(false, |t| self.cache.masked_crates.contains(&t.def_id().krate)) + .is_some_and(|t| self.cache.masked_crates.contains(&t.def_id().krate)) || i.for_ .def_id(self.cache) - .map_or(false, |d| self.cache.masked_crates.contains(&d.krate)) + .is_some_and(|d| self.cache.masked_crates.contains(&d.krate)) { return None; } @@ -317,7 +317,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { // A crate has a module at its root, containing all items, // which should not be indexed. The crate-item itself is // inserted later on when serializing the search-index. - if item.item_id.as_def_id().map_or(false, |idx| !idx.is_crate_root()) { + if item.item_id.as_def_id().is_some_and(|idx| !idx.is_crate_root()) { let desc = item.doc_value().map_or_else(String::new, |x| { short_markdown_summary(x.as_str(), &item.link_names(self.cache)) }); diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 459b0fed6e872..47b50a99de9ce 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1229,7 +1229,7 @@ fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String { if let Some(trait_) = &impl_.trait_ { let trait_did = trait_.def_id(); - if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable) { + if cx.cache().traits.get(&trait_did).is_some_and(|t| t.is_notable) { if out.is_empty() { write!( &mut out, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 0d3ec7ecb6448..71d98fbfbf369 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -9,6 +9,7 @@ #![feature(control_flow_enum)] #![feature(box_syntax)] #![feature(drain_filter)] +#![feature(is_some_with)] #![feature(let_chains)] #![feature(let_else)] #![feature(test)] diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 6ea33d763b185..ffcd097071b15 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -191,7 +191,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> cleaner.keep_impl( for_, trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait(), - ) || trait_.as_ref().map_or(false, |t| cleaner.keep_impl_with_def_id(t.def_id().into())) + ) || trait_.as_ref().is_some_and(|t| cleaner.keep_impl_with_def_id(t.def_id().into())) || kind.is_blanket() } else { true diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index f01ec38665c01..5b19d66fdd669 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -55,7 +55,7 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> { for item in self.tcx.module_children(def_id).iter() { if let Some(def_id) = item.res.opt_def_id() { - if self.tcx.def_key(def_id).parent.map_or(false, |d| d == def_id.index) + if self.tcx.def_key(def_id).parent.is_some_and(|d| d == def_id.index) || item.vis.is_public() { self.visit_item(item.res); diff --git a/src/tools/clippy/book/src/development/common_tools_writing_lints.md b/src/tools/clippy/book/src/development/common_tools_writing_lints.md index e1ed89262f677..ce026e6934890 100644 --- a/src/tools/clippy/book/src/development/common_tools_writing_lints.md +++ b/src/tools/clippy/book/src/development/common_tools_writing_lints.md @@ -140,7 +140,7 @@ impl LateLintPass<'_> for MyStructLint { // we are looking for the `DefId` of `Drop` trait in lang items .drop_trait() // then we use it with our type `ty` by calling `implements_trait` from Clippy's utils - .map_or(false, |id| implements_trait(cx, ty, id, &[])) { + .is_some_and(|id| implements_trait(cx, ty, id, &[])) { // `expr` implements `Drop` trait } diff --git a/src/tools/clippy/clippy_dev/src/bless.rs b/src/tools/clippy/clippy_dev/src/bless.rs index f5c51b9474fcd..c5e980f935c49 100644 --- a/src/tools/clippy/clippy_dev/src/bless.rs +++ b/src/tools/clippy/clippy_dev/src/bless.rs @@ -20,7 +20,7 @@ pub fn bless(ignore_timestamp: bool) { WalkDir::new(build_dir()) .into_iter() .map(Result::unwrap) - .filter(|entry| entry.path().extension().map_or(false, |ext| extensions.contains(&ext))) + .filter(|entry| entry.path().extension().is_some_and(|ext| extensions.contains(&ext))) .for_each(|entry| update_reference_file(&entry, ignore_timestamp)); } diff --git a/src/tools/clippy/clippy_dev/src/setup/vscode.rs b/src/tools/clippy/clippy_dev/src/setup/vscode.rs index d59001b2c66af..032e4c016addb 100644 --- a/src/tools/clippy/clippy_dev/src/setup/vscode.rs +++ b/src/tools/clippy/clippy_dev/src/setup/vscode.rs @@ -93,7 +93,7 @@ fn delete_vs_task_file(path: &Path) -> bool { /// It may fail silently. fn try_delete_vs_directory_if_empty() { let path = Path::new(VSCODE_DIR); - if path.read_dir().map_or(false, |mut iter| iter.next().is_none()) { + if path.read_dir().is_some_and(|mut iter| iter.next().is_none()) { // The directory is empty. We just try to delete it but allow a silence // fail as an empty `.vscode` directory is still valid let _silence_result = fs::remove_dir(path); diff --git a/src/tools/clippy/clippy_lints/src/attrs.rs b/src/tools/clippy/clippy_lints/src/attrs.rs index 4bcbeacf9feb5..d26d10d136628 100644 --- a/src/tools/clippy/clippy_lints/src/attrs.rs +++ b/src/tools/clippy/clippy_lints/src/attrs.rs @@ -343,7 +343,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { return; } if let Some(lint_list) = &attr.meta_item_list() { - if attr.ident().map_or(false, |ident| is_lint_level(ident.name)) { + if attr.ident().is_some_and(|ident| is_lint_level(ident.name)) { for lint in lint_list { match item.kind { ItemKind::Use(..) => { @@ -351,7 +351,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { || is_word(lint, sym::deprecated) || is_word(lint, sym!(unreachable_pub)) || is_word(lint, sym!(unused)) - || extract_clippy_lint(lint).map_or(false, |s| { + || extract_clippy_lint(lint).is_some_and(|s| { matches!( s.as_str(), "wildcard_imports" @@ -503,7 +503,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_ block .expr .as_ref() - .map_or(false, |e| is_relevant_expr(cx, typeck_results, e)), + .is_some_and(|e| is_relevant_expr(cx, typeck_results, e)), |stmt| match &stmt.kind { StmtKind::Local(_) => true, StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr), @@ -513,7 +513,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_ } fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, expr: &Expr<'_>) -> bool { - if macro_backtrace(expr.span).last().map_or(false, |macro_call| { + if macro_backtrace(expr.span).last().is_some_and(|macro_call| { is_panic(cx, macro_call.def_id) || cx.tcx.item_name(macro_call.def_id) == sym::unreachable }) { return false; diff --git a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs index 95abe8aa59fbe..0d12689b7aa9a 100644 --- a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs +++ b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs @@ -58,7 +58,7 @@ fn is_impl_not_trait_with_bool_out(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { trait_id, ) }) - .map_or(false, |assoc_item| { + .is_some_and(|assoc_item| { let proj = cx.tcx.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(ty, &[])); let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj); diff --git a/src/tools/clippy/clippy_lints/src/booleans.rs b/src/tools/clippy/clippy_lints/src/booleans.rs index 526ee2f891a16..e8b53198784ce 100644 --- a/src/tools/clippy/clippy_lints/src/booleans.rs +++ b/src/tools/clippy/clippy_lints/src/booleans.rs @@ -484,7 +484,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); - get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])) + get_trait_def_id(cx, &paths::ORD).is_some_and(|id| implements_trait(cx, ty, id, &[])) } struct NotSimplificationVisitor<'a, 'tcx> { diff --git a/src/tools/clippy/clippy_lints/src/comparison_chain.rs b/src/tools/clippy/clippy_lints/src/comparison_chain.rs index a05b41eb3ab52..8034f0856a85d 100644 --- a/src/tools/clippy/clippy_lints/src/comparison_chain.rs +++ b/src/tools/clippy/clippy_lints/src/comparison_chain.rs @@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain { // Check that the type being compared implements `core::cmp::Ord` let ty = cx.typeck_results().expr_ty(lhs1); - let is_ord = get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])); + let is_ord = get_trait_def_id(cx, &paths::ORD).is_some_and(|id| implements_trait(cx, ty, id, &[])); if !is_ord { return; diff --git a/src/tools/clippy/clippy_lints/src/copies.rs b/src/tools/clippy/clippy_lints/src/copies.rs index 1deff9684a140..8eb901ff8b68a 100644 --- a/src/tools/clippy/clippy_lints/src/copies.rs +++ b/src/tools/clippy/clippy_lints/src/copies.rs @@ -247,7 +247,7 @@ fn lint_branches_sharing_code<'tcx>( let span = span.with_hi(last_block.span.hi()); // Improve formatting if the inner block has indention (i.e. normal Rust formatting) let test_span = Span::new(span.lo() - BytePos(4), span.lo(), span.ctxt(), span.parent()); - let span = if snippet_opt(cx, test_span).map_or(false, |snip| snip == " ") { + let span = if snippet_opt(cx, test_span).is_some_and(|snip| snip == " ") { span.with_lo(test_span.lo()) } else { span @@ -357,12 +357,10 @@ fn eq_stmts( let new_bindings = &moved_bindings[old_count..]; blocks .iter() - .all(|b| get_stmt(b).map_or(false, |s| eq_binding_names(s, new_bindings))) + .all(|b| get_stmt(b).is_some_and(|s| eq_binding_names(s, new_bindings))) } else { true - }) && blocks - .iter() - .all(|b| get_stmt(b).map_or(false, |s| eq.eq_stmt(s, stmt))) + }) && blocks.iter().all(|b| get_stmt(b).is_some_and(|s| eq.eq_stmt(s, stmt))) } fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<'_>, blocks: &[&Block<'_>]) -> BlockEq { @@ -447,7 +445,7 @@ fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<' }); if let Some(e) = block.expr { for block in blocks { - if block.expr.map_or(false, |expr| !eq.eq_expr(expr, e)) { + if block.expr.is_some_and(|expr| !eq.eq_expr(expr, e)) { moved_locals.truncate(moved_locals_at_start); return BlockEq { start_end_eq, @@ -466,7 +464,7 @@ fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<' } fn check_for_warn_of_moved_symbol(cx: &LateContext<'_>, symbols: &[(HirId, Symbol)], if_expr: &Expr<'_>) -> bool { - get_enclosing_block(cx, if_expr.hir_id).map_or(false, |block| { + get_enclosing_block(cx, if_expr.hir_id).is_some_and(|block| { let ignore_span = block.span.shrink_to_lo().to(if_expr.span); symbols diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index 28f218a8e344f..3b457050aa8cb 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -352,7 +352,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h // there's a Copy impl for any instance of the adt. if !is_copy(cx, ty) { if ty_subs.non_erasable_generics().next().is_some() { - let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).map_or(false, |impls| { + let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).is_some_and(|impls| { impls .iter() .any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())) diff --git a/src/tools/clippy/clippy_lints/src/duplicate_mod.rs b/src/tools/clippy/clippy_lints/src/duplicate_mod.rs index 4f49bb879f503..4c1a63cb2a83b 100644 --- a/src/tools/clippy/clippy_lints/src/duplicate_mod.rs +++ b/src/tools/clippy/clippy_lints/src/duplicate_mod.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Crate, Inline, Item, ItemKind, ModKind}; use rustc_errors::MultiSpan; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext, Level}; +use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{FileName, Span}; use std::collections::BTreeMap; @@ -79,21 +79,29 @@ impl EarlyLintPass for DuplicateMod { } fn check_crate_post(&mut self, cx: &EarlyContext<'_>, _: &Crate) { - for Modules { local_path, spans, lint_levels } in self.modules.values() { + for Modules { + local_path, + spans, + lint_levels, + } in self.modules.values() + { if spans.len() < 2 { continue; } // At this point the lint would be emitted assert_eq!(spans.len(), lint_levels.len()); - let spans: Vec<_> = spans.into_iter().zip(lint_levels).filter_map(|(span, lvl)|{ - if let Some(id) = lvl.get_expectation_id() { - cx.fulfill_expectation(id); - } + let spans: Vec<_> = spans + .into_iter() + .zip(lint_levels) + .filter_map(|(span, lvl)| { + if let Some(id) = lvl.get_expectation_id() { + cx.fulfill_expectation(id); + } - (!matches!(lvl, Level::Allow | Level::Expect(_))).then_some(*span) - }) - .collect(); + (!matches!(lvl, Level::Allow | Level::Expect(_))).then_some(*span) + }) + .collect(); if spans.len() < 2 { continue; diff --git a/src/tools/clippy/clippy_lints/src/enum_variants.rs b/src/tools/clippy/clippy_lints/src/enum_variants.rs index cd36f9fcd729e..47949d1f46053 100644 --- a/src/tools/clippy/clippy_lints/src/enum_variants.rs +++ b/src/tools/clippy/clippy_lints/src/enum_variants.rs @@ -132,8 +132,8 @@ fn check_enum_start(cx: &LateContext<'_>, item_name: &str, variant: &Variant<'_> let item_name_chars = item_name.chars().count(); if count_match_start(item_name, name).char_count == item_name_chars - && name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase()) - && name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric()) + && name.chars().nth(item_name_chars).is_some_and(|c| !c.is_lowercase()) + && name.chars().nth(item_name_chars + 1).is_some_and(|c| !c.is_numeric()) { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/eta_reduction.rs b/src/tools/clippy/clippy_lints/src/eta_reduction.rs index 42fac550ec69c..126b49003377e 100644 --- a/src/tools/clippy/clippy_lints/src/eta_reduction.rs +++ b/src/tools/clippy/clippy_lints/src/eta_reduction.rs @@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction { if_chain! { if let ty::Closure(_, substs) = callee_ty.peel_refs().kind(); if substs.as_closure().kind() == ClosureKind::FnMut; - if path_to_local(callee).map_or(false, |l| local_used_after_expr(cx, l, expr)); + if path_to_local(callee).is_some_and(|l| local_used_after_expr(cx, l, expr)); then { // Mutable closure is used after current expr; we cannot consume it. diff --git a/src/tools/clippy/clippy_lints/src/if_let_mutex.rs b/src/tools/clippy/clippy_lints/src/if_let_mutex.rs index e950170078493..a461454b0d714 100644 --- a/src/tools/clippy/clippy_lints/src/if_let_mutex.rs +++ b/src/tools/clippy/clippy_lints/src/if_let_mutex.rs @@ -121,7 +121,7 @@ impl<'tcx> Visitor<'tcx> for ArmVisitor<'_, 'tcx> { impl<'tcx, 'l> ArmVisitor<'tcx, 'l> { fn same_mutex(&self, cx: &LateContext<'_>, op_mutex: &Expr<'_>) -> bool { self.found_mutex - .map_or(false, |arm_mutex| SpanlessEq::new(cx).eq_expr(op_mutex, arm_mutex)) + .is_some_and(|arm_mutex| SpanlessEq::new(cx).eq_expr(op_mutex, arm_mutex)) } } diff --git a/src/tools/clippy/clippy_lints/src/infinite_iter.rs b/src/tools/clippy/clippy_lints/src/infinite_iter.rs index 78b5ec8ec1ef4..24f4d5ed04ec8 100644 --- a/src/tools/clippy/clippy_lints/src/infinite_iter.rs +++ b/src/tools/clippy/clippy_lints/src/infinite_iter.rs @@ -169,9 +169,9 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { ExprKind::Block(block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)), ExprKind::Box(e) | ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_infinite(cx, e), ExprKind::Call(path, _) => path_def_id(cx, path) - .map_or(false, |id| match_def_path(cx, id, &paths::ITER_REPEAT)) + .is_some_and(|id| match_def_path(cx, id, &paths::ITER_REPEAT)) .into(), - ExprKind::Struct(..) => higher::Range::hir(expr).map_or(false, |r| r.end.is_none()).into(), + ExprKind::Struct(..) => higher::Range::hir(expr).is_some_and(|r| r.end.is_none()).into(), _ => Finite, } } @@ -233,9 +233,7 @@ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { let not_double_ended = cx .tcx .get_diagnostic_item(sym::DoubleEndedIterator) - .map_or(false, |id| { - !implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[]) - }); + .is_some_and(|id| !implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[])); if not_double_ended { return is_infinite(cx, &args[0]); } diff --git a/src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs b/src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs index b56d87c5348c2..85289c128a32b 100644 --- a/src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs +++ b/src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs @@ -74,7 +74,7 @@ fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefI if cx .tcx .get_diagnostic_item(sym::Iterator) - .map_or(false, |iter_id| !implements_trait(cx, ret_ty, iter_id, &[])) + .is_some_and(|iter_id| !implements_trait(cx, ret_ty, iter_id, &[])) { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs index 246f5aad8fbad..4517dacaac1f8 100644 --- a/src/tools/clippy/clippy_lints/src/len_zero.rs +++ b/src/tools/clippy/clippy_lints/src/len_zero.rs @@ -480,7 +480,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = &cx.typeck_results().expr_ty(expr).peel_refs(); match ty.kind() { - ty::Dynamic(tt, ..) => tt.principal().map_or(false, |principal| { + ty::Dynamic(tt, ..) => tt.principal().is_some_and(|principal| { let is_empty = sym!(is_empty); cx.tcx .associated_items(principal.def_id()) diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index 172fdf8c85269..e7f5df059c33d 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -3,6 +3,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(drain_filter)] +#![feature(is_some_with)] #![feature(iter_intersperse)] #![feature(let_chains)] #![feature(let_else)] diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs index 5c0bd57ac5097..eb69eb6ce7eb0 100644 --- a/src/tools/clippy/clippy_lints/src/lifetimes.rs +++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs @@ -415,7 +415,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { .tcx .lang_items() .require(item) - .map_or(false, |id| Some(id) == trait_ref.trait_def_id()) + .is_ok_and(|id| Some(id) == trait_ref.trait_def_id()) }) { let mut sub_visitor = RefVisitor::new(self.cx); sub_visitor.visit_trait_ref(trait_ref); diff --git a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs index 5f5beccd030c1..e1cd44f7b47b3 100644 --- a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs @@ -69,7 +69,7 @@ fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { match ty.kind() { ty::Array(_, n) => n .try_eval_usize(cx.tcx, cx.param_env) - .map_or(false, |val| (0..=32).contains(&val)), + .is_some_and(|val| (0..=32).contains(&val)), _ => false, } } diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_find.rs b/src/tools/clippy/clippy_lints/src/loops/manual_find.rs index 33736d6d4e650..b6b8d11bff792 100644 --- a/src/tools/clippy/clippy_lints/src/loops/manual_find.rs +++ b/src/tools/clippy/clippy_lints/src/loops/manual_find.rs @@ -52,7 +52,7 @@ pub(super) fn check<'tcx>( ); } let ty = cx.typeck_results().expr_ty(inner_ret); - if cx.tcx.lang_items().copy_trait().map_or(false, |id| implements_trait(cx, ty, id, &[])) { + if cx.tcx.lang_items().copy_trait().is_some_and(|id| implements_trait(cx, ty, id, &[])) { snippet.push_str( &format!( ".find(|{}{}| {})", diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs b/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs index b31015d195b52..c98c395976e0b 100644 --- a/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs +++ b/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs @@ -418,7 +418,7 @@ fn get_assignments<'a, 'tcx>( .chain((*expr).into_iter()) .filter(move |e| { if let ExprKind::AssignOp(_, place, _) = e.kind { - path_to_local(place).map_or(false, |id| { + path_to_local(place).is_some_and(|id| { !loop_counters .iter() // skip the first item which should be `StartKind::Range` diff --git a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs index aedf3810b23e9..4a7a7d55c7f5d 100644 --- a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs +++ b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs @@ -139,7 +139,7 @@ impl BreakAfterExprVisitor { break_after_expr: false, }; - get_enclosing_block(cx, hir_id).map_or(false, |block| { + get_enclosing_block(cx, hir_id).is_some_and(|block| { visitor.visit_block(block); visitor.break_after_expr }) diff --git a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs index 1439f1f4c75d5..9d18593c79fc3 100644 --- a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs +++ b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs @@ -53,7 +53,7 @@ pub(super) fn check<'tcx>( .tcx .lang_items() .clone_trait() - .map_or(false, |id| implements_trait(cx, ty, id, &[])); + .is_some_and(|id| implements_trait(cx, ty, id, &[])); then { // Make sure that the push does not involve possibly mutating values match pushed_item.kind { diff --git a/src/tools/clippy/clippy_lints/src/loops/utils.rs b/src/tools/clippy/clippy_lints/src/loops/utils.rs index 4801a84eb92ce..965ddc8a78839 100644 --- a/src/tools/clippy/clippy_lints/src/loops/utils.rs +++ b/src/tools/clippy/clippy_lints/src/loops/utils.rs @@ -321,9 +321,10 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor { /// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the /// actual `Iterator` that the loop uses. pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { - let impls_iterator = cx.tcx.get_diagnostic_item(sym::Iterator).map_or(false, |id| { - implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[]) - }); + let impls_iterator = cx + .tcx + .get_diagnostic_item(sym::Iterator) + .is_some_and(|id| implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[])); if impls_iterator { format!( "{}", diff --git a/src/tools/clippy/clippy_lints/src/manual_strip.rs b/src/tools/clippy/clippy_lints/src/manual_strip.rs index dfb3efc4e28b6..5f05f4b1ab96a 100644 --- a/src/tools/clippy/clippy_lints/src/manual_strip.rs +++ b/src/tools/clippy/clippy_lints/src/manual_strip.rs @@ -160,9 +160,9 @@ fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'t .. }) = expr.kind { - constant_length(cx, pattern).map_or(false, |length| length == n) + constant_length(cx, pattern).is_some_and(|length| length == n) } else { - len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg)) + len_arg(cx, expr).is_some_and(|arg| eq_expr_value(cx, pattern, arg)) } } diff --git a/src/tools/clippy/clippy_lints/src/map_clone.rs b/src/tools/clippy/clippy_lints/src/map_clone.rs index 3533de54a1e3d..b9bf280dfddd1 100644 --- a/src/tools/clippy/clippy_lints/src/map_clone.rs +++ b/src/tools/clippy/clippy_lints/src/map_clone.rs @@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone { if ident_eq(name, obj) && method.ident.name == sym::clone; if let Some(fn_id) = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id); if let Some(trait_id) = cx.tcx.trait_of_item(fn_id); - if cx.tcx.lang_items().clone_trait().map_or(false, |id| id == trait_id); + if cx.tcx.lang_items().clone_trait().is_some_and(|id| id == trait_id); // no autoderefs if !cx.typeck_results().expr_adjustments(obj).iter() .any(|a| matches!(a.kind, Adjust::Deref(Some(..)))); diff --git a/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs b/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs index a68eec842abc5..3981077ec2d43 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs @@ -88,7 +88,7 @@ where if first_attrs.is_empty(); if iter .all(|arm| { - find_bool_lit(&arm.2.kind, is_if_let).map_or(false, |b| b == b0) && arm.3.is_none() && arm.0.is_empty() + find_bool_lit(&arm.2.kind, is_if_let).is_some_and(|b| b == b0) && arm.3.is_none() && arm.0.is_empty() }); then { if let Some(last_pat) = last_pat_opt { diff --git a/src/tools/clippy/clippy_lints/src/matches/try_err.rs b/src/tools/clippy/clippy_lints/src/matches/try_err.rs index 0491a0679f37a..7e4d1aa3c2afc 100644 --- a/src/tools/clippy/clippy_lints/src/matches/try_err.rs +++ b/src/tools/clippy/clippy_lints/src/matches/try_err.rs @@ -57,7 +57,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine let span = hygiene::walk_chain(err_arg.span, try_arg.span.ctxt()); let mut applicability = Applicability::MachineApplicable; let origin_snippet = snippet_with_applicability(cx, span, "_", &mut applicability); - let ret_prefix = if get_parent_expr(cx, expr).map_or(false, |e| matches!(e.kind, ExprKind::Ret(_))) { + let ret_prefix = if get_parent_expr(cx, expr).is_some_and(|e| matches!(e.kind, ExprKind::Ret(_))) { "" // already returns } else { "return " diff --git a/src/tools/clippy/clippy_lints/src/mem_forget.rs b/src/tools/clippy/clippy_lints/src/mem_forget.rs index d6c235b5a693a..696e5e42444ac 100644 --- a/src/tools/clippy/clippy_lints/src/mem_forget.rs +++ b/src/tools/clippy/clippy_lints/src/mem_forget.rs @@ -35,7 +35,7 @@ impl<'tcx> LateLintPass<'tcx> for MemForget { if cx.tcx.is_diagnostic_item(sym::mem_forget, def_id) { let forgot_ty = cx.typeck_results().expr_ty(first_arg); - if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) { + if forgot_ty.ty_adt_def().is_some_and(|def| def.has_dtor(cx.tcx)) { span_lint(cx, MEM_FORGET, e.span, "usage of `mem::forget` on `Drop` type"); } } diff --git a/src/tools/clippy/clippy_lints/src/methods/err_expect.rs b/src/tools/clippy/clippy_lints/src/methods/err_expect.rs index 570a1b87358dd..7a9f21a1d9f51 100644 --- a/src/tools/clippy/clippy_lints/src/methods/err_expect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/err_expect.rs @@ -56,5 +56,5 @@ fn get_data_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { cx.tcx .get_diagnostic_item(sym::Debug) - .map_or(false, |debug| implements_trait(cx, ty, debug, &[])) + .is_some_and(|debug| implements_trait(cx, ty, debug, &[])) } diff --git a/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs b/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs index 6f2307d8f18ff..c5f8d0c4b237c 100644 --- a/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs +++ b/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs @@ -84,7 +84,7 @@ pub(super) fn check<'tcx>( hir::ExprKind::MethodCall(..) => { cx.typeck_results() .type_dependent_def_id(arg.hir_id) - .map_or(false, |method_id| { + .is_some_and(|method_id| { matches!( cx.tcx.fn_sig(method_id).output().skip_binder().kind(), ty::Ref(re, ..) if re.is_static() diff --git a/src/tools/clippy/clippy_lints/src/methods/filter_next.rs b/src/tools/clippy/clippy_lints/src/methods/filter_next.rs index bcf8d93b602ef..c97898a67cd3d 100644 --- a/src/tools/clippy/clippy_lints/src/methods/filter_next.rs +++ b/src/tools/clippy/clippy_lints/src/methods/filter_next.rs @@ -16,9 +16,10 @@ pub(super) fn check<'tcx>( filter_arg: &'tcx hir::Expr<'_>, ) { // lint if caller of `.filter().next()` is an Iterator - let recv_impls_iterator = cx.tcx.get_diagnostic_item(sym::Iterator).map_or(false, |id| { - implements_trait(cx, cx.typeck_results().expr_ty(recv), id, &[]) - }); + let recv_impls_iterator = cx + .tcx + .get_diagnostic_item(sym::Iterator) + .is_some_and(|id| implements_trait(cx, cx.typeck_results().expr_ty(recv), id, &[])); if recv_impls_iterator { let msg = "called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling \ `.find(..)` instead"; diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs b/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs index 68a75667914aa..545584b786032 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs @@ -37,8 +37,8 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option { } else { let ty = cx.typeck_results().expr_ty(e); if is_type_diagnostic_item(cx, ty, sym::String) - || (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, Ty::is_str)) - || (match_type(cx, ty, &paths::COW) && get_ty_param(ty).map_or(false, Ty::is_str)) + || (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).is_some_and(|ty| ty.is_str())) + || (match_type(cx, ty, &paths::COW) && get_ty_param(ty).is_some_and(|ty| ty.is_str())) { Some(RepeatKind::String) } else { diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 9bb7bb7a7aba4..d871c9236cdd7 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -2923,7 +2923,7 @@ impl SelfKind { ty.boxed_ty() == parent_ty } else if is_type_diagnostic_item(cx, ty, sym::Rc) || is_type_diagnostic_item(cx, ty, sym::Arc) { if let ty::Adt(_, substs) = ty.kind() { - substs.types().next().map_or(false, |t| t == parent_ty) + substs.types().next().is_some_and(|t| t == parent_ty) } else { false } diff --git a/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs b/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs index d64a9f320d90e..0dc8a2c0e3a9b 100644 --- a/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs @@ -42,5 +42,5 @@ fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool { cx.tcx .get_diagnostic_item(sym::Debug) - .map_or(false, |debug| implements_trait(cx, ty, debug, &[])) + .is_some_and(|debug| implements_trait(cx, ty, debug, &[])) } diff --git a/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs b/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs index 912499bf96b94..11af15a2290f0 100644 --- a/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs @@ -48,9 +48,7 @@ pub(super) fn check<'tcx>( hir::ExprKind::Path(ref expr_qpath) => cx .qpath_res(expr_qpath, map_arg.hir_id) .opt_def_id() - .map_or(false, |fun_def_id| { - deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path)) - }), + .is_some_and(|fun_def_id| deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path))), hir::ExprKind::Closure { body, .. } => { let closure_body = cx.tcx.hir().body(body); let closure_expr = peel_blocks(&closure_body.value); diff --git a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs index 4ac738272d085..269577de624cc 100644 --- a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs +++ b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs @@ -372,7 +372,7 @@ fn parse_iter_usage<'tcx>( && cx .typeck_results() .type_dependent_def_id(e.hir_id) - .map_or(false, |id| is_diag_item_method(cx, id, sym::Option)) => + .is_some_and(|id| is_diag_item_method(cx, id, sym::Option)) => { (Some(UnwrapKind::Unwrap), e.span) }, diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs index b4c6bfb31ed1c..a550ba7bbc080 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -269,7 +269,7 @@ fn check_other_call_arg<'tcx>( .subst_and_normalize_erasing_regions(call_substs, cx.param_env, projection_predicate.term); implements_trait(cx, receiver_ty, deref_trait_id, &[]) && get_associated_type(cx, receiver_ty, deref_trait_id, "Target") - .map_or(false, |ty| ty::Term::Ty(ty) == normalized_ty) + .is_some_and(|ty| ty::Term::Ty(ty) == normalized_ty) } else { false } diff --git a/src/tools/clippy/clippy_lints/src/misc.rs b/src/tools/clippy/clippy_lints/src/misc.rs index be7df08d89f05..8224e80c9ccb3 100644 --- a/src/tools/clippy/clippy_lints/src/misc.rs +++ b/src/tools/clippy/clippy_lints/src/misc.rs @@ -301,7 +301,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool { use rustc_span::hygiene::MacroKind; if expr.span.from_expansion() { let data = expr.span.ctxt().outer_expn_data(); - matches!(data.kind, ExpnKind::Macro(MacroKind::Attr|MacroKind::Derive, _)) + matches!(data.kind, ExpnKind::Macro(MacroKind::Attr | MacroKind::Derive, _)) } else { false } diff --git a/src/tools/clippy/clippy_lints/src/misc_early/mod.rs b/src/tools/clippy/clippy_lints/src/misc_early/mod.rs index 704918c0b979b..81f1c9a89d7f0 100644 --- a/src/tools/clippy/clippy_lints/src/misc_early/mod.rs +++ b/src/tools/clippy/clippy_lints/src/misc_early/mod.rs @@ -390,7 +390,7 @@ impl MiscEarlyLints { // See for a regression. // FIXME: Find a better way to detect those cases. let lit_snip = match snippet_opt(cx, lit.span) { - Some(snip) if snip.chars().next().map_or(false, |c| c.is_ascii_digit()) => snip, + Some(snip) if snip.chars().next().is_some_and(|c| c.is_ascii_digit()) => snip, _ => return, }; diff --git a/src/tools/clippy/clippy_lints/src/needless_continue.rs b/src/tools/clippy/clippy_lints/src/needless_continue.rs index 98a3bce1ff38a..26c8105147b8d 100644 --- a/src/tools/clippy/clippy_lints/src/needless_continue.rs +++ b/src/tools/clippy/clippy_lints/src/needless_continue.rs @@ -189,7 +189,7 @@ fn needless_continue_in_else(else_expr: &ast::Expr, label: Option<&ast::Label>) } fn is_first_block_stmt_continue(block: &ast::Block, label: Option<&ast::Label>) -> bool { - block.stmts.get(0).map_or(false, |stmt| match stmt.kind { + block.stmts.get(0).is_some_and(|stmt| match stmt.kind { ast::StmtKind::Semi(ref e) | ast::StmtKind::Expr(ref e) => { if let ast::ExprKind::Continue(ref l) = e.kind { compare_labels(label, l.as_ref()) @@ -429,7 +429,7 @@ fn check_and_warn<'a>(cx: &EarlyContext<'_>, expr: &'a ast::Expr) { #[must_use] fn erode_from_back(s: &str) -> String { let mut ret = s.to_string(); - while ret.pop().map_or(false, |c| c != '}') {} + while ret.pop().is_some_and(|c| c != '}') {} while let Some(c) = ret.pop() { if !c.is_whitespace() { ret.push(c); diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index a1ef32ae60805..830d459801cc9 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -251,7 +251,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx Item<'_>) { if let ItemKind::Const(hir_ty, body_id) = it.kind { let ty = hir_ty_to_ty(cx.tcx, hir_ty); - if !macro_backtrace(it.span).last().map_or(false, |macro_call| { + if !macro_backtrace(it.span).last().is_some_and(|macro_call| { matches!( cx.tcx.get_diagnostic_name(macro_call.def_id), Some(sym::thread_local_macro) diff --git a/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs b/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs index 4722c031006be..49afc816f6318 100644 --- a/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs +++ b/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs @@ -8,7 +8,6 @@ use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_hir::def_id::DefId; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::hygiene::{ExpnKind, MacroKind}; @@ -100,7 +99,8 @@ fn is_offending_macro<'a>(cx: &EarlyContext<'_>, span: Span, mac_braces: &'a Mac || span .macro_backtrace() .last() - .map_or(false, |e| e.macro_def_id.map_or(false, DefId::is_local)) + .and_then(|e| e.macro_def_id) + .is_some_and(|id| id.is_local()) }; if_chain! { if let ExpnKind::Macro(MacroKind::Bang, mac_name) = span.ctxt().outer_expn_data().kind; diff --git a/src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs b/src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs index e1f9b5906f667..d5923100dc187 100644 --- a/src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs +++ b/src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs @@ -42,9 +42,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) if typeck .type_dependent_def_id(expr.hir_id) .and_then(|id| cx.tcx.trait_of_item(id)) - .map_or(false, |id| { - matches!(cx.tcx.get_diagnostic_name(id), Some(sym::ToString | sym::ToOwned)) - }) => + .is_some_and(|id| matches!(cx.tcx.get_diagnostic_name(id), Some(sym::ToString | sym::ToOwned))) => { (arg, arg.span) }, diff --git a/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs b/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs index b6097710dc689..9dbf2c1330c47 100644 --- a/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs @@ -15,7 +15,7 @@ pub struct Context { } impl Context { fn skip_expr(&mut self, e: &hir::Expr<'_>) -> bool { - self.expr_id.is_some() || self.const_span.map_or(false, |span| span.contains(e.span)) + self.expr_id.is_some() || self.const_span.is_some_and(|span| span.contains(e.span)) } pub fn check_binary<'tcx>( diff --git a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs index 5fa4fd74853f1..2474a8a2f4800 100644 --- a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs +++ b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs @@ -200,7 +200,10 @@ impl<'tcx> PassByRefOrValue { continue; } } - let value_type = if fn_body.and_then(|body| body.params.get(index)).map_or(false, is_self) { + let value_type = if fn_body + .and_then(|body| body.params.get(index)) + .is_some_and(|p| is_self(p)) + { "self".into() } else { snippet(cx, decl_ty.span, "_").into() diff --git a/src/tools/clippy/clippy_lints/src/ptr.rs b/src/tools/clippy/clippy_lints/src/ptr.rs index 25b73918c0a25..1f77a835bb1b6 100644 --- a/src/tools/clippy/clippy_lints/src/ptr.rs +++ b/src/tools/clippy/clippy_lints/src/ptr.rs @@ -674,9 +674,8 @@ fn get_rptr_lm<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> Option<(&'tcx Lifetime, Mutabil fn is_null_path(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { if let ExprKind::Call(pathexp, []) = expr.kind { - path_def_id(cx, pathexp).map_or(false, |id| { - matches!(cx.tcx.get_diagnostic_name(id), Some(sym::ptr_null | sym::ptr_null_mut)) - }) + path_def_id(cx, pathexp) + .is_some_and(|id| matches!(cx.tcx.get_diagnostic_name(id), Some(sym::ptr_null | sym::ptr_null_mut))) } else { false } diff --git a/src/tools/clippy/clippy_lints/src/redundant_slicing.rs b/src/tools/clippy/clippy_lints/src/redundant_slicing.rs index db6c97f3739c7..b762fe34dd5f4 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_slicing.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_slicing.rs @@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { let (expr_ty, expr_ref_count) = peel_mid_ty_refs(cx.typeck_results().expr_ty(expr)); let (indexed_ty, indexed_ref_count) = peel_mid_ty_refs(cx.typeck_results().expr_ty(indexed)); let parent_expr = get_parent_expr(cx, expr); - let needs_parens_for_prefix = parent_expr.map_or(false, |parent| { + let needs_parens_for_prefix = parent_expr.is_some_and(|parent| { parent.precedence().order() > PREC_PREFIX }); let mut app = Applicability::MachineApplicable; @@ -112,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { kind: ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _), .. }) - ) || cx.typeck_results().expr_adjustments(expr).first().map_or(false, |a| { + ) || cx.typeck_results().expr_adjustments(expr).first().is_some_and(|a| { matches!(a.kind, Adjust::Borrow(AutoBorrow::Ref(_, AutoBorrowMutability::Mut { .. }))) }) { // The slice was used to make a temporary reference. diff --git a/src/tools/clippy/clippy_lints/src/returns.rs b/src/tools/clippy/clippy_lints/src/returns.rs index 5ae04947b82d0..44f42ad41c1ff 100644 --- a/src/tools/clippy/clippy_lints/src/returns.rs +++ b/src/tools/clippy/clippy_lints/src/returns.rs @@ -182,7 +182,7 @@ fn check_final_expr<'tcx>( // allow `#[cfg(a)] return a; #[cfg(b)] return b;` let attrs = cx.tcx.hir().attrs(expr.hir_id); if !attrs.iter().any(attr_is_cfg) { - let borrows = inner.map_or(false, |inner| last_statement_borrows(cx, inner)); + let borrows = inner.is_some_and(|inner| last_statement_borrows(cx, inner)); if !borrows { emit_return_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs b/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs index f35f44eda5679..ef47f8079064c 100644 --- a/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs +++ b/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs @@ -53,7 +53,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m }, TyKind::Path(qpath) if get_bounds_if_impl_trait(cx, qpath, inner.hir_id) - .map_or(false, |bounds| bounds.len() > 1) => + .is_some_and(|bounds| bounds.len() > 1) => { format!("&{}({})", ltopt, &inner_snippet) }, diff --git a/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs b/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs index cf509455aad0a..68e5f74edd2cd 100644 --- a/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs +++ b/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs @@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, ExprKind, PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Ty, TypeVisitable, TypeSuperVisitable, TypeVisitor}; +use rustc_middle::ty::{self, Ty, TypeSuperVisitable, TypeVisitable, TypeVisitor}; use super::LET_UNIT_VALUE; diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs b/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs index 7d4373b2a57bc..4c7a173c3ed3d 100644 --- a/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs +++ b/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs @@ -185,7 +185,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { segments: [PathSegment { ident: left_name, .. }], .. })) = &left_expr.kind; if left_name == left_ident; - if cx.tcx.get_diagnostic_item(sym::Ord).map_or(false, |id| { + if cx.tcx.get_diagnostic_item(sym::Ord).is_some_and(|id| { implements_trait(cx, cx.typeck_results().expr_ty(left_expr), id, &[]) }); then { diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs index a94f0357977ea..00628ceca1241 100644 --- a/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs +++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs @@ -1355,9 +1355,7 @@ fn is_first_if_chain_expr(cx: &LateContext<'_>, hir_id: HirId, if_chain_span: Sp #[rustfmt::skip] !matches!(node, Node::Expr(Expr { kind: ExprKind::Block(..), .. }) | Node::Stmt(_)) }) - .map_or(false, |(id, _)| { - is_expn_of(cx.tcx.hir().span(id), "if_chain") != Some(if_chain_span) - }) + .is_some_and(|(id, _)| is_expn_of(cx.tcx.hir().span(id), "if_chain") != Some(if_chain_span)) } /// Checks a trailing slice of statements and expression of a `Block` to see if they are part diff --git a/src/tools/clippy/clippy_lints/src/vec_init_then_push.rs b/src/tools/clippy/clippy_lints/src/vec_init_then_push.rs index 35db45e2b0c99..e70f6c51e15ea 100644 --- a/src/tools/clippy/clippy_lints/src/vec_init_then_push.rs +++ b/src/tools/clippy/clippy_lints/src/vec_init_then_push.rs @@ -98,7 +98,7 @@ impl VecPushSearcher { needs_mut |= cx.typeck_results().expr_ty_adjusted(last_place).ref_mutability() == Some(Mutability::Mut) || get_parent_expr(cx, last_place) - .map_or(false, |e| matches!(e.kind, ExprKind::AddrOf(_, Mutability::Mut, _))); + .is_some_and(|e| matches!(e.kind, ExprKind::AddrOf(_, Mutability::Mut, _))); }, ExprKind::MethodCall(_, [recv, ..], _) if recv.hir_id == e.hir_id diff --git a/src/tools/clippy/clippy_lints/src/write.rs b/src/tools/clippy/clippy_lints/src/write.rs index 67b2bc8c3f3cd..b1180c95d5c10 100644 --- a/src/tools/clippy/clippy_lints/src/write.rs +++ b/src/tools/clippy/clippy_lints/src/write.rs @@ -305,7 +305,7 @@ impl EarlyLintPass for Write { .opts .crate_name .as_ref() - .map_or(false, |crate_name| crate_name == "build_script_build") + .is_some_and(|crate_name| crate_name == "build_script_build") } if mac.path == sym!(print) { diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs index 177e754ee091e..a0c0d0f11de08 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs @@ -601,7 +601,7 @@ pub fn eq_ext(l: &Extern, r: &Extern) -> bool { use Extern::*; match (l, r) { (None, None) | (Implicit(_), Implicit(_)) => true, - (Explicit(l,_), Explicit(r,_)) => eq_str_lit(l, r), + (Explicit(l, _), Explicit(r, _)) => eq_str_lit(l, r), _ => false, } } diff --git a/src/tools/clippy/clippy_utils/src/diagnostics.rs b/src/tools/clippy/clippy_utils/src/diagnostics.rs index 7f55db3b31f70..ad95369b9ef70 100644 --- a/src/tools/clippy/clippy_utils/src/diagnostics.rs +++ b/src/tools/clippy/clippy_utils/src/diagnostics.rs @@ -155,13 +155,7 @@ where }); } -pub fn span_lint_hir( - cx: &LateContext<'_>, - lint: &'static Lint, - hir_id: HirId, - sp: Span, - msg: &str, -) { +pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| { let mut diag = diag.build(msg); docs_link(&mut diag, lint); diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index 793e3cc58c21d..a4e260499d6fa 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -180,7 +180,7 @@ impl HirEqInterExpr<'_, '_, '_> { } fn cannot_be_compared_block(&mut self, block: &Block<'_>) -> bool { - if block.stmts.last().map_or(false, |stmt| { + if block.stmts.last().is_some_and(|stmt| { matches!( stmt.kind, StmtKind::Semi(semi_expr) if self.should_ignore(semi_expr) @@ -269,9 +269,8 @@ impl HirEqInterExpr<'_, '_, '_> { (&ExprKind::Block(l, _), &ExprKind::Block(r, _)) => self.eq_block(l, r), (&ExprKind::Binary(l_op, ll, lr), &ExprKind::Binary(r_op, rl, rr)) => { l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr) - || swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| { - l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr) - }) + || swap_binop(l_op.node, ll, lr) + .is_some_and(|(l_op, ll, lr)| l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)) }, (&ExprKind::Break(li, ref le), &ExprKind::Break(ri, ref re)) => { both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name) @@ -541,7 +540,7 @@ fn swap_binop<'a>( /// `eq_fn`. pub fn both(l: &Option, r: &Option, mut eq_fn: impl FnMut(&X, &X) -> bool) -> bool { l.as_ref() - .map_or_else(|| r.is_none(), |x| r.as_ref().map_or(false, |y| eq_fn(x, y))) + .map_or_else(|| r.is_none(), |x| r.as_ref().is_some_and(|y| eq_fn(x, y))) } /// Checks if two slices are equal as per `eq_fn`. diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 1b32f0aaeb8df..b42d3c2c1db19 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1,5 +1,6 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] +#![feature(is_some_with)] #![feature(let_else)] #![feature(let_chains)] #![feature(lint_reasons)] @@ -93,7 +94,9 @@ use rustc_middle::ty::fast_reject::SimplifiedTypeGen::{ ArraySimplifiedType, BoolSimplifiedType, CharSimplifiedType, FloatSimplifiedType, IntSimplifiedType, PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType, }; -use rustc_middle::ty::{layout::IntegerExt, BorrowKind, DefIdTree, Ty, TyCtxt, TypeAndMut, TypeVisitable, UpvarCapture}; +use rustc_middle::ty::{ + layout::IntegerExt, BorrowKind, DefIdTree, Ty, TyCtxt, TypeAndMut, TypeVisitable, UpvarCapture, +}; use rustc_middle::ty::{FloatTy, IntTy, UintTy}; use rustc_semver::RustcVersion; use rustc_session::Session; @@ -268,7 +271,7 @@ pub fn is_wild(pat: &Pat<'_>) -> bool { pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool { let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); let trt_id = cx.tcx.trait_of_item(def_id); - trt_id.map_or(false, |trt_id| match_def_path(cx, trt_id, path)) + trt_id.is_some_and(|trt_id| match_def_path(cx, trt_id, path)) } /// Checks if a method is defined in an impl of a diagnostic item @@ -293,7 +296,7 @@ pub fn is_diag_trait_item(cx: &LateContext<'_>, def_id: DefId, diag_item: Symbol pub fn is_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, diag_item: Symbol) -> bool { cx.typeck_results() .type_dependent_def_id(expr.hir_id) - .map_or(false, |did| is_diag_trait_item(cx, did, diag_item)) + .is_some_and(|did| is_diag_trait_item(cx, did, diag_item)) } /// Checks if the given expression is a path referring an item on the trait @@ -309,7 +312,7 @@ pub fn is_trait_item(cx: &LateContext<'_>, expr: &Expr<'_>, diag_item: Symbol) - if let hir::ExprKind::Path(ref qpath) = expr.kind { cx.qpath_res(qpath, expr.hir_id) .opt_def_id() - .map_or(false, |def_id| is_diag_trait_item(cx, def_id, diag_item)) + .is_some_and(|def_id| is_diag_trait_item(cx, def_id, diag_item)) } else { false } @@ -369,13 +372,13 @@ pub fn match_qpath(path: &QPath<'_>, segments: &[&str]) -> bool { /// /// Please use `is_expr_diagnostic_item` if the target is a diagnostic item. pub fn is_expr_path_def_path(cx: &LateContext<'_>, expr: &Expr<'_>, segments: &[&str]) -> bool { - path_def_id(cx, expr).map_or(false, |id| match_def_path(cx, id, segments)) + path_def_id(cx, expr).is_some_and(|id| match_def_path(cx, id, segments)) } /// If the expression is a path, resolves it to a `DefId` and checks if it matches the given /// diagnostic item. pub fn is_expr_diagnostic_item(cx: &LateContext<'_>, expr: &Expr<'_>, diag_item: Symbol) -> bool { - path_def_id(cx, expr).map_or(false, |id| cx.tcx.is_diagnostic_item(diag_item, id)) + path_def_id(cx, expr).is_some_and(|id| cx.tcx.is_diagnostic_item(diag_item, id)) } /// THIS METHOD IS DEPRECATED and will eventually be removed since it does not match against the @@ -1081,7 +1084,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option, def_id: DefId) -> bool { cx.tcx .entry_fn(()) - .map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id) + .is_some_and(|(entry_fn_def_id, _)| def_id == entry_fn_def_id) } /// Returns `true` if the expression is in the program's `#[panic_handler]`. @@ -1435,7 +1438,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { match pat.kind { PatKind::Wild => false, - PatKind::Binding(_, _, _, pat) => pat.map_or(false, |pat| is_refutable(cx, pat)), + PatKind::Binding(_, _, _, pat) => pat.is_some_and(|pat| is_refutable(cx, pat)), PatKind::Box(pat) | PatKind::Ref(pat, _) => is_refutable(cx, pat), PatKind::Lit(..) | PatKind::Range(..) => true, PatKind::Path(ref qpath) => is_enum_variant(cx, qpath, pat.hir_id), @@ -1652,7 +1655,7 @@ pub fn match_libc_symbol(cx: &LateContext<'_>, did: DefId, name: &str) -> bool { let path = cx.get_def_path(did); // libc is meant to be used as a flat list of names, but they're all actually defined in different // modules based on the target platform. Ignore everything but crate name and the item name. - path.first().map_or(false, |s| s.as_str() == "libc") && path.last().map_or(false, |s| s.as_str() == name) + path.first().is_some_and(|s| s.as_str() == "libc") && path.last().is_some_and(|s| s.as_str() == name) } /// Returns the list of condition expressions and the list of blocks in a @@ -1740,7 +1743,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { _ => None, }; - did.map_or(false, |did| cx.tcx.has_attr(did, sym::must_use)) + did.is_some_and(|did| cx.tcx.has_attr(did, sym::must_use)) } /// Checks if an expression represents the identity function @@ -1787,7 +1790,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool match expr.kind { ExprKind::Closure { body, .. } => is_body_identity_function(cx, cx.tcx.hir().body(body)), - _ => path_def_id(cx, expr).map_or(false, |id| match_def_path(cx, id, &paths::CONVERT_IDENTITY)), + _ => path_def_id(cx, expr).is_some_and(|id| match_def_path(cx, id, &paths::CONVERT_IDENTITY)), } } diff --git a/src/tools/clippy/clippy_utils/src/macros.rs b/src/tools/clippy/clippy_utils/src/macros.rs index a268e339bb130..dccb0d840e3b0 100644 --- a/src/tools/clippy/clippy_utils/src/macros.rs +++ b/src/tools/clippy/clippy_utils/src/macros.rs @@ -528,7 +528,7 @@ impl<'tcx> FormatArgsArg<'tcx> { /// Returns true if any formatting parameters are used that would have an effect on strings, /// like `{:+2}` instead of just `{}`. pub fn has_string_formatting(&self) -> bool { - self.spec.map_or(false, |spec| { + self.spec.is_some_and(|spec| { // `!` because these conditions check that `self` is unformatted. !if_chain! { // struct `core::fmt::rt::v1::Argument` diff --git a/src/tools/clippy/clippy_utils/src/numeric_literal.rs b/src/tools/clippy/clippy_utils/src/numeric_literal.rs index 3fb5415ce0299..16fe6ed7ac7c9 100644 --- a/src/tools/clippy/clippy_utils/src/numeric_literal.rs +++ b/src/tools/clippy/clippy_utils/src/numeric_literal.rs @@ -57,7 +57,7 @@ impl<'a> NumericLiteral<'a> { .trim_start() .chars() .next() - .map_or(false, |c| c.is_ascii_digit()) + .is_some_and(|c| c.is_ascii_digit()) { let (unsuffixed, suffix) = split_suffix(src, lit_kind); let float = matches!(lit_kind, LitKind::Float(..)); diff --git a/src/tools/clippy/clippy_utils/src/source.rs b/src/tools/clippy/clippy_utils/src/source.rs index f88a92fb11c11..7b24acf851748 100644 --- a/src/tools/clippy/clippy_utils/src/source.rs +++ b/src/tools/clippy/clippy_utils/src/source.rs @@ -24,7 +24,7 @@ pub fn span_starts_with(cx: &T, span: Span, text: &str) -> bool let end = span.hi() - pos.sf.start_pos; src.get(pos.pos.0 as usize..end.0 as usize) // Expression spans can include wrapping parenthesis. Remove them first. - .map_or(false, |s| s.trim_start_matches('(').starts_with(text)) + .is_some_and(|s| s.trim_start_matches('(').starts_with(text)) } helper(cx.sess().source_map(), span, text) } diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index a426fa1b0ffcf..b311e0f3979df 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -321,11 +321,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb /// Returns `false` if the `LangItem` is not defined. pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool { match ty.kind() { - ty::Adt(adt, _) => cx - .tcx - .lang_items() - .require(lang_item) - .map_or(false, |li| li == adt.did()), + ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).is_ok_and(|li| li == adt.did()), _ => false, } } @@ -376,7 +372,7 @@ pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { .tcx .lang_items() .drop_trait() - .map_or(false, |id| implements_trait(cx, ty, id, &[])) + .is_some_and(|id| implements_trait(cx, ty, id, &[])) { // This type doesn't implement drop, so no side effects here. // Check if any component type has any. @@ -584,7 +580,7 @@ fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { let output = bounds .projection_bounds() - .find(|p| lang_items.fn_once_output().map_or(false, |id| id == p.item_def_id())) + .find(|p| lang_items.fn_once_output().is_some_and(|id| id == p.item_def_id())) .map(|p| p.map_bound(|p| p.term.ty().unwrap())); Some(ExprFnSig::Trait(bound.map_bound(|b| b.substs.type_at(0)), output)) }, diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs index 68cfa8c1aa8ec..71b8a4118a566 100644 --- a/src/tools/clippy/clippy_utils/src/visitors.rs +++ b/src/tools/clippy/clippy_utils/src/visitors.rs @@ -253,13 +253,13 @@ pub fn is_const_evaluatable<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> .cx .qpath_res(p, hir_id) .opt_def_id() - .map_or(false, |id| self.cx.tcx.is_const_fn_raw(id)) => {}, + .is_some_and(|id| self.cx.tcx.is_const_fn_raw(id)) => {}, ExprKind::MethodCall(..) if self .cx .typeck_results() .type_dependent_def_id(e.hir_id) - .map_or(false, |id| self.cx.tcx.is_const_fn_raw(id)) => {}, + .is_some_and(|id| self.cx.tcx.is_const_fn_raw(id)) => {}, ExprKind::Binary(_, lhs, rhs) if self.cx.typeck_results().expr_ty(lhs).peel_refs().is_primitive_ty() && self.cx.typeck_results().expr_ty(rhs).peel_refs().is_primitive_ty() => {}, @@ -338,7 +338,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { .cx .typeck_results() .type_dependent_def_id(e.hir_id) - .map_or(false, |id| self.cx.tcx.fn_sig(id).unsafety() == Unsafety::Unsafe) => + .is_some_and(|id| self.cx.tcx.fn_sig(id).unsafety() == Unsafety::Unsafe) => { self.is_unsafe = true; }, @@ -352,7 +352,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { .cx .qpath_res(p, e.hir_id) .opt_def_id() - .map_or(false, |id| self.cx.tcx.is_mutable_static(id)) => + .is_some_and(|id| self.cx.tcx.is_mutable_static(id)) => { self.is_unsafe = true; }, diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs index 96d542cfe1052..b6051df052513 100644 --- a/src/tools/clippy/src/driver.rs +++ b/src/tools/clippy/src/driver.rs @@ -1,3 +1,4 @@ +#![feature(is_some_with)] #![feature(rustc_private)] #![feature(once_cell)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] @@ -200,7 +201,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { } // If backtraces are enabled, also print the query stack - let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0"); + let backtrace = env::var_os("RUST_BACKTRACE").is_some_and(|x| x != "0"); let num_frames = if backtrace { None } else { Some(2) };