Skip to content

Commit

Permalink
Fix clippy warnings for upcoming Rust 1.65.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Nov 2, 2022
1 parent ea5622a commit 5ed3ca9
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 56 deletions.
3 changes: 3 additions & 0 deletions src/auditwheel/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub fn find_versioned_libraries(elf: &Elf) -> Vec<VersionedLibrary> {
}

/// Find incompliant symbols from symbol versions
#[allow(clippy::result_large_err)]
fn find_incompliant_symbols(
elf: &Elf,
symbol_versions: &[String],
Expand All @@ -111,6 +112,7 @@ fn find_incompliant_symbols(
Ok(symbols)
}

#[allow(clippy::result_large_err)]
fn policy_is_satisfied(
policy: &Policy,
elf: &Elf,
Expand Down Expand Up @@ -253,6 +255,7 @@ fn get_default_platform_policies() -> Vec<Policy> {
/// a higher version would be possible.
///
/// Does nothing for `platform_tag` set to `Off`/`Linux` or non-linux platforms.
#[allow(clippy::result_large_err)]
pub fn auditwheel_rs(
artifact: &BuildArtifact,
target: &Target,
Expand Down
2 changes: 1 addition & 1 deletion src/auditwheel/musllinux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn find_musl_libc() -> Result<Option<PathBuf>> {
/// Dynamic Program Loader
pub fn get_musl_version(ld_path: impl AsRef<Path>) -> Result<Option<(u16, u16)>> {
let ld_path = ld_path.as_ref();
let output = Command::new(&ld_path)
let output = Command::new(ld_path)
.stdout(Stdio::null())
.stderr(Stdio::piped())
.output()?;
Expand Down
2 changes: 1 addition & 1 deletion src/auditwheel/patchelf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn set_rpath<S: AsRef<OsStr>>(file: impl AsRef<Path>, rpath: &S) -> Result<(
/// Get the `RPATH` of executables and libraries
pub fn get_rpath(file: impl AsRef<Path>) -> Result<Vec<String>> {
let file = file.as_ref();
let contents = fs_err::read(&file)?;
let contents = fs_err::read(file)?;
match goblin::Object::parse(&contents) {
Ok(goblin::Object::Elf(elf)) => {
let rpaths = if !elf.runpaths.is_empty() {
Expand Down
2 changes: 2 additions & 0 deletions src/auditwheel/repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use anyhow::Result;
use lddtree::DependencyAnalyzer;
use std::path::{Path, PathBuf};

/// Find external shared library dependencies
#[allow(clippy::result_large_err)]
pub fn find_external_libs(
artifact: impl AsRef<Path>,
policy: &Policy,
Expand Down
2 changes: 1 addition & 1 deletion src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ mod test {
.exec()
.unwrap();
let metadata21 =
Metadata21::from_cargo_toml(&cargo_toml, &"test-crates/pyo3-pure", &cargo_metadata)
Metadata21::from_cargo_toml(&cargo_toml, "test-crates/pyo3-pure", &cargo_metadata)
.unwrap();
assert_eq!(get_min_python_minor(&metadata21), None);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ fn compile_target(
/// Currently the check is only run on linux, macOS and Windows
pub fn warn_missing_py_init(artifact: &Path, module_name: &str) -> Result<()> {
let py_init = format!("PyInit_{}", module_name);
let mut fd = File::open(&artifact)?;
let mut fd = File::open(artifact)?;
let mut buffer = Vec::new();
fd.read_to_end(&mut buffer)?;
let mut found = false;
Expand Down
4 changes: 2 additions & 2 deletions src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn develop(
) -> Result<()> {
let mut target_triple = cargo_options.target.as_ref().map(|x| x.to_string());
let target = Target::from_target_triple(cargo_options.target)?;
let python = target.get_venv_python(&venv_dir);
let python = target.get_venv_python(venv_dir);

// check python platform and architecture
if !target.user_specified {
Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn develop(
"--force-reinstall",
];
let output = Command::new(&python)
.args(&command)
.args(command)
.arg(dunce::simplified(filename))
.output()
.context(format!("pip install failed with {:?}", python))?;
Expand Down
32 changes: 16 additions & 16 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl PathWriter {
/// Creates a [ModuleWriter] that adds the module to the current virtualenv
pub fn venv(target: &Target, venv_dir: &Path, bridge: &BridgeModel) -> Result<Self> {
let interpreter =
PythonInterpreter::check_executable(target.get_venv_python(&venv_dir), target, bridge)?
PythonInterpreter::check_executable(target.get_venv_python(venv_dir), target, bridge)?
.ok_or_else(|| {
anyhow!("Expected `python` to be a python interpreter inside a virtualenv ಠ_ಠ")
})?;
Expand Down Expand Up @@ -185,7 +185,7 @@ impl ModuleWriter for PathWriter {
file.write_all(bytes)
.context(format!("Failed to write to file at {}", path.display()))?;

let hash = base64::encode_config(&Sha256::digest(bytes), base64::URL_SAFE_NO_PAD);
let hash = base64::encode_config(Sha256::digest(bytes), base64::URL_SAFE_NO_PAD);
self.record.push((
target.as_ref().to_str().unwrap().to_owned(),
hash,
Expand Down Expand Up @@ -231,7 +231,7 @@ impl ModuleWriter for WheelWriter {
self.zip.start_file(target.clone(), options)?;
self.zip.write_all(bytes)?;

let hash = base64::encode_config(&Sha256::digest(bytes), base64::URL_SAFE_NO_PAD);
let hash = base64::encode_config(Sha256::digest(bytes), base64::URL_SAFE_NO_PAD);
self.record.push((target, hash, bytes.len()));

Ok(())
Expand Down Expand Up @@ -453,7 +453,7 @@ where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
Command::new(&python)
Command::new(python)
.args(args)
.output()
.context(format!("Failed to run python at {:?}", &python))
Expand All @@ -479,7 +479,7 @@ fn cffi_header(crate_dir: &Path, target_dir: &Path, tempdir: &TempDir) -> Result
);
}

let mut config = cbindgen::Config::from_root_or_default(&crate_dir);
let mut config = cbindgen::Config::from_root_or_default(crate_dir);
config.defines = HashMap::new();
config.include_guard = None;

Expand Down Expand Up @@ -534,7 +534,7 @@ recompiler.make_py_source(ffi, "ffi", r"{ffi_py}")
header = header.display(),
);

let output = call_python(python, &["-c", &cffi_invocation])?;
let output = call_python(python, ["-c", &cffi_invocation])?;
let install_cffi = if !output.status.success() {
// First, check whether the error was cffi not being installed
let last_line = str::from_utf8(&output.stderr)?.lines().last().unwrap_or("");
Expand All @@ -544,7 +544,7 @@ recompiler.make_py_source(ffi, "ffi", r"{ffi_py}")
// https://stackoverflow.com/a/42580137/3549270
let output = call_python(
python,
&["-c", "import sys\nprint(sys.base_prefix != sys.prefix)"],
["-c", "import sys\nprint(sys.base_prefix != sys.prefix)"],
)?;

match str::from_utf8(&output.stdout)?.trim() {
Expand Down Expand Up @@ -575,7 +575,7 @@ recompiler.make_py_source(ffi, "ffi", r"{ffi_py}")
// are coming from different environments
let output = call_python(
python,
&[
[
"-m",
"pip",
"install",
Expand All @@ -595,7 +595,7 @@ recompiler.make_py_source(ffi, "ffi", r"{ffi_py}")
println!("🎁 Installed cffi");

// Try again
let output = call_python(python, &["-c", &cffi_invocation])?;
let output = call_python(python, ["-c", &cffi_invocation])?;
handle_cffi_call_result(python, tempdir, &ffi_py, &output)
}

Expand All @@ -618,7 +618,7 @@ fn handle_cffi_call_result(
// Don't swallow warnings
io::stderr().write_all(&output.stderr)?;

let ffi_py_content = fs::read_to_string(&ffi_py)?;
let ffi_py_content = fs::read_to_string(ffi_py)?;
tempdir.close()?;
Ok(ffi_py_content)
}
Expand Down Expand Up @@ -658,7 +658,7 @@ pub fn write_bindings_module(
let _ = fs::remove_file(&target);

debug!("Copying {} to {}", artifact.display(), target.display());
fs::copy(&artifact, &target).context(format!(
fs::copy(artifact, &target).context(format!(
"Failed to copy {} to {}",
artifact.display(),
target.display()
Expand All @@ -671,7 +671,7 @@ pub fn write_bindings_module(
.rust_module
.strip_prefix(python_module.parent().unwrap())
.unwrap();
writer.add_file_with_permissions(relative.join(&so_filename), &artifact, 0o755)?;
writer.add_file_with_permissions(relative.join(&so_filename), artifact, 0o755)?;
}
} else {
let module = PathBuf::from(module_name);
Expand All @@ -697,7 +697,7 @@ if hasattr({module_name}, "__all__"):
writer.add_file(&module.join("__init__.pyi"), type_stub)?;
writer.add_bytes(&module.join("py.typed"), b"")?;
}
writer.add_file_with_permissions(&module.join(so_filename), &artifact, 0o755)?;
writer.add_file_with_permissions(&module.join(so_filename), artifact, 0o755)?;
}

Ok(())
Expand Down Expand Up @@ -726,10 +726,10 @@ pub fn write_cffi_module(
}

if editable {
let base_path = python_module.join(&module_name);
let base_path = python_module.join(module_name);
fs::create_dir_all(&base_path)?;
let target = base_path.join("native.so");
fs::copy(&artifact, &target).context(format!(
fs::copy(artifact, &target).context(format!(
"Failed to copy {} to {}",
artifact.display(),
target.display()
Expand Down Expand Up @@ -762,7 +762,7 @@ pub fn write_cffi_module(
if !editable || project_layout.python_module.is_none() {
writer.add_bytes(&module.join("__init__.py"), cffi_init_file().as_bytes())?;
writer.add_bytes(&module.join("ffi.py"), cffi_declarations.as_bytes())?;
writer.add_file_with_permissions(&module.join("native.so"), &artifact, 0o755)?;
writer.add_file_with_permissions(&module.join("native.so"), artifact, 0o755)?;
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/project_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ impl ProjectResolver {
let cargo_metadata = Self::resolve_cargo_metadata(&manifest_file, &cargo_options)?;

let mut metadata21 =
Metadata21::from_cargo_toml(&cargo_toml, &manifest_dir, &cargo_metadata)
Metadata21::from_cargo_toml(&cargo_toml, manifest_dir, &cargo_metadata)
.context("Failed to parse Cargo.toml into python metadata")?;
if let Some(pyproject) = pyproject {
let pyproject_dir = pyproject_file.parent().unwrap();
metadata21.merge_pyproject_toml(&pyproject_dir, pyproject)?;
metadata21.merge_pyproject_toml(pyproject_dir, pyproject)?;
}
let extra_metadata = cargo_toml.remaining_core_metadata();

Expand Down Expand Up @@ -196,7 +196,7 @@ impl ProjectResolver {
let workspace_parent = workspace_root.parent().unwrap_or(&workspace_root);
for parent in path.ancestors().skip(1) {
// Allow looking outside to the parent directory of Cargo workspace root
if !dunce::simplified(parent).starts_with(&workspace_parent) {
if !dunce::simplified(parent).starts_with(workspace_parent) {
break;
}
let pyproject_file = parent.join(PYPROJECT_TOML);
Expand Down
2 changes: 1 addition & 1 deletion src/pyproject_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl PyProjectToml {
/// source distributions
pub fn new(pyproject_file: impl AsRef<Path>) -> Result<PyProjectToml> {
let path = pyproject_file.as_ref();
let contents = fs::read_to_string(&path)?;
let contents = fs::read_to_string(path)?;
let pyproject: PyProjectToml = toml_edit::easy::from_str(&contents)
.map_err(|err| format_err!("pyproject.toml is not PEP 517 compliant: {}", err))?;
Ok(pyproject)
Expand Down
10 changes: 5 additions & 5 deletions src/python_interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn find_all_windows(target: &Target, min_python_minor: usize) -> Result<Vec<Stri
let executable = capture.get(6).unwrap().as_str();
let version = format!("-{}.{}-{}", major, minor, pointer_width);
let output = Command::new(executable)
.args(&["-c", code])
.args(["-c", code])
.output()
.unwrap();
let path = str::from_utf8(&output.stdout).unwrap().trim();
Expand Down Expand Up @@ -231,7 +231,7 @@ fn find_all_windows(target: &Target, min_python_minor: usize) -> Result<Vec<Stri
}

fn windows_python_info(executable: &Path) -> Result<Option<InterpreterConfig>> {
let python_info = Command::new(&executable)
let python_info = Command::new(executable)
.arg("-c")
.arg("import sys; print(sys.version)")
.output();
Expand Down Expand Up @@ -546,8 +546,8 @@ impl PythonInterpreter {
target: &Target,
bridge: &BridgeModel,
) -> Result<Option<PythonInterpreter>> {
let output = Command::new(&executable.as_ref())
.args(&["-c", GET_INTERPRETER_METADATA])
let output = Command::new(executable.as_ref())
.args(["-c", GET_INTERPRETER_METADATA])
.output();

let err_msg = format!(
Expand Down Expand Up @@ -825,7 +825,7 @@ impl PythonInterpreter {
return true;
}
let out = Command::new(&self.executable)
.args(&[
.args([
"-m",
"pip",
"debug",
Expand Down
22 changes: 11 additions & 11 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn rewrite_cargo_toml(
root_crate: bool,
) -> Result<String> {
let manifest_path = manifest_path.as_ref();
let text = fs::read_to_string(&manifest_path).context(format!(
let text = fs::read_to_string(manifest_path).context(format!(
"Can't read Cargo.toml at {}",
manifest_path.display(),
))?;
Expand All @@ -63,7 +63,7 @@ fn rewrite_cargo_toml(
// ^^^^^^^^^^^^^^^^^^ table[&dep_name]["path"]
// ^^^^^^^^^^^^^ dep_name
for dep_category in &["dependencies", "dev-dependencies", "build-dependencies"] {
if let Some(table) = data.get_mut(*dep_category).and_then(|x| x.as_table_mut()) {
if let Some(table) = data.get_mut(dep_category).and_then(|x| x.as_table_mut()) {
let workspace_deps = workspace_manifest
.get("workspace")
.and_then(|x| x.get(dep_category))
Expand Down Expand Up @@ -253,7 +253,7 @@ fn add_crate_to_source_distribution(
let manifest_path = manifest_path.as_ref();
let pyproject_toml_path = pyproject_toml_path.as_ref();
let output = Command::new("cargo")
.args(&["package", "--list", "--allow-dirty", "--manifest-path"])
.args(["package", "--list", "--allow-dirty", "--manifest-path"])
.arg(manifest_path)
.output()
.with_context(|| {
Expand Down Expand Up @@ -283,7 +283,7 @@ fn add_crate_to_source_distribution(
let pyproject_dir = pyproject_toml_path.parent().unwrap();
let cargo_toml_in_subdir = root_crate
&& abs_manifest_dir != pyproject_dir
&& abs_manifest_dir.starts_with(&pyproject_dir);
&& abs_manifest_dir.starts_with(pyproject_dir);

// manifest_dir should be a relative path
let manifest_dir = manifest_path.parent().unwrap();
Expand All @@ -293,7 +293,7 @@ fn add_crate_to_source_distribution(
let relative_to_cwd = manifest_dir.join(relative_to_manifests);
if root_crate && cargo_toml_in_subdir {
let relative_to_project_root = abs_manifest_dir
.strip_prefix(&pyproject_dir)
.strip_prefix(pyproject_dir)
.unwrap()
.join(relative_to_manifests);
(relative_to_project_root, relative_to_cwd)
Expand Down Expand Up @@ -344,7 +344,7 @@ fn add_crate_to_source_distribution(
LOCAL_DEPENDENCIES_FOLDER.to_string()
};
let rewritten_cargo_toml = rewrite_cargo_toml(
&manifest_path,
manifest_path,
workspace_manifest,
known_path_deps,
local_deps_folder,
Expand Down Expand Up @@ -466,7 +466,7 @@ pub fn source_distribution(
add_crate_to_source_distribution(
&mut writer,
&pyproject_toml_path,
&path_dep,
path_dep,
path_dep_workspace_manifest,
&root_dir.join(LOCAL_DEPENDENCIES_FOLDER).join(name),
&known_path_deps,
Expand All @@ -483,7 +483,7 @@ pub fn source_distribution(
add_crate_to_source_distribution(
&mut writer,
&pyproject_toml_path,
&manifest_path,
manifest_path,
&workspace_manifest,
&root_dir,
&known_path_deps,
Expand All @@ -500,7 +500,7 @@ pub fn source_distribution(
let relative_cargo_lock = if cargo_lock_path.starts_with(project_root) {
cargo_lock_path.strip_prefix(project_root).unwrap()
} else {
cargo_lock_path.strip_prefix(&abs_manifest_dir).unwrap()
cargo_lock_path.strip_prefix(abs_manifest_dir).unwrap()
};
writer.add_file(root_dir.join(relative_cargo_lock), &cargo_lock_path)?;
} else {
Expand All @@ -527,7 +527,7 @@ pub fn source_distribution(
debug!("Ignoring {}", source.display());
continue;
}
let target = root_dir.join(source.strip_prefix(&pyproject_dir).unwrap());
let target = root_dir.join(source.strip_prefix(pyproject_dir).unwrap());
if source.is_dir() {
writer.add_directory(target)?;
} else {
Expand Down Expand Up @@ -557,7 +557,7 @@ pub fn source_distribution(
.expect("No files found for pattern")
.filter_map(Result::ok)
{
let target = root_dir.join(&source.strip_prefix(pyproject_dir).unwrap());
let target = root_dir.join(source.strip_prefix(pyproject_dir).unwrap());
if source.is_dir() {
writer.add_directory(target)?;
} else {
Expand Down
Loading

0 comments on commit 5ed3ca9

Please sign in to comment.