From 4f72dc4a8b65ce4eb5313cd4fc20247247b901f6 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Mon, 8 Jan 2024 13:56:55 +0100 Subject: [PATCH 1/3] automatic clippy fixes --- crates/rattler_conda_types/src/package/paths.rs | 2 +- crates/rattler_conda_types/src/repo_data/mod.rs | 4 ++-- crates/rattler_conda_types/src/version/bump.rs | 4 ++-- crates/rattler_index/tests/test_index.rs | 6 +++--- crates/rattler_lock/src/lib.rs | 2 +- crates/rattler_solve/src/libsolv_c/input.rs | 4 +--- crates/rattler_virtual_packages/src/libc.rs | 2 +- crates/rattler_virtual_packages/src/osx.rs | 2 +- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/rattler_conda_types/src/package/paths.rs b/crates/rattler_conda_types/src/package/paths.rs index 785937b2a..0ec36d038 100644 --- a/crates/rattler_conda_types/src/package/paths.rs +++ b/crates/rattler_conda_types/src/package/paths.rs @@ -317,7 +317,7 @@ mod test { let mut paths = vec![]; for i in 0..15 { paths.push(PathsEntry { - relative_path: format!("rel\\path_{}", i).into(), + relative_path: format!("rel\\path_{i}").into(), path_type: super::PathType::HardLink, prefix_placeholder: None, no_link: false, diff --git a/crates/rattler_conda_types/src/repo_data/mod.rs b/crates/rattler_conda_types/src/repo_data/mod.rs index ddca86c44..b21864900 100644 --- a/crates/rattler_conda_types/src/repo_data/mod.rs +++ b/crates/rattler_conda_types/src/repo_data/mod.rs @@ -453,7 +453,7 @@ mod test { conda_packages: FxHashMap::default(), removed: ["xyz", "foo", "bar", "baz", "qux", "aux", "quux"] .iter() - .map(|s| s.to_string()) + .map(|s| (*s).to_string()) .collect(), }; insta::assert_yaml_snapshot!(repodata); @@ -540,6 +540,6 @@ mod test { let test_data_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../test-data"); let data_path = test_data_path.join(path); - RepoData::from_path(&data_path).unwrap() + RepoData::from_path(data_path).unwrap() } } diff --git a/crates/rattler_conda_types/src/version/bump.rs b/crates/rattler_conda_types/src/version/bump.rs index 4c620bf71..2f9722e36 100644 --- a/crates/rattler_conda_types/src/version/bump.rs +++ b/crates/rattler_conda_types/src/version/bump.rs @@ -1,6 +1,6 @@ use thiserror::Error; -/// VersionBumpType is used to specify the type of bump to perform on a version. +/// `VersionBumpType` is used to specify the type of bump to perform on a version. #[derive(Clone)] pub enum VersionBumpType { /// Bump the major version number. @@ -15,7 +15,7 @@ pub enum VersionBumpType { Segment(i32), } -/// VersionBumpError is used to specify the type of error that occurred when bumping a version. +/// `VersionBumpError` is used to specify the type of error that occurred when bumping a version. #[derive(Error, Debug, PartialEq)] pub enum VersionBumpError { /// Cannot bump the major segment of a version with less than 1 segment. diff --git a/crates/rattler_index/tests/test_index.rs b/crates/rattler_index/tests/test_index.rs index 005b707fc..afffb3329 100644 --- a/crates/rattler_index/tests/test_index.rs +++ b/crates/rattler_index/tests/test_index.rs @@ -23,7 +23,7 @@ fn test_index() { .unwrap(); let res = index(temp_dir.path(), Some(&Platform::Win64)); - assert_eq!(res.is_ok(), true); + assert!(res.is_ok()); let repodata_path = temp_dir.path().join(subdir_path).join("repodata.json"); let repodata_json: Value = serde_json::from_reader(File::open(repodata_path).unwrap()).unwrap(); @@ -41,7 +41,7 @@ fn test_index() { .as_str(), Some("win-64") ); - assert_eq!(repodata_json.get("packages").is_some(), true); + assert!(repodata_json.get("packages").is_some()); assert_eq!( repodata_json .get("packages.conda") @@ -56,6 +56,6 @@ fn test_index() { fn test_index_empty_directory() { let temp_dir = tempfile::tempdir().unwrap(); let res = index(temp_dir.path(), None); - assert_eq!(res.is_ok(), true); + assert!(res.is_ok()); assert_eq!(fs::read_dir(temp_dir).unwrap().count(), 0); } diff --git a/crates/rattler_lock/src/lib.rs b/crates/rattler_lock/src/lib.rs index da17c6f1f..addae17c2 100644 --- a/crates/rattler_lock/src/lib.rs +++ b/crates/rattler_lock/src/lib.rs @@ -349,7 +349,7 @@ mod test { assert_eq!(result.name, "ncurses"); assert_eq!(result.version.as_str(), "6.4"); - let repodata_record = RepoDataRecord::try_from(result.clone()).unwrap(); + let repodata_record = RepoDataRecord::try_from(result).unwrap(); assert_eq!( repodata_record.package_record.name.as_normalized(), diff --git a/crates/rattler_solve/src/libsolv_c/input.rs b/crates/rattler_solve/src/libsolv_c/input.rs index 3b307b00f..2736452fc 100644 --- a/crates/rattler_solve/src/libsolv_c/input.rs +++ b/crates/rattler_solve/src/libsolv_c/input.rs @@ -307,9 +307,7 @@ pub fn cache_repodata(url: String, data: &[RepoDataRecord]) -> LibcByteSlice { let mut stream_ptr = std::ptr::null_mut(); let mut stream_size = 0; let file = unsafe { libc::open_memstream(&mut stream_ptr, &mut stream_size) }; - if file.is_null() { - panic!("unable to open memstream"); - } + assert!(!file.is_null(), "unable to open memstream"); repo.write(&pool, file); unsafe { libc::fclose(file) }; diff --git a/crates/rattler_virtual_packages/src/libc.rs b/crates/rattler_virtual_packages/src/libc.rs index a20602a7e..1ca156a86 100644 --- a/crates/rattler_virtual_packages/src/libc.rs +++ b/crates/rattler_virtual_packages/src/libc.rs @@ -74,6 +74,6 @@ mod test { #[cfg(unix)] pub fn doesnt_crash() { let version = super::try_detect_libc_version().unwrap(); - println!("LibC {:?}", version); + println!("LibC {version:?}"); } } diff --git a/crates/rattler_virtual_packages/src/osx.rs b/crates/rattler_virtual_packages/src/osx.rs index 39977a703..02e2f7018 100644 --- a/crates/rattler_virtual_packages/src/osx.rs +++ b/crates/rattler_virtual_packages/src/osx.rs @@ -66,6 +66,6 @@ mod test { #[cfg(target_os = "macos")] pub fn doesnt_crash() { let version = super::try_detect_osx_version(); - println!("MacOS version {:?}", version); + println!("MacOS version {version:?}"); } } From e15f1c8e434563cff144db64a65f073377862b68 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Mon, 8 Jan 2024 13:59:28 +0100 Subject: [PATCH 2/3] fix more clippy issues --- crates/rattler_repodata_gateway/src/utils/flock.rs | 3 +-- crates/rattler_virtual_packages/src/libc.rs | 9 +++++---- crates/rattler_virtual_packages/src/osx.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/rattler_repodata_gateway/src/utils/flock.rs b/crates/rattler_repodata_gateway/src/utils/flock.rs index 9d2b3e366..0bf5b5a9d 100644 --- a/crates/rattler_repodata_gateway/src/utils/flock.rs +++ b/crates/rattler_repodata_gateway/src/utils/flock.rs @@ -302,8 +302,7 @@ mod sys { // Unfortunately, depending on the target, these may or may not be the same. // For targets in which they are the same, the duplicate pattern causes a warning. #[allow(unreachable_patterns)] - Some(libc::ENOTSUP | libc::EOPNOTSUPP) => true, - Some(libc::ENOSYS) => true, + Some(libc::ENOTSUP | libc::EOPNOTSUPP | libc::ENOSYS) => true, _ => false, } } diff --git a/crates/rattler_virtual_packages/src/libc.rs b/crates/rattler_virtual_packages/src/libc.rs index 1ca156a86..cd615f03b 100644 --- a/crates/rattler_virtual_packages/src/libc.rs +++ b/crates/rattler_virtual_packages/src/libc.rs @@ -32,6 +32,11 @@ pub enum DetectLibCError { /// the future. #[cfg(unix)] fn try_detect_libc_version() -> Result, DetectLibCError> { + // GNU libc writes to stdout + static GNU_LIBC_RE: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| { + regex::Regex::new("(?mi)(?:glibc|gnu libc).*?([0-9]+(:?.[0-9]+)*)$").unwrap() + }); + // Run `ldd --version` to detect the libc version and family on the system. `ldd` is shipped // with libc so if an error occured during its execution we can assume no libc is available on // the system. @@ -47,10 +52,6 @@ fn try_detect_libc_version() -> Result, DetectLibCErro let stdout = String::from_utf8_lossy(&output.stdout); - // GNU libc writes to stdout - static GNU_LIBC_RE: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| { - regex::Regex::new("(?mi)(?:glibc|gnu libc).*?([0-9]+(:?.[0-9]+)*)$").unwrap() - }); if let Some(version_match) = GNU_LIBC_RE .captures(&stdout) .and_then(|captures| captures.get(1)) diff --git a/crates/rattler_virtual_packages/src/osx.rs b/crates/rattler_virtual_packages/src/osx.rs index 02e2f7018..2453fe575 100644 --- a/crates/rattler_virtual_packages/src/osx.rs +++ b/crates/rattler_virtual_packages/src/osx.rs @@ -23,7 +23,7 @@ fn try_detect_osx_version() -> Result, ParseOsxVersionError> { .map_err(ParseOsxVersionError::FailedToReadSystemVersion)?; let cur = std::io::Cursor::new(file.as_bytes()); let v = - plist::Value::from_reader(cur).map_err(|_| ParseOsxVersionError::CorruptedDictionary)?; + plist::Value::from_reader(cur).map_err(|_err| ParseOsxVersionError::CorruptedDictionary)?; let version = v .as_dictionary() From 18ab9c1e8bc2fba7495294fd4dfe2172de97ef21 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Mon, 8 Jan 2024 14:23:40 +0100 Subject: [PATCH 3/3] more manual clippy fixes --- crates/rattler_conda_types/benches/parse.rs | 12 +++---- crates/rattler_lock/src/lib.rs | 32 +++++++++---------- .../rattler_package_streaming/tests/write.rs | 2 +- .../rattler_repodata_gateway/src/fetch/mod.rs | 28 +++++++--------- crates/rattler_shell/src/activation.rs | 12 +++---- crates/rattler_solve/benches/bench.rs | 4 +-- 6 files changed, 42 insertions(+), 48 deletions(-) diff --git a/crates/rattler_conda_types/benches/parse.rs b/crates/rattler_conda_types/benches/parse.rs index acea3785f..9888d7641 100644 --- a/crates/rattler_conda_types/benches/parse.rs +++ b/crates/rattler_conda_types/benches/parse.rs @@ -3,22 +3,22 @@ use rattler_conda_types::Version; fn criterion_benchmark(c: &mut Criterion) { c.bench_function("parse simple version", |b| { - b.iter(|| black_box("3.11.4").parse::()) + b.iter(|| black_box("3.11.4").parse::()); }); c.bench_function("parse complex version", |b| { - b.iter(|| black_box("1!1.0b2.post345.dev456+3.2.20.rc3").parse::()) + b.iter(|| black_box("1!1.0b2.post345.dev456+3.2.20.rc3").parse::()); }); c.bench_function("parse logical constraint", |b| { - b.iter(|| black_box(">=3.1").parse::()) + b.iter(|| black_box(">=3.1").parse::()); }); c.bench_function("parse wildcard constraint", |b| { - b.iter(|| black_box("3.1.*").parse::()) + b.iter(|| black_box("3.1.*").parse::()); }); c.bench_function("parse simple version spec", |b| { - b.iter(|| black_box(">=3.1").parse::()) + b.iter(|| black_box(">=3.1").parse::()); }); c.bench_function("parse complex version spec", |b| { - b.iter(|| black_box("(>=2.1.0,<3.0)|(~=3.2.1,~3.2.2.1)|(==4.1)").parse::()) + b.iter(|| black_box("(>=2.1.0,<3.0)|(~=3.2.1,~3.2.2.1)|(==4.1)").parse::()); }); } diff --git a/crates/rattler_lock/src/lib.rs b/crates/rattler_lock/src/lib.rs index addae17c2..d7d0d4a64 100644 --- a/crates/rattler_lock/src/lib.rs +++ b/crates/rattler_lock/src/lib.rs @@ -303,22 +303,22 @@ mod test { // Make sure that we have parsed some packages assert!(!conda_lock.package.is_empty()); insta::with_settings!({sort_maps => true}, { - assert_yaml_snapshot!( - conda_lock - .packages_for_platform(Platform::Linux64) - .collect::>() - ); - assert_yaml_snapshot!( - conda_lock - .packages_for_platform(Platform::Osx64) - .collect::>() - ); - assert_yaml_snapshot!( - conda_lock - .packages_for_platform(Platform::OsxArm64) - .collect::>() - ); - }) + assert_yaml_snapshot!( + conda_lock + .packages_for_platform(Platform::Linux64) + .collect::>() + ); + assert_yaml_snapshot!( + conda_lock + .packages_for_platform(Platform::Osx64) + .collect::>() + ); + assert_yaml_snapshot!( + conda_lock + .packages_for_platform(Platform::OsxArm64) + .collect::>() + ); + }); } #[test] diff --git a/crates/rattler_package_streaming/tests/write.rs b/crates/rattler_package_streaming/tests/write.rs index f4b682d12..024dfd6b8 100644 --- a/crates/rattler_package_streaming/tests/write.rs +++ b/crates/rattler_package_streaming/tests/write.rs @@ -99,7 +99,7 @@ fn compare_two_tar_archives( .filter(|(k, _)| !k.starts_with(&info_licenses)) .collect::>(); } - _ => {} + FilterFiles::None => {} } assert_eq!(map1.len(), map2.len()); diff --git a/crates/rattler_repodata_gateway/src/fetch/mod.rs b/crates/rattler_repodata_gateway/src/fetch/mod.rs index 634ef8eba..a88205514 100644 --- a/crates/rattler_repodata_gateway/src/fetch/mod.rs +++ b/crates/rattler_repodata_gateway/src/fetch/mod.rs @@ -1137,7 +1137,7 @@ mod test { server.url(), AuthenticatedClient::default(), cache_dir.into_path(), - Default::default(), + FetchRepoDataOptions::default(), None, ) .await @@ -1167,7 +1167,7 @@ mod test { server.url(), AuthenticatedClient::default(), cache_dir.path().to_owned(), - Default::default(), + FetchRepoDataOptions::default(), None, ) .await @@ -1180,7 +1180,7 @@ mod test { server.url(), AuthenticatedClient::default(), cache_dir.path().to_owned(), - Default::default(), + FetchRepoDataOptions::default(), None, ) .await @@ -1204,7 +1204,7 @@ mod test { server.url(), AuthenticatedClient::default(), cache_dir.into_path(), - Default::default(), + FetchRepoDataOptions::default(), None, ) .await @@ -1233,7 +1233,7 @@ mod test { server.url(), AuthenticatedClient::default(), cache_dir.into_path(), - Default::default(), + FetchRepoDataOptions::default(), None, ) .await @@ -1275,7 +1275,7 @@ mod test { server.url(), AuthenticatedClient::default(), cache_dir.into_path(), - Default::default(), + FetchRepoDataOptions::default(), None, ) .await @@ -1324,7 +1324,7 @@ mod test { server.url(), AuthenticatedClient::default(), cache_dir.into_path(), - Default::default(), + FetchRepoDataOptions::default(), None, ) .await @@ -1375,7 +1375,7 @@ mod test { server.url(), authenticated_client, cache_dir.into_path(), - Default::default(), + FetchRepoDataOptions::default(), None, ) .await @@ -1408,9 +1408,7 @@ mod test { server.url(), AuthenticatedClient::default(), cache_dir.into_path(), - FetchRepoDataOptions { - ..Default::default() - }, + FetchRepoDataOptions::default(), Some(Box::new(download_progress)), ) .await @@ -1433,9 +1431,7 @@ mod test { .unwrap(), AuthenticatedClient::default(), cache_dir.into_path(), - FetchRepoDataOptions { - ..Default::default() - }, + FetchRepoDataOptions::default(), None, ) .await; @@ -1457,9 +1453,7 @@ mod test { server.url(), AuthenticatedClient::default(), cache_dir.into_path(), - FetchRepoDataOptions { - ..Default::default() - }, + FetchRepoDataOptions::default(), None, ) .await; diff --git a/crates/rattler_shell/src/activation.rs b/crates/rattler_shell/src/activation.rs index 7182dccd3..350f972e0 100644 --- a/crates/rattler_shell/src/activation.rs +++ b/crates/rattler_shell/src/activation.rs @@ -750,38 +750,38 @@ mod tests { #[test] #[cfg(windows)] fn test_run_activation_powershell() { - test_run_activation(crate::shell::PowerShell::default().into()) + test_run_activation(crate::shell::PowerShell::default().into()); } #[test] #[cfg(windows)] fn test_run_activation_cmd() { - test_run_activation(crate::shell::CmdExe::default().into()) + test_run_activation(crate::shell::CmdExe::default().into()); } #[test] #[cfg(unix)] fn test_run_activation_bash() { - test_run_activation(crate::shell::Bash::default().into()) + test_run_activation(crate::shell::Bash::default().into()); } #[test] #[cfg(target_os = "macos")] fn test_run_activation_zsh() { - test_run_activation(crate::shell::Zsh::default().into()) + test_run_activation(crate::shell::Zsh::default().into()); } #[test] #[cfg(unix)] #[ignore] fn test_run_activation_fish() { - test_run_activation(crate::shell::Fish::default().into()) + test_run_activation(crate::shell::Fish::default().into()); } #[test] #[cfg(unix)] #[ignore] fn test_run_activation_xonsh() { - test_run_activation(crate::shell::Xonsh::default().into()) + test_run_activation(crate::shell::Xonsh::default().into()); } } diff --git a/crates/rattler_solve/benches/bench.rs b/crates/rattler_solve/benches/bench.rs index fbb23927b..2ce89d258 100644 --- a/crates/rattler_solve/benches/bench.rs +++ b/crates/rattler_solve/benches/bench.rs @@ -66,7 +66,7 @@ fn bench_solve_environment(c: &mut Criterion, specs: Vec<&str>) { specs: specs.clone(), })) .unwrap() - }) + }); }); #[cfg(feature = "resolvo")] @@ -81,7 +81,7 @@ fn bench_solve_environment(c: &mut Criterion, specs: Vec<&str>) { specs: specs.clone(), })) .unwrap() - }) + }); }); group.finish();