Skip to content

Commit 6029616

Browse files
committed
Fix clippy warnings
1 parent 9f6b8f0 commit 6029616

23 files changed

+130
-192
lines changed

src/auditwheel/audit.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn find_incompliant_symbols(
107107
if sym.st_type() == STT_FUNC {
108108
let name = strtab.get_at(sym.st_name).unwrap_or("BAD NAME");
109109
for symbol_version in symbol_versions {
110-
if name.ends_with(&format!("@{}", symbol_version)) {
110+
if name.ends_with(&format!("@{symbol_version}")) {
111111
symbols.push(name.to_string());
112112
}
113113
}
@@ -184,7 +184,7 @@ fn policy_is_satisfied(
184184
.collect();
185185
let offending_symbol_versions: Vec<String> = offending_versions
186186
.iter()
187-
.map(|v| format!("{}_{}", name, v))
187+
.map(|v| format!("{name}_{v}"))
188188
.collect();
189189
let offending_symbols = find_incompliant_symbols(elf, &offending_symbol_versions)?;
190190
let offender = if offending_symbols.is_empty() {
@@ -242,8 +242,7 @@ fn get_default_platform_policies() -> Vec<Policy> {
242242
return MUSLLINUX_POLICIES
243243
.iter()
244244
.filter(|policy| {
245-
policy.name == "linux"
246-
|| policy.name == format!("musllinux_{}_{}", major, minor)
245+
policy.name == "linux" || policy.name == format!("musllinux_{major}_{minor}")
247246
})
248247
.cloned()
249248
.collect();
@@ -290,9 +289,7 @@ pub fn auditwheel_rs(
290289
Some(PlatformTag::Musllinux { x, y }) => MUSLLINUX_POLICIES
291290
.clone()
292291
.into_iter()
293-
.filter(|policy| {
294-
policy.name == "linux" || policy.name == format!("musllinux_{}_{}", x, y)
295-
})
292+
.filter(|policy| policy.name == "linux" || policy.name == format!("musllinux_{x}_{y}"))
296293
.map(|mut policy| {
297294
policy.fixup_musl_libc_so_name(target.target_arch());
298295
policy
@@ -349,8 +346,7 @@ pub fn auditwheel_rs(
349346
if policy.priority < highest_policy.priority && highest_policy.name != "manylinux_2_5" {
350347
println!(
351348
"📦 Wheel is eligible for a higher priority tag. \
352-
You requested {} but this wheel is eligible for {}",
353-
policy, highest_policy,
349+
You requested {policy} but this wheel is eligible for {highest_policy}",
354350
);
355351
}
356352
}
@@ -410,7 +406,7 @@ pub fn get_sysroot_path(target: &Target) -> Result<PathBuf> {
410406
.target(target_triple);
411407
let compiler = build
412408
.try_get_compiler()
413-
.with_context(|| format!("Failed to get compiler for {}", target_triple))?;
409+
.with_context(|| format!("Failed to get compiler for {target_triple}"))?;
414410
// Only GNU like compilers support `--print-sysroot`
415411
if !compiler.is_like_gnu() {
416412
return Ok(PathBuf::from("/"));
@@ -450,7 +446,7 @@ pub fn get_policy_and_libs(
450446
auditwheel_rs(artifact, target, platform_tag, allow_linking_libpython).with_context(
451447
|| {
452448
if let Some(platform_tag) = platform_tag {
453-
format!("Error ensuring {} compliance", platform_tag)
449+
format!("Error ensuring {platform_tag} compliance")
454450
} else {
455451
"Error checking for manylinux/musllinux compliance".to_string()
456452
}
@@ -462,7 +458,7 @@ pub fn get_policy_and_libs(
462458
let external_libs = find_external_libs(&artifact.path, &policy, sysroot, ld_paths)
463459
.with_context(|| {
464460
if let Some(platform_tag) = platform_tag {
465-
format!("Error repairing wheel for {} compliance", platform_tag)
461+
format!("Error repairing wheel for {platform_tag} compliance")
466462
} else {
467463
"Error repairing wheel for manylinux/musllinux compliance".to_string()
468464
}

src/auditwheel/patchelf.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ pub fn verify_patchelf() -> Result<()> {
2222
if semver < semver::Version::new(0, 14, 0) {
2323
// TODO: turn it into an error in 1.0
2424
eprintln!(
25-
"⚠️ Warning: patchelf {} found. auditwheel repair requires patchelf >= 0.14.",
26-
version
25+
"⚠️ Warning: patchelf {version} found. auditwheel repair requires patchelf >= 0.14."
2726
);
2827
}
2928
Ok(())

src/auditwheel/platform_tag.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ impl PlatformTag {
8585
impl fmt::Display for PlatformTag {
8686
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8787
match *self {
88-
PlatformTag::Manylinux { x, y } => write!(f, "manylinux_{}_{}", x, y),
89-
PlatformTag::Musllinux { x, y } => write!(f, "musllinux_{}_{}", x, y),
88+
PlatformTag::Manylinux { x, y } => write!(f, "manylinux_{x}_{y}"),
89+
PlatformTag::Musllinux { x, y } => write!(f, "musllinux_{x}_{y}"),
9090
PlatformTag::Linux => write!(f, "linux"),
9191
}
9292
}

src/build_context.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ impl BridgeModel {
7373
impl Display for BridgeModel {
7474
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
7575
match self {
76-
BridgeModel::Bin(Some((name, _))) => write!(f, "{} bin", name),
76+
BridgeModel::Bin(Some((name, _))) => write!(f, "{name} bin"),
7777
BridgeModel::Bin(None) => write!(f, "bin"),
78-
BridgeModel::Bindings(name, _) => write!(f, "{}", name),
78+
BridgeModel::Bindings(name, _) => write!(f, "{name}"),
7979
BridgeModel::BindingsAbi3(..) => write!(f, "pyo3"),
8080
BridgeModel::Cffi => write!(f, "cffi"),
8181
BridgeModel::UniFfi => write!(f, "uniffi"),
@@ -281,8 +281,7 @@ impl BuildContext {
281281
&& !python_interpreter.support_portable_wheels()
282282
{
283283
println!(
284-
"🐍 Skipping auditwheel because {} does not support manylinux/musllinux wheels",
285-
python_interpreter
284+
"🐍 Skipping auditwheel because {python_interpreter} does not support manylinux/musllinux wheels"
286285
);
287286
return Ok((Policy::default(), Vec::new()));
288287
}
@@ -383,10 +382,10 @@ impl BuildContext {
383382
// Generate a new soname with a short hash
384383
let short_hash = &hash_file(&lib_path)?[..8];
385384
let (file_stem, file_ext) = lib.name.split_once('.').unwrap();
386-
let new_soname = if !file_stem.ends_with(&format!("-{}", short_hash)) {
387-
format!("{}-{}.{}", file_stem, short_hash, file_ext)
385+
let new_soname = if !file_stem.ends_with(&format!("-{short_hash}")) {
386+
format!("{file_stem}-{short_hash}.{file_ext}")
388387
} else {
389-
format!("{}.{}", file_stem, file_ext)
388+
format!("{file_stem}.{file_ext}")
390389
};
391390

392391
// Copy the original lib to a tmpdir and modify some of its properties
@@ -511,7 +510,7 @@ impl BuildContext {
511510
let platform = self
512511
.target
513512
.get_platform_tag(platform_tags, self.universal2)?;
514-
let tag = format!("cp{}{}-abi3-{}", major, min_minor, platform);
513+
let tag = format!("cp{major}{min_minor}-abi3-{platform}");
515514

516515
let mut writer = WheelWriter::new(
517516
&tag,
@@ -537,7 +536,7 @@ impl BuildContext {
537536
self.add_pth(&mut writer)?;
538537
add_data(&mut writer, self.project_layout.data.as_deref())?;
539538
let wheel_path = writer.finish()?;
540-
Ok((wheel_path, format!("cp{}{}", major, min_minor)))
539+
Ok((wheel_path, format!("cp{major}{min_minor}")))
541540
}
542541

543542
/// For abi3 we only need to build a single wheel and we don't even need a python interpreter

src/build_options.rs

+14-33
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,7 @@ impl BuildOptions {
237237
min_python_minor,
238238
)?;
239239
let host_python = &host_interpreters[0];
240-
println!(
241-
"🐍 Using host {} for cross-compiling preparation",
242-
host_python
243-
);
240+
println!("🐍 Using host {host_python} for cross-compiling preparation");
244241
// pyo3
245242
env::set_var("PYO3_PYTHON", &host_python.executable);
246243
// rust-cpython, and legacy pyo3 versions
@@ -320,14 +317,14 @@ impl BuildOptions {
320317
.map(ToString::to_string)
321318
.collect::<Vec<String>>()
322319
.join(", ");
323-
println!("🐍 Found {}", interpreters_str);
320+
println!("🐍 Found {interpreters_str}");
324321

325322
Ok(interpreters)
326323
}
327324
BridgeModel::Cffi => {
328325
let interpreter =
329326
find_single_python_interpreter(bridge, interpreter, target, "cffi")?;
330-
println!("🐍 Using {} to generate the cffi bindings", interpreter);
327+
println!("🐍 Using {interpreter} to generate the cffi bindings");
331328
Ok(vec![interpreter])
332329
}
333330
BridgeModel::Bin(None) | BridgeModel::UniFfi => Ok(vec![]),
@@ -364,7 +361,7 @@ impl BuildOptions {
364361
soabi: None,
365362
}])
366363
} else if let Some(interp) = interpreters.get(0) {
367-
println!("🐍 Using {} to generate to link bindings (With abi3, an interpreter is only required on windows)", interp);
364+
println!("🐍 Using {interp} to generate to link bindings (With abi3, an interpreter is only required on windows)");
368365
Ok(interpreters)
369366
} else if generate_import_lib {
370367
println!("🐍 Not using a specific python interpreter (Automatically generating windows import library)");
@@ -617,10 +614,7 @@ impl BuildOptions {
617614

618615
for platform_tag in &platform_tags {
619616
if !platform_tag.is_supported() {
620-
eprintln!(
621-
"⚠️ Warning: {} is unsupported by the Rust compiler.",
622-
platform_tag
623-
);
617+
eprintln!("⚠️ Warning: {platform_tag} is unsupported by the Rust compiler.");
624618
}
625619
}
626620

@@ -771,7 +765,7 @@ fn has_abi3(cargo_metadata: &Metadata) -> Result<Option<(u8, u8)>> {
771765
))
772766
})
773767
.collect::<Result<Vec<(u8, u8)>>>()
774-
.context(format!("Bogus {} cargo features", lib))?
768+
.context(format!("Bogus {lib} cargo features"))?
775769
.into_iter()
776770
.min();
777771
if abi3_selected && min_abi3_version.is_none() {
@@ -920,7 +914,7 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
920914
};
921915

922916
if !(bridge.is_bindings("pyo3") || bridge.is_bindings("pyo3-ffi")) {
923-
println!("🔗 Found {} bindings", bridge);
917+
println!("🔗 Found {bridge} bindings");
924918
}
925919

926920
for &lib in PYO3_BINDING_CRATES.iter() {
@@ -929,21 +923,17 @@ pub fn find_bridge(cargo_metadata: &Metadata, bridge: Option<&str>) -> Result<Br
929923
if !pyo3_node.features.contains(&"extension-module".to_string()) {
930924
let version = cargo_metadata[&pyo3_node.id].version.to_string();
931925
eprintln!(
932-
"⚠️ Warning: You're building a library without activating {}'s \
926+
"⚠️ Warning: You're building a library without activating {lib}'s \
933927
`extension-module` feature. \
934-
See https://pyo3.rs/v{}/building_and_distribution.html#linking",
935-
lib, version
928+
See https://pyo3.rs/v{version}/building_and_distribution.html#linking"
936929
);
937930
}
938931

939932
return if let Some((major, minor)) = has_abi3(cargo_metadata)? {
940-
println!(
941-
"🔗 Found {} bindings with abi3 support for Python ≥ {}.{}",
942-
lib, major, minor
943-
);
933+
println!("🔗 Found {lib} bindings with abi3 support for Python ≥ {major}.{minor}");
944934
Ok(BridgeModel::BindingsAbi3(major, minor))
945935
} else {
946-
println!("🔗 Found {} bindings", lib);
936+
println!("🔗 Found {lib} bindings");
947937
Ok(bridge)
948938
};
949939
}
@@ -1074,16 +1064,10 @@ fn find_interpreter_in_sysconfig(
10741064
.split_once('.')
10751065
.context("Invalid python interpreter version")?;
10761066
let ver_major = ver_major.parse::<usize>().with_context(|| {
1077-
format!(
1078-
"Invalid python interpreter major version '{}', expect a digit",
1079-
ver_major
1080-
)
1067+
format!("Invalid python interpreter major version '{ver_major}', expect a digit")
10811068
})?;
10821069
let ver_minor = ver_minor.parse::<usize>().with_context(|| {
1083-
format!(
1084-
"Invalid python interpreter minor version '{}', expect a digit",
1085-
ver_minor
1086-
)
1070+
format!("Invalid python interpreter minor version '{ver_minor}', expect a digit")
10871071
})?;
10881072
let sysconfig = InterpreterConfig::lookup(
10891073
target.target_os(),
@@ -1092,10 +1076,7 @@ fn find_interpreter_in_sysconfig(
10921076
(ver_major, ver_minor),
10931077
)
10941078
.with_context(|| {
1095-
format!(
1096-
"Failed to find a {} {}.{} interpreter",
1097-
python_impl, ver_major, ver_minor
1098-
)
1079+
format!("Failed to find a {python_impl} {ver_major}.{ver_minor} interpreter")
10991080
})?;
11001081
debug!(
11011082
"Found {} {}.{} in bundled sysconfig",

src/compile.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ fn compile_target(
203203
// See https://github.com/PyO3/setuptools-rust/issues/106 for detail
204204
let module_name = &context.module_name;
205205
let so_filename = match bridge_model {
206-
BridgeModel::BindingsAbi3(..) => format!("{base}.abi3.so", base = module_name),
206+
BridgeModel::BindingsAbi3(..) => format!("{module_name}.abi3.so"),
207207
_ => python_interpreter
208208
.expect("missing python interpreter for non-abi3 wheel build")
209209
.get_library_name(module_name),
210210
};
211211
let macos_dylib_install_name =
212-
format!("link-args=-Wl,-install_name,@rpath/{}", so_filename);
212+
format!("link-args=-Wl,-install_name,@rpath/{so_filename}");
213213
let mac_args = [
214214
"-C".to_string(),
215215
"link-arg=-undefined".to_string(),
@@ -276,7 +276,7 @@ fn compile_target(
276276
let zig_triple = if target.is_linux() && !target.is_musl_target() {
277277
match context.platform_tag.iter().find(|tag| tag.is_manylinux()) {
278278
Some(PlatformTag::Manylinux { x, y }) => {
279-
format!("{}.{}.{}", target_triple, x, y)
279+
format!("{target_triple}.{x}.{y}")
280280
}
281281
_ => target_triple.to_string(),
282282
}
@@ -379,10 +379,9 @@ fn compile_target(
379379
use crate::target::rustc_macosx_target_version;
380380

381381
let (major, minor) = rustc_macosx_target_version(target_triple);
382-
build_command.env("MACOSX_DEPLOYMENT_TARGET", format!("{}.{}", major, minor));
382+
build_command.env("MACOSX_DEPLOYMENT_TARGET", format!("{major}.{minor}"));
383383
eprintln!(
384-
"💻 Using `MACOSX_DEPLOYMENT_TARGET={}.{}` for {} by default",
385-
major, minor, target_triple
384+
"💻 Using `MACOSX_DEPLOYMENT_TARGET={major}.{minor}` for {target_triple} by default"
386385
);
387386
}
388387

@@ -420,8 +419,7 @@ fn compile_target(
420419
if should_warn {
421420
// This is a spurious error I don't really understand
422421
eprintln!(
423-
"⚠️ Warning: The package {} wasn't listed in `cargo metadata`",
424-
package_id
422+
"⚠️ Warning: The package {package_id} wasn't listed in `cargo metadata`"
425423
);
426424
}
427425
continue;
@@ -490,7 +488,7 @@ fn compile_target(
490488
///
491489
/// Currently the check is only run on linux, macOS and Windows
492490
pub fn warn_missing_py_init(artifact: &Path, module_name: &str) -> Result<()> {
493-
let py_init = format!("PyInit_{}", module_name);
491+
let py_init = format!("PyInit_{module_name}");
494492
let mut fd = File::open(artifact)?;
495493
let mut buffer = Vec::new();
496494
fd.read_to_end(&mut buffer)?;
@@ -549,10 +547,9 @@ pub fn warn_missing_py_init(artifact: &Path, module_name: &str) -> Result<()> {
549547

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

src/cross_compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn search_lib_dir(path: impl AsRef<Path>, target: &Target) -> Vec<PathBuf> {
152152
let (cpython_version_pat, pypy_version_pat) = if let Some(v) =
153153
env::var_os("PYO3_CROSS_PYTHON_VERSION").map(|s| s.into_string().unwrap())
154154
{
155-
(format!("python{}", v), format!("pypy{}", v))
155+
(format!("python{v}"), format!("pypy{v}"))
156156
} else {
157157
("python3.".into(), "pypy3.".into())
158158
};

src/develop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ pub fn develop(
8585
// Remove extra marker to make it installable with pip
8686
for extra in &extras {
8787
pkg = pkg
88-
.replace(&format!(" and extra == '{}'", extra), "")
89-
.replace(&format!("; extra == '{}'", extra), "");
88+
.replace(&format!(" and extra == '{extra}'"), "")
89+
.replace(&format!("; extra == '{extra}'"), "");
9090
}
9191
pkg
9292
}));
@@ -113,7 +113,7 @@ pub fn develop(
113113
.args(command)
114114
.arg(dunce::simplified(filename))
115115
.output()
116-
.context(format!("pip install failed with {:?}", python))?;
116+
.context(format!("pip install failed with {python:?}"))?;
117117
if !output.status.success() {
118118
bail!(
119119
"pip install in {} failed running {:?}: {}\n--- Stdout:\n{}\n--- Stderr:\n{}\n---\n",

0 commit comments

Comments
 (0)