cargo clippy --fix

This commit is contained in:
Johann Hemmann 2024-01-18 13:59:49 +01:00
parent 1ab8c7fd27
commit fad4fa163c
178 changed files with 595 additions and 738 deletions

View file

@ -441,7 +441,7 @@ impl CargoWorkspace {
.collect::<Vec<ManifestPath>>();
// some packages has this pkg as dep. return their manifests
if parent_manifests.len() > 0 {
if !parent_manifests.is_empty() {
return Some(parent_manifests);
}

View file

@ -36,7 +36,7 @@ impl ManifestPath {
}
pub fn canonicalize(&self) -> ! {
(&**self).canonicalize()
self.canonicalize()
}
}

View file

@ -201,7 +201,7 @@ impl Sysroot {
e
});
if let Err(e) =
std::fs::remove_file(&format!("{sysroot_src_dir}/sysroot/Cargo.lock"))
std::fs::remove_file(format!("{sysroot_src_dir}/sysroot/Cargo.lock"))
{
tracing::error!(
"failed to remove sysroot `{sysroot_src_dir}/sysroot/Cargo.lock`: {}",
@ -268,11 +268,8 @@ impl Sysroot {
res.workspace_members = res
.packages
.iter()
.filter_map(|package| {
RELEVANT_SYSROOT_CRATES
.contains(&&*package.name)
.then(|| package.id.clone())
})
.filter(|&package| RELEVANT_SYSROOT_CRATES.contains(&&*package.name))
.map(|package| package.id.clone())
.collect();
let cargo_workspace = CargoWorkspace::new(res);
Some(Sysroot {

View file

@ -106,7 +106,7 @@ fn replace_fake_sys_root(s: &mut String) {
let fake_sysroot_path = get_test_path("fake-sysroot");
let fake_sysroot_path = if cfg!(windows) {
let normalized_path =
fake_sysroot_path.to_str().expect("expected str").replace(r#"\"#, r#"\\"#);
fake_sysroot_path.to_str().expect("expected str").replace('\\', r#"\\"#);
format!(r#"{}\\"#, normalized_path)
} else {
format!("{}/", fake_sysroot_path.to_str().expect("expected str"))

View file

@ -38,7 +38,7 @@ pub struct CfgOverrides {
impl CfgOverrides {
pub fn len(&self) -> usize {
self.global.len() + self.selective.iter().map(|(_, it)| it.len()).sum::<usize>()
self.global.len() + self.selective.values().map(|it| it.len()).sum::<usize>()
}
}
@ -177,7 +177,7 @@ impl ProjectWorkspace {
};
let res = match manifest {
ProjectManifest::ProjectJson(project_json) => {
let file = fs::read_to_string(&project_json)
let file = fs::read_to_string(project_json)
.with_context(|| format!("Failed to read json file {project_json}"))?;
let data = serde_json::from_str(&file)
.with_context(|| format!("Failed to deserialize json file {project_json}"))?;
@ -194,7 +194,7 @@ impl ProjectWorkspace {
ProjectManifest::CargoToml(cargo_toml) => {
let toolchain = version(cargo_toml.parent(), toolchain::cargo(), "cargo ")?;
let meta = CargoWorkspace::fetch_metadata(
&cargo_toml,
cargo_toml,
cargo_toml.parent(),
config,
progress,
@ -241,7 +241,7 @@ impl ProjectWorkspace {
.map_err(|p| Some(format!("rustc source path is not absolute: {p}"))),
Some(RustLibSource::Discover) => {
sysroot.as_ref().ok().and_then(Sysroot::discover_rustc_src).ok_or_else(
|| Some(format!("Failed to discover rustc source for sysroot.")),
|| Some("Failed to discover rustc source for sysroot.".to_string()),
)
}
None => Err(None),
@ -287,7 +287,7 @@ impl ProjectWorkspace {
let cfg_overrides = config.cfg_overrides.clone();
let data_layout = target_data_layout::get(
Some(&cargo_toml),
Some(cargo_toml),
config.target.as_deref(),
&config.extra_env,
);