Skip to content

Commit 78a5f52

Browse files
d-e-s-odanielocfb
authored andcommitted
Fix clippy reported issues
With Rust 1.67 clippy warns about us not inlining some variables in format strings in some locations. Follow the suggestions mostly, except where we are dealing with large code blocks that already contain curly braces. Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent 5553d9c commit 78a5f52

File tree

19 files changed

+80
-120
lines changed

19 files changed

+80
-120
lines changed

examples/capable/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ fn main() {
1111
.source(SRC)
1212
.build_and_generate(&out)
1313
.unwrap();
14-
println!("cargo:rerun-if-changed={}", SRC);
14+
println!("cargo:rerun-if-changed={SRC}");
1515
}

examples/capable/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn _handle_event(opts: Command, event: capable_bss_types::event) {
167167
}
168168

169169
fn handle_lost_events(cpu: i32, count: u64) {
170-
eprintln!("Lost {} events on CPU {}", count, cpu);
170+
eprintln!("Lost {count} events on CPU {cpu}");
171171
}
172172

173173
fn main() -> Result<()> {

examples/runqslower/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ fn main() {
1111
.source(SRC)
1212
.build_and_generate(&out)
1313
.unwrap();
14-
println!("cargo:rerun-if-changed={}", SRC);
14+
println!("cargo:rerun-if-changed={SRC}");
1515
}

examples/runqslower/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn handle_event(_cpu: i32, data: &[u8]) {
7171
}
7272

7373
fn handle_lost_events(cpu: i32, count: u64) {
74-
eprintln!("Lost {} events on CPU {}", count, cpu);
74+
eprintln!("Lost {count} events on CPU {cpu}");
7575
}
7676

7777
fn main() -> Result<()> {

examples/tc_port_whitelist/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ fn main() {
1111
.source(SRC)
1212
.build_and_generate(&out)
1313
.unwrap();
14-
println!("cargo:rerun-if-changed={}", SRC);
14+
println!("cargo:rerun-if-changed={SRC}");
1515
}

examples/tc_port_whitelist/src/main.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,28 @@ fn main() -> Result<()> {
8080

8181
if opts.query {
8282
match custom.query() {
83-
Err(e) => println!("failed to find custom hook: {}", e),
84-
Ok(prog_id) => println!("found custom hook prog_id: {}", prog_id),
83+
Err(e) => println!("failed to find custom hook: {e}"),
84+
Ok(prog_id) => println!("found custom hook prog_id: {prog_id}"),
8585
}
8686
match egress.query() {
87-
Err(e) => println!("failed to find custom hook: {}", e),
88-
Ok(prog_id) => println!("found custom hook prog_id: {}", prog_id),
87+
Err(e) => println!("failed to find custom hook: {e}"),
88+
Ok(prog_id) => println!("found custom hook prog_id: {prog_id}"),
8989
}
9090
match ingress.query() {
91-
Err(e) => println!("failed to find custom hook: {}", e),
92-
Ok(prog_id) => println!("found custom hook prog_id: {}", prog_id),
91+
Err(e) => println!("failed to find custom hook: {e}"),
92+
Ok(prog_id) => println!("found custom hook prog_id: {prog_id}"),
9393
}
9494
}
9595

9696
if opts.detach {
9797
if let Err(e) = ingress.detach() {
98-
println!("failed to detach ingress hook {}", e);
98+
println!("failed to detach ingress hook {e}");
9999
}
100100
if let Err(e) = egress.detach() {
101-
println!("failed to detach egress hook {}", e);
101+
println!("failed to detach egress hook {e}");
102102
}
103103
if let Err(e) = custom.detach() {
104-
println!("failed to detach custom hook {}", e);
104+
println!("failed to detach custom hook {e}");
105105
}
106106
}
107107

@@ -110,27 +110,27 @@ fn main() -> Result<()> {
110110
let key = (i as u32).to_ne_bytes();
111111
let val = port.to_ne_bytes();
112112
if let Err(e) = skel.maps_mut().ports().update(&key, &val, MapFlags::ANY) {
113-
bail!("Example limited to 10 ports: {}", e);
113+
bail!("Example limited to 10 ports: {e}");
114114
}
115115
}
116116
ingress.create()?;
117117

118118
if let Err(e) = egress.attach() {
119-
println!("failed to attach egress hook {}", e);
119+
println!("failed to attach egress hook {e}");
120120
}
121121

122122
if let Err(e) = ingress.attach() {
123-
println!("failed to attach ingress hook {}", e);
123+
println!("failed to attach ingress hook {e}");
124124
}
125125

126126
if let Err(e) = custom.attach() {
127-
println!("failed to attach custom hook {}", e);
127+
println!("failed to attach custom hook {e}");
128128
}
129129
}
130130

131131
if opts.destroy {
132132
if let Err(e) = destroy_all.destroy() {
133-
println!("failed to destroy all {}", e);
133+
println!("failed to destroy all {e}");
134134
}
135135
}
136136

examples/tproxy/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ fn main() {
1212
.clang_args("-Wno-compare-distinct-pointer-types")
1313
.build_and_generate(&out)
1414
.unwrap();
15-
println!("cargo:rerun-if-changed={}", SRC);
15+
println!("cargo:rerun-if-changed={SRC}");
1616
}

examples/tproxy/src/bin/proxy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ fn handle_client(client: TcpStream) -> Result<()> {
2929
let peer_addr = client.peer_addr().context("Failed to get peer addr")?;
3030

3131
println!("New connection:");
32-
println!("\tlocal: {}", local_addr);
33-
println!("\tpeer: {}", peer_addr);
32+
println!("\tlocal: {local_addr}");
33+
println!("\tpeer: {peer_addr}");
3434
println!();
3535

3636
Ok(())

examples/tproxy/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ fn main() -> Result<()> {
8686
}
8787

8888
if let Err(e) = ingress.detach() {
89-
eprintln!("Failed to detach prog: {}", e);
89+
eprintln!("Failed to detach prog: {e}");
9090
}
9191
if let Err(e) = ingress.destroy() {
92-
eprintln!("Failed to destroy TC hook: {}", e);
92+
eprintln!("Failed to destroy TC hook: {e}");
9393
}
9494

9595
Ok(())

libbpf-cargo/src/btf/btf.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,12 @@ impl Btf {
552552
};
553553

554554
match t.encoding {
555-
btf::BtfIntEncoding::Signed => format!("i{}", width),
555+
btf::BtfIntEncoding::Signed => format!("i{width}"),
556556
btf::BtfIntEncoding::Bool => {
557557
assert!(t.bits as usize == (std::mem::size_of::<bool>() * 8));
558558
"bool".to_string()
559559
}
560-
btf::BtfIntEncoding::Char | btf::BtfIntEncoding::None => format!("u{}", width),
560+
btf::BtfIntEncoding::Char | btf::BtfIntEncoding::None => format!("u{width}"),
561561
}
562562
}
563563
BtfType::Float(t) => {
@@ -570,12 +570,12 @@ impl Btf {
570570
_ => bail!("Invalid float width"),
571571
};
572572

573-
format!("f{}", width)
573+
format!("f{width}")
574574
}
575575
BtfType::Ptr(t) => {
576576
let pointee_ty = self.type_declaration(t.pointee_type)?;
577577

578-
format!("*mut {}", pointee_ty)
578+
format!("*mut {pointee_ty}")
579579
}
580580
BtfType::Array(t) => {
581581
let val_ty = self.type_declaration(t.val_type_id)?;
@@ -832,16 +832,11 @@ impl Btf {
832832
)?;
833833

834834
if padding != 0 {
835-
agg_content.push(format!(
836-
r#" __pad_{offset}: [u8; {padding}],"#,
837-
offset = offset,
838-
padding = padding,
839-
));
835+
agg_content
836+
.push(format!(r#" __pad_{offset}: [u8; {padding}],"#,));
840837

841838
impl_default.push(format!(
842839
r#" __pad_{offset}: [u8::default(); {padding}]"#,
843-
offset = offset,
844-
padding = padding,
845840
));
846841
}
847842

@@ -877,7 +872,7 @@ impl Btf {
877872
field_ty_str.clone()
878873
};
879874

880-
agg_content.push(format!(r#" pub {}: {},"#, field_name, field_ty_str));
875+
agg_content.push(format!(r#" pub {field_name}: {field_ty_str},"#));
881876
}
882877

883878
if t.is_struct {
@@ -903,7 +898,7 @@ impl Btf {
903898
let aggregate_type = if t.is_struct { "struct" } else { "union" };
904899
let packed_repr = if packed { ", packed" } else { "" };
905900

906-
writeln!(def, r#"#[repr(C{})]"#, packed_repr)?;
901+
writeln!(def, r#"#[repr(C{packed_repr})]"#)?;
907902
writeln!(
908903
def,
909904
r#"pub {agg_type} {name} {{"#,
@@ -912,7 +907,7 @@ impl Btf {
912907
)?;
913908

914909
for field in agg_content {
915-
writeln!(def, "{}", field)?;
910+
writeln!(def, "{field}")?;
916911
}
917912
writeln!(def, "}}")?;
918913

@@ -922,7 +917,7 @@ impl Btf {
922917
writeln!(def, r#" fn default() -> Self {{"#)?;
923918
writeln!(def, r#" {} {{"#, t.name)?;
924919
for impl_def in impl_default {
925-
writeln!(def, r#"{},"#, impl_def)?;
920+
writeln!(def, r#"{impl_def},"#)?;
926921
}
927922
writeln!(def, r#" }}"#)?;
928923
writeln!(def, r#" }}"#)?;
@@ -967,13 +962,8 @@ impl Btf {
967962
}
968963

969964
writeln!(def, r#"#[derive(Debug, Copy, Clone, PartialEq, Eq)]"#)?;
970-
writeln!(
971-
def,
972-
r#"#[repr({signed}{repr_size})]"#,
973-
signed = signed,
974-
repr_size = repr_size,
975-
)?;
976-
writeln!(def, r#"pub enum {name} {{"#, name = t.name,)?;
965+
writeln!(def, r#"#[repr({signed}{repr_size})]"#)?;
966+
writeln!(def, r#"pub enum {name} {{"#, name = t.name)?;
977967

978968
for value in &t.values {
979969
writeln!(
@@ -1012,7 +1002,7 @@ impl Btf {
10121002

10131003
writeln!(def, r#"#[derive(Debug, Copy, Clone)]"#)?;
10141004
writeln!(def, r#"#[repr(C)]"#)?;
1015-
writeln!(def, r#"pub struct {} {{"#, sec_name,)?;
1005+
writeln!(def, r#"pub struct {sec_name} {{"#)?;
10161006

10171007
let mut offset: u32 = 0;
10181008
for datasec_var in &t.vars {
@@ -1039,7 +1029,7 @@ impl Btf {
10391029
false,
10401030
)?;
10411031
if padding != 0 {
1042-
writeln!(def, r#" __pad_{}: [u8; {}],"#, offset, padding,)?;
1032+
writeln!(def, r#" __pad_{offset}: [u8; {padding}],"#)?;
10431033
}
10441034

10451035
// Set `offset` to end of current var

0 commit comments

Comments
 (0)