From ff1d86a5910ad126fe93d3ada967bb5e35d4c3aa Mon Sep 17 00:00:00 2001 From: Will Bush Date: Fri, 8 Nov 2024 06:30:54 -0600 Subject: [PATCH] lint: fix clippy::option_if_let_else --- src/eval.rs | 17 +++++++---------- src/problem/npv_160.rs | 8 +++----- src/problem/npv_161.rs | 8 +++----- src/problem/npv_162.rs | 8 +++----- src/problem/npv_163.rs | 8 +++----- 5 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/eval.rs b/src/eval.rs index 49ca339..fe25c4b 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -314,16 +314,13 @@ fn by_name( // An automatic `callPackage` by the `pkgs/by-name` overlay. // Though this gets detected by checking whether the internal // `_internalCallByNamePackageFile` was used - DefinitionVariant::AutoDefinition => { - if let Some(_location) = location { - // Such an automatic definition should definitely not have a location. - // Having one indicates that somebody is using - // `_internalCallByNamePackageFile`, - npv_102::ByNameInternalCallPackageUsed::new(attribute_name).into() - } else { - Success(Tight) - } - } + DefinitionVariant::AutoDefinition => location.map_or_else( + || Success(Tight), + // Such an automatic definition should definitely not have a location. + // Having one indicates that somebody is using + // `_internalCallByNamePackageFile`, + |_location| npv_102::ByNameInternalCallPackageUsed::new(attribute_name).into(), + ), // The attribute is manually defined, e.g. in `all-packages.nix`. // This means we need to enforce it to look like this: // callPackage ../pkgs/by-name/fo/foo/package.nix { ... } diff --git a/src/problem/npv_160.rs b/src/problem/npv_160.rs index 9bf9571..5c8b7f6 100644 --- a/src/problem/npv_160.rs +++ b/src/problem/npv_160.rs @@ -24,11 +24,9 @@ impl fmt::Display for TopLevelPackageMovedOutOfByName { file, } = self; let relative_package_file = structure::relative_file_for_package(package_name); - let call_package_arg = if let Some(path) = call_package_path { - format!("./{}", path) - } else { - "...".into() - }; + let call_package_arg = call_package_path + .as_ref() + .map_or_else(|| "...".into(), |path| format!("./{}", path)); writedoc!( f, " diff --git a/src/problem/npv_161.rs b/src/problem/npv_161.rs index 36f5dbc..6dc7a66 100644 --- a/src/problem/npv_161.rs +++ b/src/problem/npv_161.rs @@ -24,11 +24,9 @@ impl fmt::Display for TopLevelPackageMovedOutOfByNameWithCustomArguments { file, } = self; let relative_package_file = structure::relative_file_for_package(package_name); - let call_package_arg = if let Some(path) = call_package_path { - format!("./{}", path) - } else { - "...".into() - }; + let call_package_arg = call_package_path + .as_ref() + .map_or_else(|| "...".into(), |path| format!("./{}", path)); writedoc!( f, " diff --git a/src/problem/npv_162.rs b/src/problem/npv_162.rs index 0e3dae3..cbc4708 100644 --- a/src/problem/npv_162.rs +++ b/src/problem/npv_162.rs @@ -24,11 +24,9 @@ impl fmt::Display for NewTopLevelPackageShouldBeByName { file, } = self; let relative_package_file = structure::relative_file_for_package(package_name); - let call_package_arg = if let Some(path) = call_package_path { - format!("./{}", path) - } else { - "...".into() - }; + let call_package_arg = call_package_path + .as_ref() + .map_or_else(|| "...".into(), |path| format!("./{}", path)); writedoc!( f, " diff --git a/src/problem/npv_163.rs b/src/problem/npv_163.rs index dde218a..81278e6 100644 --- a/src/problem/npv_163.rs +++ b/src/problem/npv_163.rs @@ -24,11 +24,9 @@ impl fmt::Display for NewTopLevelPackageShouldBeByNameWithCustomArgument { file, } = self; let relative_package_file = structure::relative_file_for_package(package_name); - let call_package_arg = if let Some(path) = call_package_path { - format!("./{}", path) - } else { - "...".into() - }; + let call_package_arg = call_package_path + .as_ref() + .map_or_else(|| "...".into(), |path| format!("./{}", path)); writedoc!( f, "