From f786bc2406d15878736f589c3561d6c5a982d18b Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 2 Nov 2022 18:57:04 +0800 Subject: [PATCH 1/2] Fix clippy warnings for Rust 1.65.0 --- src/auditwheel/audit.rs | 3 +++ src/auditwheel/musllinux.rs | 2 +- src/auditwheel/patchelf.rs | 2 +- src/auditwheel/repair.rs | 2 ++ src/build_options.rs | 2 +- src/compile.rs | 2 +- src/develop.rs | 4 ++-- src/module_writer.rs | 32 ++++++++++++++++---------------- src/project_layout.rs | 6 +++--- src/pyproject_toml.rs | 2 +- src/python_interpreter/mod.rs | 10 +++++----- src/source_distribution.rs | 22 +++++++++++----------- src/target.rs | 8 ++++---- src/upload.rs | 7 ++++--- tests/common/develop.rs | 2 +- tests/common/editable.rs | 2 +- tests/common/integration.rs | 4 ++-- tests/common/mod.rs | 4 ++-- tests/common/other.rs | 4 ++-- 19 files changed, 63 insertions(+), 57 deletions(-) diff --git a/src/auditwheel/audit.rs b/src/auditwheel/audit.rs index 962cb6a27..3b7871693 100644 --- a/src/auditwheel/audit.rs +++ b/src/auditwheel/audit.rs @@ -92,6 +92,7 @@ pub fn find_versioned_libraries(elf: &Elf) -> Vec { } /// Find incompliant symbols from symbol versions +#[allow(clippy::result_large_err)] fn find_incompliant_symbols( elf: &Elf, symbol_versions: &[String], @@ -111,6 +112,7 @@ fn find_incompliant_symbols( Ok(symbols) } +#[allow(clippy::result_large_err)] fn policy_is_satisfied( policy: &Policy, elf: &Elf, @@ -253,6 +255,7 @@ fn get_default_platform_policies() -> Vec { /// 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, diff --git a/src/auditwheel/musllinux.rs b/src/auditwheel/musllinux.rs index 1ecc1bb75..7111134f8 100644 --- a/src/auditwheel/musllinux.rs +++ b/src/auditwheel/musllinux.rs @@ -21,7 +21,7 @@ pub fn find_musl_libc() -> Result> { /// Dynamic Program Loader pub fn get_musl_version(ld_path: impl AsRef) -> Result> { 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()?; diff --git a/src/auditwheel/patchelf.rs b/src/auditwheel/patchelf.rs index 9d69c260e..0195b8503 100644 --- a/src/auditwheel/patchelf.rs +++ b/src/auditwheel/patchelf.rs @@ -80,7 +80,7 @@ pub fn set_rpath>(file: impl AsRef, rpath: &S) -> Result<( /// Get the `RPATH` of executables and libraries pub fn get_rpath(file: impl AsRef) -> Result> { 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() { diff --git a/src/auditwheel/repair.rs b/src/auditwheel/repair.rs index 3f0e6b571..e38f453d4 100644 --- a/src/auditwheel/repair.rs +++ b/src/auditwheel/repair.rs @@ -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, policy: &Policy, diff --git a/src/build_options.rs b/src/build_options.rs index 06562b7b0..fab0b4f44 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -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); } diff --git a/src/compile.rs b/src/compile.rs index deadf505c..9a4bc3600 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -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; diff --git a/src/develop.rs b/src/develop.rs index 307d85eab..955a60824 100644 --- a/src/develop.rs +++ b/src/develop.rs @@ -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 { @@ -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))?; diff --git a/src/module_writer.rs b/src/module_writer.rs index aa872a53b..00cf053ed 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -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 { 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 ಠ_ಠ") })?; @@ -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, @@ -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(()) @@ -453,7 +453,7 @@ where I: IntoIterator, S: AsRef, { - Command::new(&python) + Command::new(python) .args(args) .output() .context(format!("Failed to run python at {:?}", &python)) @@ -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; @@ -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(""); @@ -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() { @@ -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", @@ -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) } @@ -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) } @@ -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() @@ -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); @@ -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(()) @@ -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() @@ -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(()) diff --git a/src/project_layout.rs b/src/project_layout.rs index 661e3282c..1d64328fa 100644 --- a/src/project_layout.rs +++ b/src/project_layout.rs @@ -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(); @@ -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); diff --git a/src/pyproject_toml.rs b/src/pyproject_toml.rs index d323eb74d..cd0629ccb 100644 --- a/src/pyproject_toml.rs +++ b/src/pyproject_toml.rs @@ -80,7 +80,7 @@ impl PyProjectToml { /// source distributions pub fn new(pyproject_file: impl AsRef) -> Result { 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) diff --git a/src/python_interpreter/mod.rs b/src/python_interpreter/mod.rs index dd2db082d..d46a45d58 100644 --- a/src/python_interpreter/mod.rs +++ b/src/python_interpreter/mod.rs @@ -143,7 +143,7 @@ fn find_all_windows(target: &Target, min_python_minor: usize) -> Result Result Result> { - let python_info = Command::new(&executable) + let python_info = Command::new(executable) .arg("-c") .arg("import sys; print(sys.version)") .output(); @@ -546,8 +546,8 @@ impl PythonInterpreter { target: &Target, bridge: &BridgeModel, ) -> Result> { - 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!( @@ -825,7 +825,7 @@ impl PythonInterpreter { return true; } let out = Command::new(&self.executable) - .args(&[ + .args([ "-m", "pip", "debug", diff --git a/src/source_distribution.rs b/src/source_distribution.rs index c31b2ffd4..9ee797152 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -48,7 +48,7 @@ fn rewrite_cargo_toml( root_crate: bool, ) -> Result { 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(), ))?; @@ -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)) @@ -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(|| { @@ -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(); @@ -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) @@ -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, @@ -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, @@ -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, @@ -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 { @@ -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 { @@ -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 { diff --git a/src/target.rs b/src/target.rs index e0282334a..76a9b24bb 100644 --- a/src/target.rs +++ b/src/target.rs @@ -272,8 +272,8 @@ impl Target { // Illumos (Os::Illumos, Arch::X86_64) => { let info = PlatformInfo::new()?; - let mut release = info.release().replace('.', "_").replace('-', "_"); - let mut arch = info.machine().replace(' ', "_").replace('/', "_"); + let mut release = info.release().replace(['.', '-'], "_"); + let mut arch = info.machine().replace([' ', '/'], "_"); let mut os = self.os.to_string().to_ascii_lowercase(); // See https://github.com/python/cpython/blob/46c8d915715aa2bd4d697482aa051fe974d440e1/Lib/sysconfig.py#L722-L730 @@ -353,7 +353,7 @@ impl Target { Ok(os_ver) => os_ver, Err(_) => emcc_version()?, }; - let release = release.replace('.', "_").replace('-', "_"); + let release = release.replace(['.', '-'], "_"); format!("emscripten_{}_wasm32", release) } (Os::Wasi, Arch::Wasm32) => { @@ -374,7 +374,7 @@ impl Target { info.release().to_string() } }; - let release = release.replace('.', "_").replace('-', "_"); + let release = release.replace(['.', '-'], "_"); Ok(release) } diff --git a/src/upload.rs b/src/upload.rs index d480398f4..19d5f6931 100644 --- a/src/upload.rs +++ b/src/upload.rs @@ -259,8 +259,9 @@ fn canonicalize_name(name: &str) -> String { } /// Uploads a single wheel to the registry +#[allow(clippy::result_large_err)] pub fn upload(registry: &Registry, wheel_path: &Path) -> Result<(), UploadError> { - let hash_hex = hash_file(&wheel_path)?; + let hash_hex = hash_file(wheel_path)?; let dist = python_pkginfo::Distribution::new(wheel_path) .map_err(|err| UploadError::PkgInfoError(wheel_path.to_owned(), err))?; @@ -321,7 +322,7 @@ pub fn upload(registry: &Registry, wheel_path: &Path) -> Result<(), UploadError> add_vec("requires_external", &metadata.requires_external); add_vec("project_urls", &metadata.project_urls); - let wheel = File::open(&wheel_path)?; + let wheel = File::open(wheel_path)?; let wheel_name = wheel_path .file_name() .expect("Wheel path has a file name") @@ -464,7 +465,7 @@ pub fn upload_ui(items: &[PathBuf], publish: &PublishOpt) -> Result<()> { continue; } } - let filesize = fs::metadata(&i) + let filesize = fs::metadata(i) .map(|x| ByteSize(x.len()).to_string()) .unwrap_or_else(|e| format!("Failed to get the filesize of {:?}: {}", &i, e)); return Err(err) diff --git a/tests/common/develop.rs b/tests/common/develop.rs index 17cea39a6..7288088ee 100644 --- a/tests/common/develop.rs +++ b/tests/common/develop.rs @@ -26,7 +26,7 @@ pub fn test_develop( check_installed(package, &python).unwrap_err(); let output = Command::new(&python) - .args(&[ + .args([ "-m", "pip", "install", diff --git a/tests/common/editable.rs b/tests/common/editable.rs index 6f460f008..cf33eb909 100644 --- a/tests/common/editable.rs +++ b/tests/common/editable.rs @@ -58,7 +58,7 @@ pub fn test_editable( "--force-reinstall", ]; let output = Command::new(&python) - .args(&command) + .args(command) .arg(dunce::simplified(filename)) .output() .context(format!("pip install failed with {:?}", python))?; diff --git a/tests/common/integration.rs b/tests/common/integration.rs index 91a0d6afd..e4355d01d 100644 --- a/tests/common/integration.rs +++ b/tests/common/integration.rs @@ -119,7 +119,7 @@ pub fn test_integration( "--force-reinstall", ]; let output = Command::new(&python) - .args(&command) + .args(command) .arg(dunce::simplified(filename)) .output() .context(format!("pip install failed with {:?}", python))?; @@ -202,7 +202,7 @@ pub fn test_integration_conda(package: impl AsRef, bindings: Option Result<()> { let path = if cfg!(windows) { // on Windows, also add Scripts to PATH let python_dir = python.parent().unwrap(); - env::join_paths(&[&python_dir.join("Scripts"), python_dir])?.into() + env::join_paths([&python_dir.join("Scripts"), python_dir])?.into() } else { python.parent().unwrap().to_path_buf() }; @@ -32,7 +32,7 @@ pub fn check_installed(package: &Path, python: &Path) -> Result<()> { .join("check_installed") .join("check_installed.py"); } - let output = Command::new(&python) + let output = Command::new(python) .arg(check_installed) .env("PATH", path) .output() diff --git a/tests/common/other.rs b/tests/common/other.rs index 12ef164bc..18fa30649 100644 --- a/tests/common/other.rs +++ b/tests/common/other.rs @@ -23,7 +23,7 @@ pub fn test_musl() -> Result { use std::process::Command; let get_target_list = Command::new("rustup") - .args(&["target", "list", "--installed"]) + .args(["target", "list", "--installed"]) .output(); match get_target_list { @@ -91,7 +91,7 @@ pub fn test_musl() -> Result { /// https://github.com/PyO3/maturin/issues/449 pub fn test_workspace_cargo_lock() -> Result<()> { // The first arg gets ignored - let options: BuildOptions = BuildOptions::try_parse_from(&[ + let options: BuildOptions = BuildOptions::try_parse_from([ "build", "--manifest-path", "test-crates/workspace/py/Cargo.toml", From 95adabba54faf188fe9b79f7e3184ae41ba5412c Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 3 Nov 2022 22:35:02 +0800 Subject: [PATCH 2/2] Switch from `cfg`-out to ignore test code via `cfg_attr` --- tests/common/errors.rs | 2 -- tests/common/other.rs | 3 +-- tests/run.rs | 6 +++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/common/errors.rs b/tests/common/errors.rs index 0de3f202c..97896c6fd 100644 --- a/tests/common/errors.rs +++ b/tests/common/errors.rs @@ -30,7 +30,6 @@ pub fn abi3_without_version() -> Result<()> { } /// Check that you get a good error message if you forgot to set the extension-module feature -#[cfg(all(target_os = "linux", target_env = "gnu"))] pub fn pyo3_no_extension_module() -> Result<()> { // The first argument is ignored by clap let cli = vec![ @@ -103,7 +102,6 @@ pub fn locked_doesnt_build_without_cargo_lock() -> Result<()> { /// Don't panic if the manylinux version doesn't exit /// /// https://github.com/PyO3/maturin/issues/739 -#[cfg(all(target_os = "linux", target_env = "gnu"))] pub fn invalid_manylinux_does_not_panic() -> Result<()> { // The first argument is ignored by clap let cli = vec![ diff --git a/tests/common/other.rs b/tests/common/other.rs index 18fa30649..cbdb7dc01 100644 --- a/tests/common/other.rs +++ b/tests/common/other.rs @@ -13,7 +13,6 @@ use tar::Archive; /// given that rustup and the the musl target are installed /// /// The bool in the Ok() response says whether the test was actually run -#[cfg(target_os = "linux")] pub fn test_musl() -> Result { use anyhow::bail; use fs_err as fs; @@ -48,7 +47,7 @@ pub fn test_musl() -> Result { }; // The first arg gets ignored - let options: BuildOptions = BuildOptions::try_parse_from(&[ + let options: BuildOptions = BuildOptions::try_parse_from([ "build", "--manifest-path", "test-crates/hello-world/Cargo.toml", diff --git a/tests/run.rs b/tests/run.rs index 031ea3521..e2c61054a 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -347,7 +347,7 @@ fn abi3_without_version() { } #[test] -#[cfg(all(target_os = "linux", target_env = "gnu"))] +#[cfg_attr(not(all(target_os = "linux", target_env = "gnu")), ignore)] fn pyo3_no_extension_module() { let python = test_python_path().map(PathBuf::from).unwrap_or_else(|| { let target = Target::from_target_triple(None).unwrap(); @@ -365,13 +365,13 @@ fn locked_doesnt_build_without_cargo_lock() { } #[test] -#[cfg(all(target_os = "linux", target_env = "gnu"))] +#[cfg_attr(not(all(target_os = "linux", target_env = "gnu")), ignore)] fn invalid_manylinux_does_not_panic() { handle_result(errors::invalid_manylinux_does_not_panic()) } #[test] -#[cfg(target_os = "linux")] +#[cfg_attr(not(target_os = "linux"), ignore)] fn musl() { let ran = handle_result(other::test_musl()); if !ran {