Skip to content

Commit

Permalink
Fix clippy warnings on Rust 1.67.0
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jan 27, 2023
1 parent 87ad04b commit 27200e8
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 194 deletions.
20 changes: 8 additions & 12 deletions src/auditwheel/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn find_incompliant_symbols(
if sym.st_type() == STT_FUNC {
let name = strtab.get_at(sym.st_name).unwrap_or("BAD NAME");
for symbol_version in symbol_versions {
if name.ends_with(&format!("@{}", symbol_version)) {
if name.ends_with(&format!("@{symbol_version}")) {
symbols.push(name.to_string());
}
}
Expand Down Expand Up @@ -184,7 +184,7 @@ fn policy_is_satisfied(
.collect();
let offending_symbol_versions: Vec<String> = offending_versions
.iter()
.map(|v| format!("{}_{}", name, v))
.map(|v| format!("{name}_{v}"))
.collect();
let offending_symbols = find_incompliant_symbols(elf, &offending_symbol_versions)?;
let offender = if offending_symbols.is_empty() {
Expand Down Expand Up @@ -242,8 +242,7 @@ fn get_default_platform_policies() -> Vec<Policy> {
return MUSLLINUX_POLICIES
.iter()
.filter(|policy| {
policy.name == "linux"
|| policy.name == format!("musllinux_{}_{}", major, minor)
policy.name == "linux" || policy.name == format!("musllinux_{major}_{minor}")
})
.cloned()
.collect();
Expand Down Expand Up @@ -290,9 +289,7 @@ pub fn auditwheel_rs(
Some(PlatformTag::Musllinux { x, y }) => MUSLLINUX_POLICIES
.clone()
.into_iter()
.filter(|policy| {
policy.name == "linux" || policy.name == format!("musllinux_{}_{}", x, y)
})
.filter(|policy| policy.name == "linux" || policy.name == format!("musllinux_{x}_{y}"))
.map(|mut policy| {
policy.fixup_musl_libc_so_name(target.target_arch());
policy
Expand Down Expand Up @@ -349,8 +346,7 @@ pub fn auditwheel_rs(
if policy.priority < highest_policy.priority && highest_policy.name != "manylinux_2_5" {
println!(
"📦 Wheel is eligible for a higher priority tag. \
You requested {} but this wheel is eligible for {}",
policy, highest_policy,
You requested {policy} but this wheel is eligible for {highest_policy}",
);
}
}
Expand Down Expand Up @@ -410,7 +406,7 @@ pub fn get_sysroot_path(target: &Target) -> Result<PathBuf> {
.target(target_triple);
let compiler = build
.try_get_compiler()
.with_context(|| format!("Failed to get compiler for {}", target_triple))?;
.with_context(|| format!("Failed to get compiler for {target_triple}"))?;
// Only GNU like compilers support `--print-sysroot`
if !compiler.is_like_gnu() {
return Ok(PathBuf::from("/"));
Expand Down Expand Up @@ -450,7 +446,7 @@ pub fn get_policy_and_libs(
auditwheel_rs(artifact, target, platform_tag, allow_linking_libpython).with_context(
|| {
if let Some(platform_tag) = platform_tag {
format!("Error ensuring {} compliance", platform_tag)
format!("Error ensuring {platform_tag} compliance")
} else {
"Error checking for manylinux/musllinux compliance".to_string()
}
Expand All @@ -462,7 +458,7 @@ pub fn get_policy_and_libs(
let external_libs = find_external_libs(&artifact.path, &policy, sysroot, ld_paths)
.with_context(|| {
if let Some(platform_tag) = platform_tag {
format!("Error repairing wheel for {} compliance", platform_tag)
format!("Error repairing wheel for {platform_tag} compliance")
} else {
"Error repairing wheel for manylinux/musllinux compliance".to_string()
}
Expand Down
4 changes: 2 additions & 2 deletions src/auditwheel/platform_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ impl PlatformTag {
impl fmt::Display for PlatformTag {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
PlatformTag::Manylinux { x, y } => write!(f, "manylinux_{}_{}", x, y),
PlatformTag::Musllinux { x, y } => write!(f, "musllinux_{}_{}", x, y),
PlatformTag::Manylinux { x, y } => write!(f, "manylinux_{x}_{y}"),
PlatformTag::Musllinux { x, y } => write!(f, "musllinux_{x}_{y}"),
PlatformTag::Linux => write!(f, "linux"),
}
}
Expand Down
17 changes: 8 additions & 9 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ impl BridgeModel {
impl Display for BridgeModel {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
BridgeModel::Bin(Some((name, _))) => write!(f, "{} bin", name),
BridgeModel::Bin(Some((name, _))) => write!(f, "{name} bin"),
BridgeModel::Bin(None) => write!(f, "bin"),
BridgeModel::Bindings(name, _) => write!(f, "{}", name),
BridgeModel::Bindings(name, _) => write!(f, "{name}"),
BridgeModel::BindingsAbi3(..) => write!(f, "pyo3"),
BridgeModel::Cffi => write!(f, "cffi"),
BridgeModel::UniFfi => write!(f, "uniffi"),
Expand Down Expand Up @@ -288,8 +288,7 @@ impl BuildContext {
&& !python_interpreter.support_portable_wheels()
{
println!(
"🐍 Skipping auditwheel because {} does not support manylinux/musllinux wheels",
python_interpreter
"🐍 Skipping auditwheel because {python_interpreter} does not support manylinux/musllinux wheels"
);
return Ok((Policy::default(), Vec::new()));
}
Expand Down Expand Up @@ -390,10 +389,10 @@ impl BuildContext {
// Generate a new soname with a short hash
let short_hash = &hash_file(&lib_path)?[..8];
let (file_stem, file_ext) = lib.name.split_once('.').unwrap();
let new_soname = if !file_stem.ends_with(&format!("-{}", short_hash)) {
format!("{}-{}.{}", file_stem, short_hash, file_ext)
let new_soname = if !file_stem.ends_with(&format!("-{short_hash}")) {
format!("{file_stem}-{short_hash}.{file_ext}")
} else {
format!("{}.{}", file_stem, file_ext)
format!("{file_stem}.{file_ext}")
};

// Copy the original lib to a tmpdir and modify some of its properties
Expand Down Expand Up @@ -509,7 +508,7 @@ impl BuildContext {
let platform = self
.target
.get_platform_tag(platform_tags, self.universal2)?;
let tag = format!("cp{}{}-abi3-{}", major, min_minor, platform);
let tag = format!("cp{major}{min_minor}-abi3-{platform}");

let mut writer = WheelWriter::new(
&tag,
Expand All @@ -535,7 +534,7 @@ impl BuildContext {
self.add_pth(&mut writer)?;
add_data(&mut writer, self.project_layout.data.as_deref())?;
let wheel_path = writer.finish()?;
Ok((wheel_path, format!("cp{}{}", major, min_minor)))
Ok((wheel_path, format!("cp{major}{min_minor}")))
}

/// For abi3 we only need to build a single wheel and we don't even need a python interpreter
Expand Down
47 changes: 14 additions & 33 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,7 @@ impl BuildOptions {
min_python_minor,
)?;
let host_python = &host_interpreters[0];
println!(
"🐍 Using host {} for cross-compiling preparation",
host_python
);
println!("🐍 Using host {host_python} for cross-compiling preparation");
// pyo3
env::set_var("PYO3_PYTHON", &host_python.executable);
// rust-cpython, and legacy pyo3 versions
Expand Down Expand Up @@ -322,14 +319,14 @@ impl BuildOptions {
.map(ToString::to_string)
.collect::<Vec<String>>()
.join(", ");
println!("🐍 Found {}", interpreters_str);
println!("🐍 Found {interpreters_str}");

Ok(interpreters)
}
BridgeModel::Cffi => {
let interpreter =
find_single_python_interpreter(bridge, interpreter, target, "cffi")?;
println!("🐍 Using {} to generate the cffi bindings", interpreter);
println!("🐍 Using {interpreter} to generate the cffi bindings");
Ok(vec![interpreter])
}
BridgeModel::Bin(None) | BridgeModel::UniFfi => Ok(vec![]),
Expand Down Expand Up @@ -366,7 +363,7 @@ impl BuildOptions {
soabi: None,
}])
} else if let Some(interp) = interpreters.get(0) {
println!("🐍 Using {} to generate to link bindings (With abi3, an interpreter is only required on windows)", interp);
println!("🐍 Using {interp} to generate to link bindings (With abi3, an interpreter is only required on windows)");
Ok(interpreters)
} else if generate_import_lib {
println!("🐍 Not using a specific python interpreter (Automatically generating windows import library)");
Expand Down Expand Up @@ -623,10 +620,7 @@ impl BuildOptions {

for platform_tag in &platform_tags {
if !platform_tag.is_supported() {
eprintln!(
"⚠️ Warning: {} is unsupported by the Rust compiler.",
platform_tag
);
eprintln!("⚠️ Warning: {platform_tag} is unsupported by the Rust compiler.");
}
}

Expand Down Expand Up @@ -860,7 +854,7 @@ fn has_abi3(cargo_metadata: &Metadata) -> Result<Option<(u8, u8)>> {
))
})
.collect::<Result<Vec<(u8, u8)>>>()
.context(format!("Bogus {} cargo features", lib))?
.context(format!("Bogus {lib} cargo features"))?
.into_iter()
.min();
if abi3_selected && min_abi3_version.is_none() {
Expand Down Expand Up @@ -1009,7 +1003,7 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
};

if !(bridge.is_bindings("pyo3") || bridge.is_bindings("pyo3-ffi")) {
println!("🔗 Found {} bindings", bridge);
println!("🔗 Found {bridge} bindings");
}

for &lib in PYO3_BINDING_CRATES.iter() {
Expand All @@ -1018,21 +1012,17 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
if !pyo3_node.features.contains(&"extension-module".to_string()) {
let version = cargo_metadata[&pyo3_node.id].version.to_string();
eprintln!(
"⚠️ Warning: You're building a library without activating {}'s \
"⚠️ Warning: You're building a library without activating {lib}'s \
`extension-module` feature. \
See https://pyo3.rs/v{}/building_and_distribution.html#linking",
lib, version
See https://pyo3.rs/v{version}/building_and_distribution.html#linking"
);
}

return if let Some((major, minor)) = has_abi3(cargo_metadata)? {
println!(
"🔗 Found {} bindings with abi3 support for Python ≥ {}.{}",
lib, major, minor
);
println!("🔗 Found {lib} bindings with abi3 support for Python ≥ {major}.{minor}");
Ok(BridgeModel::BindingsAbi3(major, minor))
} else {
println!("🔗 Found {} bindings", lib);
println!("🔗 Found {lib} bindings");
Ok(bridge)
};
}
Expand Down Expand Up @@ -1163,16 +1153,10 @@ fn find_interpreter_in_sysconfig(
.split_once('.')
.context("Invalid python interpreter version")?;
let ver_major = ver_major.parse::<usize>().with_context(|| {
format!(
"Invalid python interpreter major version '{}', expect a digit",
ver_major
)
format!("Invalid python interpreter major version '{ver_major}', expect a digit")
})?;
let ver_minor = ver_minor.parse::<usize>().with_context(|| {
format!(
"Invalid python interpreter minor version '{}', expect a digit",
ver_minor
)
format!("Invalid python interpreter minor version '{ver_minor}', expect a digit")
})?;
let sysconfig = InterpreterConfig::lookup(
target.target_os(),
Expand All @@ -1181,10 +1165,7 @@ fn find_interpreter_in_sysconfig(
(ver_major, ver_minor),
)
.with_context(|| {
format!(
"Failed to find a {} {}.{} interpreter",
python_impl, ver_major, ver_minor
)
format!("Failed to find a {python_impl} {ver_major}.{ver_minor} interpreter")
})?;
debug!(
"Found {} {}.{} in bundled sysconfig",
Expand Down
29 changes: 13 additions & 16 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub struct BuildArtifact {
/// Builds the rust crate into a native module (i.e. an .so or .dll) for a
/// specific python version. Returns a mapping from crate type (e.g. cdylib)
/// to artifact location.
pub fn compile<'a>(
context: &'a BuildContext,
pub fn compile(
context: &BuildContext,
python_interpreter: Option<&PythonInterpreter>,
targets: &[CompileTarget],
) -> Result<Vec<HashMap<String, BuildArtifact>>> {
Expand All @@ -49,8 +49,8 @@ pub fn compile<'a>(
}

/// Build an universal2 wheel for macos which contains both an x86 and an aarch64 binary
fn compile_universal2<'a>(
context: &'a BuildContext,
fn compile_universal2(
context: &BuildContext,
python_interpreter: Option<&PythonInterpreter>,
targets: &[CompileTarget],
) -> Result<Vec<HashMap<String, BuildArtifact>>> {
Expand Down Expand Up @@ -214,13 +214,13 @@ fn compile_target(
// See https://github.com/PyO3/setuptools-rust/issues/106 for detail
let module_name = &context.module_name;
let so_filename = match bridge_model {
BridgeModel::BindingsAbi3(..) => format!("{base}.abi3.so", base = module_name),
BridgeModel::BindingsAbi3(..) => format!("{module_name}.abi3.so"),
_ => python_interpreter
.expect("missing python interpreter for non-abi3 wheel build")
.get_library_name(module_name),
};
let macos_dylib_install_name =
format!("link-args=-Wl,-install_name,@rpath/{}", so_filename);
format!("link-args=-Wl,-install_name,@rpath/{so_filename}");
let mac_args = [
"-C".to_string(),
"link-arg=-undefined".to_string(),
Expand Down Expand Up @@ -299,7 +299,7 @@ fn compile_target(
let zig_triple = if target.is_linux() && !target.is_musl_target() {
match context.platform_tag.iter().find(|tag| tag.is_manylinux()) {
Some(PlatformTag::Manylinux { x, y }) => {
format!("{}.{}.{}", target_triple, x, y)
format!("{target_triple}.{x}.{y}")
}
_ => target_triple.to_string(),
}
Expand Down Expand Up @@ -411,10 +411,9 @@ fn compile_target(
use crate::target::rustc_macosx_target_version;

let (major, minor) = rustc_macosx_target_version(target_triple);
build_command.env("MACOSX_DEPLOYMENT_TARGET", format!("{}.{}", major, minor));
build_command.env("MACOSX_DEPLOYMENT_TARGET", format!("{major}.{minor}"));
eprintln!(
"💻 Using `MACOSX_DEPLOYMENT_TARGET={}.{}` for {} by default",
major, minor, target_triple
"💻 Using `MACOSX_DEPLOYMENT_TARGET={major}.{minor}` for {target_triple} by default"
);
}

Expand Down Expand Up @@ -452,8 +451,7 @@ fn compile_target(
if should_warn {
// This is a spurious error I don't really understand
eprintln!(
"⚠️ Warning: The package {} wasn't listed in `cargo metadata`",
package_id
"⚠️ Warning: The package {package_id} wasn't listed in `cargo metadata`"
);
}
continue;
Expand Down Expand Up @@ -522,7 +520,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 py_init = format!("PyInit_{module_name}");
let mut fd = File::open(artifact)?;
let mut buffer = Vec::new();
fd.read_to_end(&mut buffer)?;
Expand Down Expand Up @@ -581,10 +579,9 @@ pub fn warn_missing_py_init(artifact: &Path, module_name: &str) -> Result<()> {

if !found {
eprintln!(
"⚠️ Warning: Couldn't find the symbol `{}` in the native library. \
"⚠️ Warning: Couldn't find the symbol `{py_init}` in the native library. \
Python will fail to import this module. \
If you're using pyo3, check that `#[pymodule]` uses `{}` as module name",
py_init, module_name
If you're using pyo3, check that `#[pymodule]` uses `{module_name}` as module name"
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn search_lib_dir(path: impl AsRef<Path>, target: &Target) -> Vec<PathBuf> {
let (cpython_version_pat, pypy_version_pat) = if let Some(v) =
env::var_os("PYO3_CROSS_PYTHON_VERSION").map(|s| s.into_string().unwrap())
{
(format!("python{}", v), format!("pypy{}", v))
(format!("python{v}"), format!("pypy{v}"))
} else {
("python3.".into(), "pypy3.".into())
};
Expand Down
6 changes: 3 additions & 3 deletions src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ pub fn develop(
// Remove extra marker to make it installable with pip
for extra in &extras {
pkg = pkg
.replace(&format!(" and extra == '{}'", extra), "")
.replace(&format!("; extra == '{}'", extra), "");
.replace(&format!(" and extra == '{extra}'"), "")
.replace(&format!("; extra == '{extra}'"), "");
}
pkg
}));
Expand All @@ -114,7 +114,7 @@ pub fn develop(
.args(command)
.arg(dunce::simplified(filename))
.output()
.context(format!("pip install failed with {:?}", python))?;
.context(format!("pip install failed with {python:?}"))?;
if !output.status.success() {
bail!(
"pip install in {} failed running {:?}: {}\n--- Stdout:\n{}\n--- Stderr:\n{}\n---\n",
Expand Down
Loading

0 comments on commit 27200e8

Please sign in to comment.