appease `clippy::uninlined-format-args`

main
Tamir Duberstein 2 days ago
parent c65a200e9a
commit 583709f6a0

@ -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()
};

@ -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()
};

@ -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()
};

@ -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 {

@ -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()
};

@ -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()
};

@ -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 {

@ -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}"),
},
}

@ -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<btf_var_secinfo> 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<BtfEnum> = 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<BtfMember> = 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::<TestStruct>(&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");
}

@ -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;
}
}

@ -239,7 +239,7 @@ fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
m
} else {
let Some(m) = maps_by_section.get(&section_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(),

@ -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
}

@ -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,

@ -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()
}

@ -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());
}

@ -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;

@ -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);
}

@ -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(())

@ -15,7 +15,7 @@ impl std::fmt::Display for Errors {
if i != 0 {
writeln!(f)?;
}
write!(f, "{:?}", error)?;
write!(f, "{error:?}")?;
}
Ok(())
}

@ -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<S
}
let alias = parts
.next()
.with_context(|| format!("alias line missing alias: {}", line))?;
.with_context(|| format!("alias line missing alias: {line}"))?;
let module = parts
.next()
.with_context(|| format!("alias line missing module: {}", line))?;
.with_context(|| format!("alias line missing module: {line}"))?;
if parts.next().is_some() {
bail!("alias line has too many parts: {}", line);
}

@ -15,7 +15,7 @@ use xtask::AYA_BUILD_INTEGRATION_BPF;
///
/// [bindeps]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies
fn main() {
println!("cargo:rerun-if-env-changed={}", AYA_BUILD_INTEGRATION_BPF);
println!("cargo:rerun-if-env-changed={AYA_BUILD_INTEGRATION_BPF}");
let build_integration_bpf = env::var(AYA_BUILD_INTEGRATION_BPF)
.as_deref()

@ -23,8 +23,6 @@ fn iter_task() {
let expected_values = ["1 1 init", "1 1 systemd"];
assert!(
expected_values.contains(&line_init.as_str()),
"Unexpected line_init value: '{}', expected one of: {:?}",
line_init,
expected_values
"Unexpected line_init value: '{line_init}', expected one of: {expected_values:?}"
);
}

@ -55,7 +55,7 @@ where
if i != 0 {
writeln!(f)?;
}
write!(f, "{:?}", error)?;
write!(f, "{error:?}")?;
}
Ok(())
}

@ -117,8 +117,7 @@ fn check_package_api(
}
let rustdoc_json = builder.build().with_context(|| {
format!(
"rustdoc_json::Builder::default().toolchain({}).package({}).build()",
toolchain, package
"rustdoc_json::Builder::default().toolchain({toolchain}).package({package}).build()"
)
})?;
@ -134,7 +133,7 @@ fn check_package_api(
if bless {
let mut output =
File::create(&path).with_context(|| format!("error creating {}", path.display()))?;
write!(&mut output, "{}", public_api)
write!(&mut output, "{public_api}")
.with_context(|| format!("error writing {}", path.display()))?;
}
let current_api =
@ -145,8 +144,8 @@ fn check_package_api(
.fold(String::new(), |mut buf, diff| {
match diff {
Diff::Both(..) => (),
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
}))

@ -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.

Loading…
Cancel
Save