Skip to content

Commit

Permalink
Merge pull request #456 from dmitris/uninlined_format_args
Browse files Browse the repository at this point in the history
autofix clippy uninlined_format_args issues
  • Loading branch information
vadorovsky committed Dec 5, 2022
2 parents 52b9ffe + 055d94f commit 16b029e
Show file tree
Hide file tree
Showing 27 changed files with 91 additions and 92 deletions.
28 changes: 14 additions & 14 deletions aya-bpf-macros/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl SockOps {

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("sockops/{}", name)
format!("sockops/{name}")
} else {
"sockops".to_owned()
};
Expand Down Expand Up @@ -208,7 +208,7 @@ impl Xdp {

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("xdp/{}", name)
format!("xdp/{name}")
} else {
"xdp".to_owned()
};
Expand Down Expand Up @@ -240,7 +240,7 @@ impl SchedClassifier {

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("classifier/{}", name)
format!("classifier/{name}")
} else {
"classifier".to_owned()
};
Expand Down Expand Up @@ -272,7 +272,7 @@ impl CgroupSysctl {

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("cgroup/sysctl/{}", name)
format!("cgroup/sysctl/{name}")
} else {
("cgroup/sysctl").to_owned()
};
Expand Down Expand Up @@ -349,12 +349,12 @@ impl CgroupSkb {
pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(attach) = &self.expected_attach_type {
if let Some(name) = &self.name {
format!("cgroup_skb/{}/{}", attach, name)
format!("cgroup_skb/{attach}/{name}")
} else {
format!("cgroup_skb/{}", attach)
format!("cgroup_skb/{attach}")
}
} else if let Some(name) = &self.name {
format!("cgroup/skb/{}", name)
format!("cgroup/skb/{name}")
} else {
("cgroup/skb").to_owned()
};
Expand Down Expand Up @@ -432,12 +432,12 @@ impl CgroupSock {
pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
if let Some(attach_type) = &self.attach_type {
format!("cgroup/{}/{}", attach_type, name)
format!("cgroup/{attach_type}/{name}")
} else {
format!("cgroup/sock/{}", name)
format!("cgroup/sock/{name}")
}
} else if let Some(attach_type) = &self.attach_type {
format!("cgroup/{}", attach_type)
format!("cgroup/{attach_type}")
} else {
"cgroup/sock".to_string()
};
Expand Down Expand Up @@ -679,9 +679,9 @@ impl SkSkb {
pub fn expand(&self) -> Result<TokenStream> {
let kind = &self.kind;
let section_name = if let Some(name) = &self.name {
format!("sk_skb/{}/{}", kind, name)
format!("sk_skb/{kind}/{name}")
} else {
format!("sk_skb/{}", kind)
format!("sk_skb/{kind}")
};
let fn_name = &self.item.sig.ident;
let item = &self.item;
Expand Down Expand Up @@ -712,7 +712,7 @@ impl SocketFilter {

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("socket/{}", name)
format!("socket/{name}")
} else {
"socket".to_owned()
};
Expand Down Expand Up @@ -802,7 +802,7 @@ impl SkLookup {

pub fn expand(&self) -> Result<TokenStream> {
let section_name = if let Some(name) = &self.name {
format!("sk_lookup/{}", name)
format!("sk_lookup/{name}")
} else {
"sk_lookup".to_owned()
};
Expand Down
4 changes: 2 additions & 2 deletions aya-log-ebpf-macros/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Parse for LogArgs {
}

fn string_to_expr(s: String) -> Result<Expr> {
parse_str(&format!("\"{}\"", s))
parse_str(&format!("\"{s}\""))
}

fn hint_to_expr(hint: DisplayHint) -> Result<Expr> {
Expand Down Expand Up @@ -108,7 +108,7 @@ pub(crate) fn log(args: LogArgs, level: Option<TokenStream>) -> Result<TokenStre
let fragments = parse(&format_string_val).map_err(|e| {
Error::new(
format_string.span(),
format!("could not parse the format string: {}", e),
format!("could not parse the format string: {e}"),
)
})?;

Expand Down
4 changes: 2 additions & 2 deletions aya-log-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn parse_display_hint(s: &str) -> Result<DisplayHint, String> {
"ipv6" => DisplayHint::Ipv6,
"mac" => DisplayHint::LowerMac,
"MAC" => DisplayHint::UpperMac,
_ => return Err(format!("unknown display hint: {:?}", s)),
_ => return Err(format!("unknown display hint: {s:?}")),
})
}

Expand All @@ -83,7 +83,7 @@ fn parse_param(mut input: &str) -> Result<Parameter, String> {

hint = parse_display_hint(input)?;
} else if !input.is_empty() {
return Err(format!("unexpected content {:?} in format string", input));
return Err(format!("unexpected content {input:?} in format string"));
}

Ok(Parameter { hint })
Expand Down
7 changes: 3 additions & 4 deletions aya-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ where
T: LowerHex,
{
fn format(v: T) -> String {
format!("{:x}", v)
format!("{v:x}")
}
}

Expand All @@ -147,7 +147,7 @@ where
T: UpperHex,
{
fn format(v: T) -> String {
format!("{:X}", v)
format!("{v:X}")
}
}

Expand Down Expand Up @@ -481,7 +481,7 @@ fn log_buf(mut buf: &[u8], logger: &dyn Log) -> Result<(), ()> {

logger.log(
&Record::builder()
.args(format_args!("{}", full_log_msg))
.args(format_args!("{full_log_msg}"))
.target(target.ok_or(())?)
.level(level)
.module_path(module)
Expand Down Expand Up @@ -529,7 +529,6 @@ mod test {
use super::*;
use aya_log_common::{write_record_header, WriteToBuf};
use log::logger;
use testing_logger;

fn new_log(args: usize) -> Result<(usize, Vec<u8>), ()> {
let mut buf = vec![0; 8192];
Expand Down
2 changes: 1 addition & 1 deletion aya-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]
bindgen = "0.63"
clap = { version = "3", features = ["derive"] }
clap = { version = "4", features = ["derive"] }
anyhow = "1"
thiserror = "1"
tempfile = "3"
4 changes: 2 additions & 2 deletions aya-tool/src/bin/aya-tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum Command {

fn main() {
if let Err(e) = try_main() {
eprintln!("{:#}", e);
eprintln!("{e:#}");
exit(1);
}
}
Expand All @@ -47,7 +47,7 @@ fn try_main() -> Result<(), anyhow::Error> {
} else {
generate(InputFile::Btf(btf), &names, &bindgen_args)?
};
println!("{}", bindings);
println!("{bindings}");
}
};

Expand Down
2 changes: 1 addition & 1 deletion aya/src/obj/btf/btf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl Btf {
let mut ty = ty.clone();
for (i, mut param) in ty.params.iter_mut().enumerate() {
if param.name_offset == 0 && param.btf_type != 0 {
param.name_offset = self.add_string(format!("param{}", i));
param.name_offset = self.add_string(format!("param{i}"));
}
}
types.types[i] = BtfType::FuncProto(ty);
Expand Down
12 changes: 6 additions & 6 deletions aya/src/obj/btf/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ impl<'a> AccessSpec<'a> {
rel_kind => {
return Err(RelocationError::InvalidRelocationKindForType {
relocation_number: relocation.number,
relocation_kind: format!("{:?}", rel_kind),
relocation_kind: format!("{rel_kind:?}"),
type_kind: format!("{:?}", ty.kind()),
error: "field relocation on a type that doesn't have fields"
.to_string(),
Expand Down Expand Up @@ -791,7 +791,7 @@ impl ComputedRelocation {
return Err(RelocationError::InvalidInstruction {
relocation_number: rel.number,
index: ins_index,
error: format!("invalid src_reg={:x} expected {:x}", src_reg, BPF_K),
error: format!("invalid src_reg={src_reg:x} expected {BPF_K:x}"),
}
.into());
}
Expand All @@ -803,7 +803,7 @@ impl ComputedRelocation {
return Err(RelocationError::InvalidInstruction {
relocation_number: rel.number,
index: ins_index,
error: format!("value `{}` overflows 16 bits offset field", target_value),
error: format!("value `{target_value}` overflows 16 bits offset field"),
}
.into());
}
Expand Down Expand Up @@ -844,7 +844,7 @@ impl ComputedRelocation {
return Err(RelocationError::InvalidInstruction {
relocation_number: rel.number,
index: ins_index,
error: format!("invalid target size {}", size),
error: format!("invalid target size {size}"),
}
.into())
}
Expand All @@ -868,7 +868,7 @@ impl ComputedRelocation {
return Err(RelocationError::InvalidInstruction {
relocation_number: rel.number,
index: ins_index,
error: format!("invalid instruction class {:x}", class),
error: format!("invalid instruction class {class:x}"),
}
.into())
}
Expand Down Expand Up @@ -938,7 +938,7 @@ impl ComputedRelocation {
let ty = spec.btf.type_by_id(accessor.type_id)?;
return Err(RelocationError::InvalidRelocationKindForType {
relocation_number: rel.number,
relocation_kind: format!("{:?}", rel_kind),
relocation_kind: format!("{rel_kind:?}"),
type_kind: format!("{:?}", ty.kind()),
error: "invalid relocation kind for array type".to_string(),
}
Expand Down
Loading

0 comments on commit 16b029e

Please sign in to comment.