diff --git a/cargo-dylint/tests/ci.rs b/cargo-dylint/tests/ci.rs index d9548dd60..51abc5737 100644 --- a/cargo-dylint/tests/ci.rs +++ b/cargo-dylint/tests/ci.rs @@ -242,7 +242,7 @@ fn duplicate_dependencies() { let stdout_actual = std::str::from_utf8(&assert.get_output().stdout).unwrap(); let package_versions = stdout_actual .lines() - .filter(|line| line.chars().next().map_or(false, char::is_alphabetic)) + .filter(|line| line.chars().next().is_some_and(char::is_alphabetic)) .map(|line| { <[_; 2]>::try_from(line.split_ascii_whitespace().take(2).collect::>()) .unwrap() diff --git a/driver/src/lib.rs b/driver/src/lib.rs index 316e17beb..96ba77e99 100644 --- a/driver/src/lib.rs +++ b/driver/src/lib.rs @@ -245,8 +245,7 @@ impl rustc_driver::Callbacks for Callbacks { let dylint_libs = env::var(env::DYLINT_LIBS).ok(); let dylint_metadata = env::var(env::DYLINT_METADATA).ok(); let dylint_no_deps = env::var(env::DYLINT_NO_DEPS).ok(); - let dylint_no_deps_enabled = - dylint_no_deps.as_ref().map_or(false, |value| value != "0"); + let dylint_no_deps_enabled = dylint_no_deps.as_ref().is_some_and(|value| value != "0"); let cargo_primary_package_is_set = env::var(env::CARGO_PRIMARY_PACKAGE).is_ok(); sess.parse_sess().env_depinfo.lock().insert(( @@ -299,7 +298,7 @@ impl rustc_driver::Callbacks for Callbacks { #[must_use] fn list_enabled() -> bool { - env::var(env::DYLINT_LIST).map_or(false, |value| value != "0") + env::var(env::DYLINT_LIST).is_ok_and(|value| value != "0") } fn list_lints(before: &BTreeSet, after: &BTreeSet) { @@ -389,6 +388,8 @@ fn rustc_args, U: AsRef, V: AsRef>( let mut rustc_args = Vec::new(); let first_arg = args.peek(); + // smoelius: `Option::is_none_or` is too recent for some toolchains we test with. + #[allow(clippy::unnecessary_map_or)] if first_arg.map_or(true, |arg| !is_rustc(arg)) { rustc_args.push("rustc".to_owned()); } diff --git a/dylint/build.rs b/dylint/build.rs index 016ae955d..f96b676fb 100644 --- a/dylint/build.rs +++ b/dylint/build.rs @@ -26,7 +26,7 @@ fn write_dylint_driver_manifest_dir() { let dylint_driver_manifest_dir = if dylint_manifest_dir.starts_with(cargo_home) || dylint_manifest_dir .parent() - .map_or(false, |path| path.ends_with("target/package")) + .is_some_and(|path| path.ends_with("target/package")) || env::var(env::DOCS_RS).is_ok() { "None".to_owned() diff --git a/examples/experimental/missing_doc_comment_openai/src/lib.rs b/examples/experimental/missing_doc_comment_openai/src/lib.rs index a9ff0182a..d72ceef63 100644 --- a/examples/experimental/missing_doc_comment_openai/src/lib.rs +++ b/examples/experimental/missing_doc_comment_openai/src/lib.rs @@ -375,7 +375,7 @@ fn skip_preceding_line_comments(cx: &LateContext<'_>, mut span: Span) -> Span { let lo_prev_relative = sf.lines()[line]; let lo_prev = sf.absolute_position(lo_prev_relative); let span_prev = span.with_lo(lo_prev); - if snippet_opt(cx, span_prev).map_or(false, |snippet| snippet.starts_with("//")) { + if snippet_opt(cx, span_prev).is_some_and(|snippet| snippet.starts_with("//")) { span = span_prev; } else { break; @@ -387,12 +387,12 @@ fn skip_preceding_line_comments(cx: &LateContext<'_>, mut span: Span) -> Span { #[must_use] fn enabled(name: &str) -> bool { let key = env!("CARGO_PKG_NAME").to_uppercase() + "_" + name; - std::env::var(key).map_or(false, |value| value != "0") + std::env::var(key).is_ok_and(|value| value != "0") } #[must_use] fn testing() -> bool { - std::env::var(OPENAI_API_KEY).map_or(false, |value| value.to_lowercase().contains("test")) + std::env::var(OPENAI_API_KEY).is_ok_and(|value| value.to_lowercase().contains("test")) } #[cfg(test)] diff --git a/examples/general/abs_home_path/src/lib.rs b/examples/general/abs_home_path/src/lib.rs index 88e9b0b02..3928578ad 100644 --- a/examples/general/abs_home_path/src/lib.rs +++ b/examples/general/abs_home_path/src/lib.rs @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for AbsHomePath { .home .get_or_init(home::home_dir) .as_ref() - .map_or(false, |dir| path.starts_with(dir)) + .is_some_and(|dir| path.starts_with(dir)) { span_lint( cx, diff --git a/examples/general/non_local_effect_before_error_return/src/lib.rs b/examples/general/non_local_effect_before_error_return/src/lib.rs index eaaf4139c..00a695ba2 100644 --- a/examples/general/non_local_effect_before_error_return/src/lib.rs +++ b/examples/general/non_local_effect_before_error_return/src/lib.rs @@ -210,7 +210,7 @@ fn in_async_function(tcx: ty::TyCtxt<'_>, hir_id: rustc_hir::HirId) -> bool { .chain(tcx.hir().parent_iter(hir_id)) .any(|(_, node)| { node.fn_kind() - .map_or(false, |fn_kind| fn_kind.asyncness().is_async()) + .is_some_and(|fn_kind| fn_kind.asyncness().is_async()) }) } @@ -237,7 +237,7 @@ fn is_call_with_mut_ref<'tcx>( .. } = &terminator.kind // smoelius: `deref_mut` generates too much noise. - && func.const_fn_def().map_or(true, |(def_id, _)| { + && func.const_fn_def().is_none_or(|(def_id, _)| { !cx.tcx.is_diagnostic_item(sym::deref_mut_method, def_id) }) && let (locals, constants) = collect_locals_and_constants(cx, mir, path, args.iter().map(|arg| &arg.node)) @@ -314,12 +314,12 @@ fn collect_locals_and_constants<'tcx>( && let followed_widely = locals_widely.remove(destination.local) && (followed_narrowly || followed_widely) { - let width_preserving = func.const_fn_def().map_or(false, |(def_id, _)| { + let width_preserving = func.const_fn_def().is_some_and(|(def_id, _)| { WIDTH_PRESERVING .iter() .any(|path| match_def_path(cx, def_id, path)) }); - let widening = func.const_fn_def().map_or(false, |(def_id, _)| { + let widening = func.const_fn_def().is_some_and(|(def_id, _)| { WIDENING.iter().any(|path| match_def_path(cx, def_id, path)) }); for arg in args { @@ -430,7 +430,7 @@ fn error_note(span: Option) -> impl FnOnce(&mut Diag<'_, ()>) { #[must_use] fn enabled(opt: &str) -> bool { let key = env!("CARGO_PKG_NAME").to_uppercase() + "_" + opt; - std::env::var(key).map_or(false, |value| value != "0") + std::env::var(key).is_ok_and(|value| value != "0") } #[test] diff --git a/examples/restriction/collapsible_unwrap/src/lib.rs b/examples/restriction/collapsible_unwrap/src/lib.rs index b78583659..61b67950b 100644 --- a/examples/restriction/collapsible_unwrap/src/lib.rs +++ b/examples/restriction/collapsible_unwrap/src/lib.rs @@ -95,7 +95,7 @@ impl CollapsibleUnwrap { let needs_mut = cx .typeck_results() .type_dependent_def_id(expr.hir_id) - .map_or(false, |def_id| has_ref_mut_self(cx, def_id)); + .is_some_and(|def_id| has_ref_mut_self(cx, def_id)); let recv_ty = cx.typeck_results().expr_ty(recv); let name = suggest_name_from_type(cx, recv_ty); recv = inner_recv; diff --git a/examples/restriction/inconsistent_qualification/src/lib.rs b/examples/restriction/inconsistent_qualification/src/lib.rs index ae45a1350..6a6b6ecef 100644 --- a/examples/restriction/inconsistent_qualification/src/lib.rs +++ b/examples/restriction/inconsistent_qualification/src/lib.rs @@ -232,7 +232,7 @@ impl<'tcx> Visitor<'tcx> for UseVisitor<'_, 'tcx, '_> { } fn is_local(res: Res) -> bool { - res.opt_def_id().map_or(false, DefId::is_local) + res.opt_def_id().is_some_and(DefId::is_local) } fn get_owner(tcx: TyCtxt<'_>, hir_id: HirId) -> Option> { diff --git a/examples/restriction/overscoped_allow/src/lib.rs b/examples/restriction/overscoped_allow/src/lib.rs index d1fba8a08..e9680a071 100644 --- a/examples/restriction/overscoped_allow/src/lib.rs +++ b/examples/restriction/overscoped_allow/src/lib.rs @@ -382,7 +382,7 @@ fn include_trailing_semicolons(cx: &LateContext<'_>, mut span: Span) -> Span { }; while span.hi() < file.end_position() { let next = span.with_hi(span.hi() + BytePos(1)); - if !snippet_opt(cx, next).map_or(false, |snip| snip.ends_with(';')) { + if !snippet_opt(cx, next).is_some_and(|snip| snip.ends_with(';')) { break; } span = next; @@ -456,8 +456,7 @@ fn can_have_attrs(cx: &LateContext<'_>, hir_id: HirId) -> bool { } fn is_lint_attr(attr: &Attribute) -> bool { - attr.ident() - .map_or(false, |ident| is_lint_level(ident.name)) + attr.ident().is_some_and(|ident| is_lint_level(ident.name)) } // smoelius: `is_lint_level` was copied from: diff --git a/examples/supplementary/unnecessary_borrow_mut/src/lib.rs b/examples/supplementary/unnecessary_borrow_mut/src/lib.rs index 3cbf6613a..50139e747 100644 --- a/examples/supplementary/unnecessary_borrow_mut/src/lib.rs +++ b/examples/supplementary/unnecessary_borrow_mut/src/lib.rs @@ -224,7 +224,7 @@ impl<'tcx> Visitor<'tcx> for V<'tcx> { #[must_use] fn enabled(opt: &str) -> bool { let key = env!("CARGO_PKG_NAME").to_uppercase() + "_" + opt; - std::env::var(key).map_or(false, |value| value != "0") + std::env::var(key).is_ok_and(|value| value != "0") } #[test] diff --git a/examples/supplementary/unnecessary_conversion_for_trait/src/check_inherents.rs b/examples/supplementary/unnecessary_conversion_for_trait/src/check_inherents.rs index b96a8ec38..4711a3fad 100644 --- a/examples/supplementary/unnecessary_conversion_for_trait/src/check_inherents.rs +++ b/examples/supplementary/unnecessary_conversion_for_trait/src/check_inherents.rs @@ -55,7 +55,7 @@ pub fn check_inherents(cx: &LateContext<'_>) { let ty = peel_unwanted(cx, def_id, ty); ty.is_slice() || ty.is_str() - || ty.ty_adt_def().map_or(false, |adt_def| { + || ty.ty_adt_def().is_some_and(|adt_def| { type_paths .iter() .any(|path| match_def_path(cx, adt_def.did(), path)) diff --git a/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs b/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs index 39c678bca..0c785b5b4 100644 --- a/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs +++ b/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs @@ -706,7 +706,7 @@ fn build_ty_and_refs_prefix<'tcx>( #[must_use] fn enabled(name: &str) -> bool { let key = option(name); - std::env::var(key).map_or(false, |value| value != "0") + std::env::var(key).is_ok_and(|value| value != "0") } fn option(name: &str) -> String { diff --git a/internal/src/env.rs b/internal/src/env.rs index b58057d94..9abac8bdc 100644 --- a/internal/src/env.rs +++ b/internal/src/env.rs @@ -56,7 +56,7 @@ declare_const!(TARGET); /// ``` #[must_use] pub fn enabled(key: &str) -> bool { - std::env::var(key).map_or(false, |value| value != "0") + std::env::var(key).is_ok_and(|value| value != "0") } /// A wrapper around `std::env::var` that converts the error into an `anyhow::Error`. diff --git a/utils/testing/src/lib.rs b/utils/testing/src/lib.rs index c71291577..abb9d8524 100644 --- a/utils/testing/src/lib.rs +++ b/utils/testing/src/lib.rs @@ -337,7 +337,7 @@ fn rustc_flags(metadata: &Metadata, package: &Package, target: &Target) -> Resul .split(' ') .map(ToOwned::to_owned) .collect::>(); - if args.first().map_or(false, is_rustc) + if args.first().is_some_and(is_rustc) && args .as_slice() .windows(2)