Skip to content

Commit

Permalink
Make Clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Dec 2, 2024
1 parent 9e398f1 commit c93e4eb
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cargo-dylint/tests/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>())
.unwrap()
Expand Down
7 changes: 4 additions & 3 deletions driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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((
Expand Down Expand Up @@ -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<Lint>, after: &BTreeSet<Lint>) {
Expand Down Expand Up @@ -389,6 +388,8 @@ fn rustc_args<T: AsRef<OsStr>, U: AsRef<str>, V: AsRef<Path>>(
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());
}
Expand Down
2 changes: 1 addition & 1 deletion dylint/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions examples/experimental/missing_doc_comment_openai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion examples/general/abs_home_path/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions examples/general/non_local_effect_before_error_return/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}

Expand All @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -430,7 +430,7 @@ fn error_note(span: Option<Span>) -> 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]
Expand Down
2 changes: 1 addition & 1 deletion examples/restriction/collapsible_unwrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/restriction/inconsistent_qualification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnerNode<'_>> {
Expand Down
5 changes: 2 additions & 3 deletions examples/restriction/overscoped_allow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/supplementary/unnecessary_borrow_mut/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion utils/testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fn rustc_flags(metadata: &Metadata, package: &Package, target: &Target) -> Resul
.split(' ')
.map(ToOwned::to_owned)
.collect::<Vec<_>>();
if args.first().map_or(false, is_rustc)
if args.first().is_some_and(is_rustc)
&& args
.as_slice()
.windows(2)
Expand Down

0 comments on commit c93e4eb

Please sign in to comment.