Skip to content

Commit e4dbcbb

Browse files
ojedaSasha Levin
authored and
Sasha Levin
committed
rust: clean Rust 1.88.0's clippy::uninlined_format_args lint
commit 211dcf7 upstream. Starting with Rust 1.88.0 (expected 2025-06-26) [1], `rustc` may move back the `uninlined_format_args` to `style` from `pedantic` (it was there waiting for rust-analyzer suppotr), and thus we will start to see lints like: warning: variables can be used directly in the `format!` string --> rust/macros/kunit.rs:105:37 | 105 | let kunit_wrapper_fn_name = format!("kunit_rust_wrapper_{}", test); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 105 - let kunit_wrapper_fn_name = format!("kunit_rust_wrapper_{}", test); 105 + let kunit_wrapper_fn_name = format!("kunit_rust_wrapper_{test}"); There is even a case that is a pure removal: warning: variables can be used directly in the `format!` string --> rust/macros/module.rs:51:13 | 51 | format!("{field}={content}\0", field = field, content = content) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 51 - format!("{field}={content}\0", field = field, content = content) 51 + format!("{field}={content}\0") The lints all seem like nice cleanups, thus just apply them. We may want to disable `allow-mixed-uninlined-format-args` in the future. Cc: [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs). Link: rust-lang/rust-clippy#14160 [1] Acked-by: Benno Lossin <[email protected]> Reviewed-by: Tamir Duberstein <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 99c8ed6 commit e4dbcbb

File tree

3 files changed

+29
-39
lines changed

3 files changed

+29
-39
lines changed

rust/kernel/str.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl fmt::Display for BStr {
5555
b'\r' => f.write_str("\\r")?,
5656
// Printable characters.
5757
0x20..=0x7e => f.write_char(b as char)?,
58-
_ => write!(f, "\\x{:02x}", b)?,
58+
_ => write!(f, "\\x{b:02x}")?,
5959
}
6060
}
6161
Ok(())
@@ -90,7 +90,7 @@ impl fmt::Debug for BStr {
9090
b'\\' => f.write_str("\\\\")?,
9191
// Printable characters.
9292
0x20..=0x7e => f.write_char(b as char)?,
93-
_ => write!(f, "\\x{:02x}", b)?,
93+
_ => write!(f, "\\x{b:02x}")?,
9494
}
9595
}
9696
f.write_char('"')
@@ -397,7 +397,7 @@ impl fmt::Display for CStr {
397397
// Printable character.
398398
f.write_char(c as char)?;
399399
} else {
400-
write!(f, "\\x{:02x}", c)?;
400+
write!(f, "\\x{c:02x}")?;
401401
}
402402
}
403403
Ok(())
@@ -428,7 +428,7 @@ impl fmt::Debug for CStr {
428428
// Printable characters.
429429
b'\"' => f.write_str("\\\"")?,
430430
0x20..=0x7e => f.write_char(c as char)?,
431-
_ => write!(f, "\\x{:02x}", c)?,
431+
_ => write!(f, "\\x{c:02x}")?,
432432
}
433433
}
434434
f.write_str("\"")
@@ -588,13 +588,13 @@ mod tests {
588588
#[test]
589589
fn test_cstr_display() {
590590
let hello_world = CStr::from_bytes_with_nul(b"hello, world!\0").unwrap();
591-
assert_eq!(format!("{}", hello_world), "hello, world!");
591+
assert_eq!(format!("{hello_world}"), "hello, world!");
592592
let non_printables = CStr::from_bytes_with_nul(b"\x01\x09\x0a\0").unwrap();
593-
assert_eq!(format!("{}", non_printables), "\\x01\\x09\\x0a");
593+
assert_eq!(format!("{non_printables}"), "\\x01\\x09\\x0a");
594594
let non_ascii = CStr::from_bytes_with_nul(b"d\xe9j\xe0 vu\0").unwrap();
595-
assert_eq!(format!("{}", non_ascii), "d\\xe9j\\xe0 vu");
595+
assert_eq!(format!("{non_ascii}"), "d\\xe9j\\xe0 vu");
596596
let good_bytes = CStr::from_bytes_with_nul(b"\xf0\x9f\xa6\x80\0").unwrap();
597-
assert_eq!(format!("{}", good_bytes), "\\xf0\\x9f\\xa6\\x80");
597+
assert_eq!(format!("{good_bytes}"), "\\xf0\\x9f\\xa6\\x80");
598598
}
599599

600600
#[test]
@@ -605,47 +605,47 @@ mod tests {
605605
bytes[i as usize] = i.wrapping_add(1);
606606
}
607607
let cstr = CStr::from_bytes_with_nul(&bytes).unwrap();
608-
assert_eq!(format!("{}", cstr), ALL_ASCII_CHARS);
608+
assert_eq!(format!("{cstr}"), ALL_ASCII_CHARS);
609609
}
610610

611611
#[test]
612612
fn test_cstr_debug() {
613613
let hello_world = CStr::from_bytes_with_nul(b"hello, world!\0").unwrap();
614-
assert_eq!(format!("{:?}", hello_world), "\"hello, world!\"");
614+
assert_eq!(format!("{hello_world:?}"), "\"hello, world!\"");
615615
let non_printables = CStr::from_bytes_with_nul(b"\x01\x09\x0a\0").unwrap();
616-
assert_eq!(format!("{:?}", non_printables), "\"\\x01\\x09\\x0a\"");
616+
assert_eq!(format!("{non_printables:?}"), "\"\\x01\\x09\\x0a\"");
617617
let non_ascii = CStr::from_bytes_with_nul(b"d\xe9j\xe0 vu\0").unwrap();
618-
assert_eq!(format!("{:?}", non_ascii), "\"d\\xe9j\\xe0 vu\"");
618+
assert_eq!(format!("{non_ascii:?}"), "\"d\\xe9j\\xe0 vu\"");
619619
let good_bytes = CStr::from_bytes_with_nul(b"\xf0\x9f\xa6\x80\0").unwrap();
620-
assert_eq!(format!("{:?}", good_bytes), "\"\\xf0\\x9f\\xa6\\x80\"");
620+
assert_eq!(format!("{good_bytes:?}"), "\"\\xf0\\x9f\\xa6\\x80\"");
621621
}
622622

623623
#[test]
624624
fn test_bstr_display() {
625625
let hello_world = BStr::from_bytes(b"hello, world!");
626-
assert_eq!(format!("{}", hello_world), "hello, world!");
626+
assert_eq!(format!("{hello_world}"), "hello, world!");
627627
let escapes = BStr::from_bytes(b"_\t_\n_\r_\\_\'_\"_");
628-
assert_eq!(format!("{}", escapes), "_\\t_\\n_\\r_\\_'_\"_");
628+
assert_eq!(format!("{escapes}"), "_\\t_\\n_\\r_\\_'_\"_");
629629
let others = BStr::from_bytes(b"\x01");
630-
assert_eq!(format!("{}", others), "\\x01");
630+
assert_eq!(format!("{others}"), "\\x01");
631631
let non_ascii = BStr::from_bytes(b"d\xe9j\xe0 vu");
632-
assert_eq!(format!("{}", non_ascii), "d\\xe9j\\xe0 vu");
632+
assert_eq!(format!("{non_ascii}"), "d\\xe9j\\xe0 vu");
633633
let good_bytes = BStr::from_bytes(b"\xf0\x9f\xa6\x80");
634-
assert_eq!(format!("{}", good_bytes), "\\xf0\\x9f\\xa6\\x80");
634+
assert_eq!(format!("{good_bytes}"), "\\xf0\\x9f\\xa6\\x80");
635635
}
636636

637637
#[test]
638638
fn test_bstr_debug() {
639639
let hello_world = BStr::from_bytes(b"hello, world!");
640-
assert_eq!(format!("{:?}", hello_world), "\"hello, world!\"");
640+
assert_eq!(format!("{hello_world:?}"), "\"hello, world!\"");
641641
let escapes = BStr::from_bytes(b"_\t_\n_\r_\\_\'_\"_");
642-
assert_eq!(format!("{:?}", escapes), "\"_\\t_\\n_\\r_\\\\_'_\\\"_\"");
642+
assert_eq!(format!("{escapes:?}"), "\"_\\t_\\n_\\r_\\\\_'_\\\"_\"");
643643
let others = BStr::from_bytes(b"\x01");
644-
assert_eq!(format!("{:?}", others), "\"\\x01\"");
644+
assert_eq!(format!("{others:?}"), "\"\\x01\"");
645645
let non_ascii = BStr::from_bytes(b"d\xe9j\xe0 vu");
646-
assert_eq!(format!("{:?}", non_ascii), "\"d\\xe9j\\xe0 vu\"");
646+
assert_eq!(format!("{non_ascii:?}"), "\"d\\xe9j\\xe0 vu\"");
647647
let good_bytes = BStr::from_bytes(b"\xf0\x9f\xa6\x80");
648-
assert_eq!(format!("{:?}", good_bytes), "\"\\xf0\\x9f\\xa6\\x80\"");
648+
assert_eq!(format!("{good_bytes:?}"), "\"\\xf0\\x9f\\xa6\\x80\"");
649649
}
650650
}
651651

rust/macros/module.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'a> ModInfoBuilder<'a> {
4848
)
4949
} else {
5050
// Loadable modules' modinfo strings go as-is.
51-
format!("{field}={content}\0", field = field, content = content)
51+
format!("{field}={content}\0")
5252
};
5353

5454
write!(
@@ -124,10 +124,7 @@ impl ModuleInfo {
124124
};
125125

126126
if seen_keys.contains(&key) {
127-
panic!(
128-
"Duplicated key \"{}\". Keys can only be specified once.",
129-
key
130-
);
127+
panic!("Duplicated key \"{key}\". Keys can only be specified once.");
131128
}
132129

133130
assert_eq!(expect_punct(it), ':');
@@ -140,10 +137,7 @@ impl ModuleInfo {
140137
"license" => info.license = expect_string_ascii(it),
141138
"alias" => info.alias = Some(expect_string_array(it)),
142139
"firmware" => info.firmware = Some(expect_string_array(it)),
143-
_ => panic!(
144-
"Unknown key \"{}\". Valid keys are: {:?}.",
145-
key, EXPECTED_KEYS
146-
),
140+
_ => panic!("Unknown key \"{key}\". Valid keys are: {EXPECTED_KEYS:?}."),
147141
}
148142

149143
assert_eq!(expect_punct(it), ',');
@@ -155,7 +149,7 @@ impl ModuleInfo {
155149

156150
for key in REQUIRED_KEYS {
157151
if !seen_keys.iter().any(|e| e == key) {
158-
panic!("Missing required key \"{}\".", key);
152+
panic!("Missing required key \"{key}\".");
159153
}
160154
}
161155

@@ -167,10 +161,7 @@ impl ModuleInfo {
167161
}
168162

169163
if seen_keys != ordered_keys {
170-
panic!(
171-
"Keys are not ordered as expected. Order them like: {:?}.",
172-
ordered_keys
173-
);
164+
panic!("Keys are not ordered as expected. Order them like: {ordered_keys:?}.");
174165
}
175166

176167
info

rust/macros/pinned_drop.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ pub(crate) fn pinned_drop(_args: TokenStream, input: TokenStream) -> TokenStream
2525
// Found the end of the generics, this should be `PinnedDrop`.
2626
assert!(
2727
matches!(tt, TokenTree::Ident(i) if i.to_string() == "PinnedDrop"),
28-
"expected 'PinnedDrop', found: '{:?}'",
29-
tt
28+
"expected 'PinnedDrop', found: '{tt:?}'"
3029
);
3130
pinned_drop_idx = Some(i);
3231
break;

0 commit comments

Comments
 (0)