Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatic clippy fixes #470

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/rattler_conda_types/benches/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Version>())
b.iter(|| black_box("3.11.4").parse::<Version>());
});
c.bench_function("parse complex version", |b| {
b.iter(|| black_box("1!1.0b2.post345.dev456+3.2.20.rc3").parse::<Version>())
b.iter(|| black_box("1!1.0b2.post345.dev456+3.2.20.rc3").parse::<Version>());
});
c.bench_function("parse logical constraint", |b| {
b.iter(|| black_box(">=3.1").parse::<Version>())
b.iter(|| black_box(">=3.1").parse::<Version>());
});
c.bench_function("parse wildcard constraint", |b| {
b.iter(|| black_box("3.1.*").parse::<Version>())
b.iter(|| black_box("3.1.*").parse::<Version>());
});
c.bench_function("parse simple version spec", |b| {
b.iter(|| black_box(">=3.1").parse::<Version>())
b.iter(|| black_box(">=3.1").parse::<Version>());
});
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::<Version>())
b.iter(|| black_box("(>=2.1.0,<3.0)|(~=3.2.1,~3.2.2.1)|(==4.1)").parse::<Version>());
});
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_conda_types/src/package/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/rattler_conda_types/src/repo_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
}
}
4 changes: 2 additions & 2 deletions crates/rattler_conda_types/src/version/bump.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions crates/rattler_index/tests/test_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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")
Expand All @@ -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);
}
34 changes: 17 additions & 17 deletions crates/rattler_lock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()
);
assert_yaml_snapshot!(
conda_lock
.packages_for_platform(Platform::Osx64)
.collect::<Vec<_>>()
);
assert_yaml_snapshot!(
conda_lock
.packages_for_platform(Platform::OsxArm64)
.collect::<Vec<_>>()
);
})
assert_yaml_snapshot!(
conda_lock
.packages_for_platform(Platform::Linux64)
.collect::<Vec<_>>()
);
assert_yaml_snapshot!(
conda_lock
.packages_for_platform(Platform::Osx64)
.collect::<Vec<_>>()
);
assert_yaml_snapshot!(
conda_lock
.packages_for_platform(Platform::OsxArm64)
.collect::<Vec<_>>()
);
});
}

#[test]
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_package_streaming/tests/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn compare_two_tar_archives<T: Read>(
.filter(|(k, _)| !k.starts_with(&info_licenses))
.collect::<HashMap<_, _>>();
}
_ => {}
FilterFiles::None => {}
}

assert_eq!(map1.len(), map2.len());
Expand Down
28 changes: 11 additions & 17 deletions crates/rattler_repodata_gateway/src/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ mod test {
server.url(),
AuthenticatedClient::default(),
cache_dir.into_path(),
Default::default(),
FetchRepoDataOptions::default(),
None,
)
.await
Expand Down Expand Up @@ -1167,7 +1167,7 @@ mod test {
server.url(),
AuthenticatedClient::default(),
cache_dir.path().to_owned(),
Default::default(),
FetchRepoDataOptions::default(),
None,
)
.await
Expand All @@ -1180,7 +1180,7 @@ mod test {
server.url(),
AuthenticatedClient::default(),
cache_dir.path().to_owned(),
Default::default(),
FetchRepoDataOptions::default(),
None,
)
.await
Expand All @@ -1204,7 +1204,7 @@ mod test {
server.url(),
AuthenticatedClient::default(),
cache_dir.into_path(),
Default::default(),
FetchRepoDataOptions::default(),
None,
)
.await
Expand Down Expand Up @@ -1233,7 +1233,7 @@ mod test {
server.url(),
AuthenticatedClient::default(),
cache_dir.into_path(),
Default::default(),
FetchRepoDataOptions::default(),
None,
)
.await
Expand Down Expand Up @@ -1275,7 +1275,7 @@ mod test {
server.url(),
AuthenticatedClient::default(),
cache_dir.into_path(),
Default::default(),
FetchRepoDataOptions::default(),
None,
)
.await
Expand Down Expand Up @@ -1324,7 +1324,7 @@ mod test {
server.url(),
AuthenticatedClient::default(),
cache_dir.into_path(),
Default::default(),
FetchRepoDataOptions::default(),
None,
)
.await
Expand Down Expand Up @@ -1375,7 +1375,7 @@ mod test {
server.url(),
authenticated_client,
cache_dir.into_path(),
Default::default(),
FetchRepoDataOptions::default(),
None,
)
.await
Expand Down Expand Up @@ -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
Expand All @@ -1433,9 +1431,7 @@ mod test {
.unwrap(),
AuthenticatedClient::default(),
cache_dir.into_path(),
FetchRepoDataOptions {
..Default::default()
},
FetchRepoDataOptions::default(),
None,
)
.await;
Expand All @@ -1457,9 +1453,7 @@ mod test {
server.url(),
AuthenticatedClient::default(),
cache_dir.into_path(),
FetchRepoDataOptions {
..Default::default()
},
FetchRepoDataOptions::default(),
None,
)
.await;
Expand Down
3 changes: 1 addition & 2 deletions crates/rattler_repodata_gateway/src/utils/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/rattler_shell/src/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions crates/rattler_solve/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn bench_solve_environment(c: &mut Criterion, specs: Vec<&str>) {
specs: specs.clone(),
}))
.unwrap()
})
});
});

#[cfg(feature = "resolvo")]
Expand All @@ -81,7 +81,7 @@ fn bench_solve_environment(c: &mut Criterion, specs: Vec<&str>) {
specs: specs.clone(),
}))
.unwrap()
})
});
});

group.finish();
Expand Down
4 changes: 1 addition & 3 deletions crates/rattler_solve/src/libsolv_c/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand Down
11 changes: 6 additions & 5 deletions crates/rattler_virtual_packages/src/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ pub enum DetectLibCError {
/// the future.
#[cfg(unix)]
fn try_detect_libc_version() -> Result<Option<(String, Version)>, DetectLibCError> {
// GNU libc writes to stdout
static GNU_LIBC_RE: once_cell::sync::Lazy<regex::Regex> = 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.
Expand All @@ -47,10 +52,6 @@ fn try_detect_libc_version() -> Result<Option<(String, Version)>, DetectLibCErro

let stdout = String::from_utf8_lossy(&output.stdout);

// GNU libc writes to stdout
static GNU_LIBC_RE: once_cell::sync::Lazy<regex::Regex> = 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))
Expand All @@ -74,6 +75,6 @@ mod test {
#[cfg(unix)]
pub fn doesnt_crash() {
let version = super::try_detect_libc_version().unwrap();
println!("LibC {:?}", version);
println!("LibC {version:?}");
}
}
4 changes: 2 additions & 2 deletions crates/rattler_virtual_packages/src/osx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn try_detect_osx_version() -> Result<Option<Version>, 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()
Expand Down Expand Up @@ -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:?}");
}
}