From 583709f6a09c432b4e06ab9353bb4e397d58c451 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Thu, 24 Apr 2025 06:01:49 -0400 Subject: [PATCH] appease `clippy::uninlined-format-args` --- aya-ebpf-macros/src/btf_tracepoint.rs | 2 +- aya-ebpf-macros/src/fentry.rs | 2 +- aya-ebpf-macros/src/fexit.rs | 2 +- aya-ebpf-macros/src/kprobe.rs | 2 +- aya-ebpf-macros/src/lsm.rs | 2 +- aya-ebpf-macros/src/raw_tracepoint.rs | 2 +- aya-ebpf-macros/src/uprobe.rs | 2 +- aya-log/src/lib.rs | 2 +- aya-obj/src/btf/btf.rs | 40 ++++++++++--------------- aya-obj/src/obj.rs | 4 +-- aya-obj/src/relocation.rs | 2 +- aya/src/bpf.rs | 2 +- aya/src/maps/hash_map/hash_map.rs | 2 +- aya/src/maps/mod.rs | 4 +-- aya/src/maps/perf/perf_buffer.rs | 2 +- aya/src/programs/utils.rs | 3 +- aya/src/util.rs | 2 +- test-distro/src/depmod.rs | 8 ++--- test-distro/src/init.rs | 2 +- test-distro/src/modprobe.rs | 6 ++-- test/integration-ebpf/build.rs | 2 +- test/integration-test/src/tests/iter.rs | 4 +-- xtask/src/lib.rs | 2 +- xtask/src/public_api.rs | 9 +++--- xtask/src/run.rs | 6 ++-- 25 files changed, 52 insertions(+), 64 deletions(-) diff --git a/aya-ebpf-macros/src/btf_tracepoint.rs b/aya-ebpf-macros/src/btf_tracepoint.rs index 65d1fb4f..c8f5261a 100644 --- a/aya-ebpf-macros/src/btf_tracepoint.rs +++ b/aya-ebpf-macros/src/btf_tracepoint.rs @@ -30,7 +30,7 @@ impl BtfTracePoint { block: _, } = item; let section_name: Cow<'_, _> = if let Some(function) = function { - format!("tp_btf/{}", function).into() + format!("tp_btf/{function}").into() } else { "tp_btf".into() }; diff --git a/aya-ebpf-macros/src/fentry.rs b/aya-ebpf-macros/src/fentry.rs index 7aaca5d2..aca54757 100644 --- a/aya-ebpf-macros/src/fentry.rs +++ b/aya-ebpf-macros/src/fentry.rs @@ -40,7 +40,7 @@ impl FEntry { } = item; let section_prefix = if *sleepable { "fentry.s" } else { "fentry" }; let section_name: Cow<'_, _> = if let Some(function) = function { - format!("{}/{}", section_prefix, function).into() + format!("{section_prefix}/{function}").into() } else { section_prefix.into() }; diff --git a/aya-ebpf-macros/src/fexit.rs b/aya-ebpf-macros/src/fexit.rs index 8b958477..1a2b15a9 100644 --- a/aya-ebpf-macros/src/fexit.rs +++ b/aya-ebpf-macros/src/fexit.rs @@ -40,7 +40,7 @@ impl FExit { } = item; let section_prefix = if *sleepable { "fexit.s" } else { "fexit" }; let section_name: Cow<'_, _> = if let Some(function) = function { - format!("{}/{}", section_prefix, function).into() + format!("{section_prefix}/{function}").into() } else { section_prefix.into() }; diff --git a/aya-ebpf-macros/src/kprobe.rs b/aya-ebpf-macros/src/kprobe.rs index a46382f3..ba5ea31b 100644 --- a/aya-ebpf-macros/src/kprobe.rs +++ b/aya-ebpf-macros/src/kprobe.rs @@ -44,7 +44,7 @@ impl KProbe { .as_deref() .map(str::parse) .transpose() - .map_err(|err| span.error(format!("failed to parse `offset` argument: {}", err)))?; + .map_err(|err| span.error(format!("failed to parse `offset` argument: {err}")))?; err_on_unknown_args(&args)?; Ok(Self { diff --git a/aya-ebpf-macros/src/lsm.rs b/aya-ebpf-macros/src/lsm.rs index e5c530c4..689a7da7 100644 --- a/aya-ebpf-macros/src/lsm.rs +++ b/aya-ebpf-macros/src/lsm.rs @@ -40,7 +40,7 @@ impl Lsm { } = item; let section_prefix = if *sleepable { "lsm.s" } else { "lsm" }; let section_name: Cow<'_, _> = if let Some(hook) = hook { - format!("{}/{}", section_prefix, hook).into() + format!("{section_prefix}/{hook}").into() } else { section_prefix.into() }; diff --git a/aya-ebpf-macros/src/raw_tracepoint.rs b/aya-ebpf-macros/src/raw_tracepoint.rs index b0c5c103..7e5c6ed2 100644 --- a/aya-ebpf-macros/src/raw_tracepoint.rs +++ b/aya-ebpf-macros/src/raw_tracepoint.rs @@ -29,7 +29,7 @@ impl RawTracePoint { block: _, } = item; let section_name: Cow<'_, _> = if let Some(tracepoint) = tracepoint { - format!("raw_tp/{}", tracepoint).into() + format!("raw_tp/{tracepoint}").into() } else { "raw_tp".into() }; diff --git a/aya-ebpf-macros/src/uprobe.rs b/aya-ebpf-macros/src/uprobe.rs index 1453f99f..290dda33 100644 --- a/aya-ebpf-macros/src/uprobe.rs +++ b/aya-ebpf-macros/src/uprobe.rs @@ -47,7 +47,7 @@ impl UProbe { .as_deref() .map(str::parse) .transpose() - .map_err(|err| span.error(format!("failed to parse `offset` argument: {}", err)))?; + .map_err(|err| span.error(format!("failed to parse `offset` argument: {err}")))?; let sleepable = pop_bool_arg(&mut args, "sleepable"); err_on_unknown_args(&args)?; Ok(Self { diff --git a/aya-log/src/lib.rs b/aya-log/src/lib.rs index 03d83182..ab1fb850 100644 --- a/aya-log/src/lib.rs +++ b/aya-log/src/lib.rs @@ -690,7 +690,7 @@ fn log_buf(mut buf: &[u8], logger: &dyn Log) -> Result<(), ()> { Ok(v) => { full_log_msg.push_str(v); } - Err(e) => error!("received invalid utf8 string: {}", e), + Err(e) => error!("received invalid utf8 string: {e}"), }, } diff --git a/aya-obj/src/btf/btf.rs b/aya-obj/src/btf/btf.rs index c0e5ea33..b998cbde 100644 --- a/aya-obj/src/btf/btf.rs +++ b/aya-obj/src/btf/btf.rs @@ -516,7 +516,7 @@ impl Btf { } // Sanitize DATASEC if they are not supported. BtfType::DataSec(d) if !features.btf_datasec => { - debug!("{}: not supported. replacing with STRUCT", kind); + debug!("{kind}: not supported. replacing with STRUCT"); // STRUCT aren't allowed to have "." in their name, fixup this if needed. let mut name_offset = d.name_offset; @@ -565,7 +565,7 @@ impl Btf { // There are some cases when the compiler does indeed populate the size. if d.size > 0 { - debug!("{} {}: size fixup not required", kind, name); + debug!("{kind} {name}: size fixup not required"); } else { // We need to get the size of the section from the ELF file. // Fortunately, we cached these when parsing it initially @@ -576,7 +576,7 @@ impl Btf { return Err(BtfError::UnknownSectionSize { section_name: name }); } }; - debug!("{} {}: fixup size to {}", kind, name, size); + debug!("{kind} {name}: fixup size to {size}"); d.size = *size as u32; // The Vec contains BTF_KIND_VAR sections @@ -591,10 +591,7 @@ impl Btf { if let BtfType::Var(var) = types.type_by_id(e.btf_type)? { let var_name = self.string_at(var.name_offset)?; if var.linkage == VarLinkage::Static { - debug!( - "{} {}: VAR {}: fixup not required", - kind, name, var_name - ); + debug!("{kind} {name}: VAR {var_name}: fixup not required"); continue; } @@ -607,10 +604,7 @@ impl Btf { } }; e.offset = *offset as u32; - debug!( - "{} {}: VAR {}: fixup offset {}", - kind, name, var_name, offset - ); + debug!("{kind} {name}: VAR {var_name}: fixup offset {offset}"); } else { return Err(BtfError::InvalidDatasec); } @@ -632,7 +626,7 @@ impl Btf { } // Sanitize FUNC_PROTO. BtfType::FuncProto(ty) if !features.btf_func => { - debug!("{}: not supported. replacing with ENUM", kind); + debug!("{kind}: not supported. replacing with ENUM"); let members: Vec = ty .params .iter() @@ -649,7 +643,7 @@ impl Btf { let name = self.string_at(ty.name_offset)?; // Sanitize FUNC. if !features.btf_func { - debug!("{}: not supported. replacing with TYPEDEF", kind); + debug!("{kind}: not supported. replacing with TYPEDEF"); *t = BtfType::Typedef(Typedef::new(ty.name_offset, ty.btf_type)); } else if !features.btf_func_global || name == "memset" @@ -665,8 +659,7 @@ impl Btf { if ty.linkage() == FuncLinkage::Global { if !features.btf_func_global { debug!( - "{}: BTF_FUNC_GLOBAL not supported. replacing with BTF_FUNC_STATIC", - kind + "{kind}: BTF_FUNC_GLOBAL not supported. replacing with BTF_FUNC_STATIC", ); } else { debug!("changing FUNC {name} linkage to BTF_FUNC_STATIC"); @@ -677,27 +670,27 @@ impl Btf { } // Sanitize FLOAT. BtfType::Float(ty) if !features.btf_float => { - debug!("{}: not supported. replacing with STRUCT", kind); + debug!("{kind}: not supported. replacing with STRUCT"); *t = BtfType::Struct(Struct::new(0, vec![], ty.size)); } // Sanitize DECL_TAG. BtfType::DeclTag(ty) if !features.btf_decl_tag => { - debug!("{}: not supported. replacing with INT", kind); + debug!("{kind}: not supported. replacing with INT"); *t = BtfType::Int(Int::new(ty.name_offset, 1, IntEncoding::None, 0)); } // Sanitize TYPE_TAG. BtfType::TypeTag(ty) if !features.btf_type_tag => { - debug!("{}: not supported. replacing with CONST", kind); + debug!("{kind}: not supported. replacing with CONST"); *t = BtfType::Const(Const::new(ty.btf_type)); } // Sanitize Signed ENUMs. BtfType::Enum(ty) if !features.btf_enum64 && ty.is_signed() => { - debug!("{}: signed ENUMs not supported. Marking as unsigned", kind); + debug!("{kind}: signed ENUMs not supported. Marking as unsigned"); ty.set_signed(false); } // Sanitize ENUM64. BtfType::Enum64(ty) if !features.btf_enum64 => { - debug!("{}: not supported. replacing with UNION", kind); + debug!("{kind}: not supported. replacing with UNION"); let placeholder_id = enum64_placeholder_id.expect("enum64_placeholder_id must be set"); let members: Vec = ty @@ -1215,7 +1208,7 @@ mod tests { ] }; assert_eq!(data.len(), 517); - let btf = Btf::parse(data, Endianness::default()).unwrap_or_else(|e| panic!("{}", e)); + let btf = Btf::parse(data, Endianness::default()).unwrap(); let data2 = btf.to_bytes(); assert_eq!(data2.len(), 517); assert_eq!(data, data2); @@ -1259,8 +1252,7 @@ mod tests { let ext_data = unsafe { bytes_of::(&test_data).to_vec() }; assert_eq!(ext_data.len(), 80); - let _: BtfExt = BtfExt::parse(&ext_data, Endianness::default(), &btf) - .unwrap_or_else(|e| panic!("{}", e)); + let _: BtfExt = BtfExt::parse(&ext_data, Endianness::default(), &btf).unwrap(); } #[test] @@ -1323,7 +1315,7 @@ mod tests { let btf_bytes = btf.to_bytes(); let raw_btf = btf_bytes.as_slice(); - let btf = Btf::parse(raw_btf, Endianness::default()).unwrap_or_else(|e| panic!("{}", e)); + let btf = Btf::parse(raw_btf, Endianness::default()).unwrap(); assert_eq!(btf.string_at(1).unwrap(), "int"); assert_eq!(btf.string_at(5).unwrap(), "widget"); } diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index 871e6937..8faa8741 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -1322,12 +1322,12 @@ fn parse_btf_map_def(btf: &Btf, info: &DataSecEntry) -> Result<(String, BtfMapDe "pinning" => { let pinning = get_map_field(btf, m.btf_type)?; map_def.pinning = PinningType::try_from(pinning).unwrap_or_else(|_| { - debug!("{} is not a valid pin type. using PIN_NONE", pinning); + debug!("{pinning} is not a valid pin type. using PIN_NONE"); PinningType::None }); } other => { - debug!("skipping unknown map section: {}", other); + debug!("skipping unknown map section: {other}"); continue; } } diff --git a/aya-obj/src/relocation.rs b/aya-obj/src/relocation.rs index 06f214ea..8c0becd5 100644 --- a/aya-obj/src/relocation.rs +++ b/aya-obj/src/relocation.rs @@ -239,7 +239,7 @@ fn relocate_maps<'a, I: Iterator>( m } else { let Some(m) = maps_by_section.get(§ion_index) else { - debug!("failed relocating map by section index {}", section_index); + debug!("failed relocating map by section index {section_index}"); return Err(RelocationError::SectionNotFound { symbol_index: rel.symbol_index, symbol_name: sym.name.clone(), diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index 9c11defc..1a300198 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -86,7 +86,7 @@ fn detect_features() -> Features { is_info_gpl_compatible_supported(), btf, ); - debug!("BPF Feature Detection: {:#?}", f); + debug!("BPF Feature Detection: {f:#?}"); f } diff --git a/aya/src/maps/hash_map/hash_map.rs b/aya/src/maps/hash_map/hash_map.rs index d88b5057..e8d2c463 100644 --- a/aya/src/maps/hash_map/hash_map.rs +++ b/aya/src/maps/hash_map/hash_map.rs @@ -457,7 +457,7 @@ mod tests { Some(10) => set_next_key(attr, 20), Some(20) => sys_error(EFAULT), Some(30) => sys_error(ENOENT), - Some(i) => panic!("invalid key {}", i), + Some(i) => panic!("invalid key {i}"), }, Syscall::Ebpf { cmd: bpf_cmd::BPF_MAP_LOOKUP_ELEM, diff --git a/aya/src/maps/mod.rs b/aya/src/maps/mod.rs index 511fcc57..849b14bc 100644 --- a/aya/src/maps/mod.rs +++ b/aya/src/maps/mod.rs @@ -254,7 +254,7 @@ fn maybe_warn_rlimit() { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let &Self(size) = self; if size < 1024 { - write!(f, "{} bytes", size) + write!(f, "{size} bytes") } else if size < 1024 * 1024 { write!(f, "{} KiB", size / 1024) } else { @@ -1020,7 +1020,7 @@ mod test_utils { cmd: bpf_cmd::BPF_MAP_CREATE, .. } => Ok(crate::MockableFd::mock_signed_fd().into()), - call => panic!("unexpected syscall {:?}", call), + call => panic!("unexpected syscall {call:?}"), }); MapData::create(obj, "foo", None).unwrap() } diff --git a/aya/src/maps/perf/perf_buffer.rs b/aya/src/maps/perf/perf_buffer.rs index 387d7ff5..27554ac7 100644 --- a/aya/src/maps/perf/perf_buffer.rs +++ b/aya/src/maps/perf/perf_buffer.rs @@ -290,7 +290,7 @@ mod tests { override_syscall(|call| match call { Syscall::PerfEventOpen { .. } => Ok(crate::MockableFd::mock_signed_fd().into()), Syscall::PerfEventIoctl { .. } => Ok(0), - call => panic!("unexpected syscall: {:?}", call), + call => panic!("unexpected syscall: {call:?}"), }); TEST_MMAP_RET.with(|ret| *ret.borrow_mut() = buf.cast()); } diff --git a/aya/src/programs/utils.rs b/aya/src/programs/utils.rs index a1728893..f9119617 100644 --- a/aya/src/programs/utils.rs +++ b/aya/src/programs/utils.rs @@ -65,8 +65,7 @@ pub(crate) fn boot_time() -> SystemTime { assert_eq!( unsafe { libc::clock_gettime(clock_id, &mut time) }, 0, - "clock_gettime({}, _)", - clock_id + "clock_gettime({clock_id}, _)" ); let libc::timespec { tv_sec, tv_nsec } = time; diff --git a/aya/src/util.rs b/aya/src/util.rs index 4635e837..cd3b7ac6 100644 --- a/aya/src/util.rs +++ b/aya/src/util.rs @@ -342,7 +342,7 @@ pub fn syscall_prefix() -> Result<&'static str, io::Error> { ]; let ksym = kernel_symbols()?; for p in PREFIXES { - let prefixed_syscall = format!("{}bpf", p); + let prefixed_syscall = format!("{p}bpf"); if ksym.values().any(|el| *el == prefixed_syscall) { return Ok(p); } diff --git a/test-distro/src/depmod.rs b/test-distro/src/depmod.rs index c4dca8c5..2e782d34 100644 --- a/test-distro/src/depmod.rs +++ b/test-distro/src/depmod.rs @@ -110,14 +110,14 @@ fn read_aliases_from_module( let end = start + s.size() as usize; let sym_data = &data[start..end]; let cstr = std::ffi::CStr::from_bytes_with_nul(sym_data) - .with_context(|| format!("failed to convert {:?} to cstr", sym_data))?; + .with_context(|| format!("failed to convert {sym_data:?} to cstr"))?; let sym_str = cstr .to_str() - .with_context(|| format!("failed to convert {:?} to str", cstr))?; + .with_context(|| format!("failed to convert {cstr:?} to str"))?; let alias = sym_str .strip_prefix("alias=") - .with_context(|| format!("failed to strip prefix 'alias=' from {}", sym_str))?; - writeln!(output, "alias {} {}", alias, module_name).expect("write"); + .with_context(|| format!("failed to strip prefix 'alias=' from {sym_str}"))?; + writeln!(output, "alias {alias} {module_name}").expect("write"); } } Ok(()) diff --git a/test-distro/src/init.rs b/test-distro/src/init.rs index 7dd9d952..2b78ceff 100644 --- a/test-distro/src/init.rs +++ b/test-distro/src/init.rs @@ -15,7 +15,7 @@ impl std::fmt::Display for Errors { if i != 0 { writeln!(f)?; } - write!(f, "{:?}", error)?; + write!(f, "{error:?}")?; } Ok(()) } diff --git a/test-distro/src/modprobe.rs b/test-distro/src/modprobe.rs index 07300503..de56c757 100644 --- a/test-distro/src/modprobe.rs +++ b/test-distro/src/modprobe.rs @@ -51,7 +51,7 @@ fn try_main(quiet: bool, name: String) -> anyhow::Result<()> { module ); let module_path = glob(&pattern) - .with_context(|| format!("failed to glob: {}", pattern))? + .with_context(|| format!("failed to glob: {pattern}"))? .next() .ok_or_else(|| anyhow!("module not found: {}", module))? .context("glob error")?; @@ -106,10 +106,10 @@ fn resolve_alias(quiet: bool, module_dir: &Path, name: &str) -> anyhow::Result (), - Diff::Right(line) => writeln!(&mut buf, "-{}", line).unwrap(), - Diff::Left(line) => writeln!(&mut buf, "+{}", line).unwrap(), + Diff::Right(line) => writeln!(&mut buf, "-{line}").unwrap(), + Diff::Left(line) => writeln!(&mut buf, "+{line}").unwrap(), }; buf })) diff --git a/xtask/src/run.rs b/xtask/src/run.rs index 187828f9..218642c1 100644 --- a/xtask/src/run.rs +++ b/xtask/src/run.rs @@ -448,7 +448,7 @@ pub fn run(opts: Options) -> Result<()> { for (profile, binaries) in binaries { for (name, binary) in binaries { - let name = format!("{}-{}", profile, name); + let name = format!("{profile}-{name}"); let path = tmp_dir.path().join(&name); copy(&binary, &path).with_context(|| { format!("copy({}, {}) failed", binary.display(), path.display()) @@ -558,7 +558,7 @@ pub fn run(opts: Options) -> Result<()> { .spawn(move || { for line in stderr.lines() { let line = line.context("failed to read line from stderr")?; - eprintln!("{}", line); + eprintln!("{line}"); terminate_if_kernel_hang(&line, &stdin)?; } anyhow::Ok(()) @@ -569,7 +569,7 @@ pub fn run(opts: Options) -> Result<()> { let mut outcome = None; for line in stdout.lines() { let line = line.context("failed to read line from stdout")?; - println!("{}", line); + println!("{line}"); terminate_if_kernel_hang(&line, &stdin)?; // The init program will print "init: success" or "init: failure" to indicate // the outcome of running the binaries it found in /bin.