Skip to content

Commit d44fe2d

Browse files
ojedagregkh
authored andcommitted
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 2fcf498 commit d44fe2d

File tree

4 files changed

+30
-40
lines changed

4 files changed

+30
-40
lines changed

rust/kernel/str.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl fmt::Display for BStr {
5656
b'\r' => f.write_str("\\r")?,
5757
// Printable characters.
5858
0x20..=0x7e => f.write_char(b as char)?,
59-
_ => write!(f, "\\x{:02x}", b)?,
59+
_ => write!(f, "\\x{b:02x}")?,
6060
}
6161
}
6262
Ok(())
@@ -92,7 +92,7 @@ impl fmt::Debug for BStr {
9292
b'\\' => f.write_str("\\\\")?,
9393
// Printable characters.
9494
0x20..=0x7e => f.write_char(b as char)?,
95-
_ => write!(f, "\\x{:02x}", b)?,
95+
_ => write!(f, "\\x{b:02x}")?,
9696
}
9797
}
9898
f.write_char('"')
@@ -401,7 +401,7 @@ impl fmt::Display for CStr {
401401
// Printable character.
402402
f.write_char(c as char)?;
403403
} else {
404-
write!(f, "\\x{:02x}", c)?;
404+
write!(f, "\\x{c:02x}")?;
405405
}
406406
}
407407
Ok(())
@@ -433,7 +433,7 @@ impl fmt::Debug for CStr {
433433
// Printable characters.
434434
b'\"' => f.write_str("\\\"")?,
435435
0x20..=0x7e => f.write_char(c as char)?,
436-
_ => write!(f, "\\x{:02x}", c)?,
436+
_ => write!(f, "\\x{c:02x}")?,
437437
}
438438
}
439439
f.write_str("\"")
@@ -595,13 +595,13 @@ mod tests {
595595
#[test]
596596
fn test_cstr_display() {
597597
let hello_world = CStr::from_bytes_with_nul(b"hello, world!\0").unwrap();
598-
assert_eq!(format!("{}", hello_world), "hello, world!");
598+
assert_eq!(format!("{hello_world}"), "hello, world!");
599599
let non_printables = CStr::from_bytes_with_nul(b"\x01\x09\x0a\0").unwrap();
600-
assert_eq!(format!("{}", non_printables), "\\x01\\x09\\x0a");
600+
assert_eq!(format!("{non_printables}"), "\\x01\\x09\\x0a");
601601
let non_ascii = CStr::from_bytes_with_nul(b"d\xe9j\xe0 vu\0").unwrap();
602-
assert_eq!(format!("{}", non_ascii), "d\\xe9j\\xe0 vu");
602+
assert_eq!(format!("{non_ascii}"), "d\\xe9j\\xe0 vu");
603603
let good_bytes = CStr::from_bytes_with_nul(b"\xf0\x9f\xa6\x80\0").unwrap();
604-
assert_eq!(format!("{}", good_bytes), "\\xf0\\x9f\\xa6\\x80");
604+
assert_eq!(format!("{good_bytes}"), "\\xf0\\x9f\\xa6\\x80");
605605
}
606606

607607
#[test]
@@ -612,47 +612,47 @@ mod tests {
612612
bytes[i as usize] = i.wrapping_add(1);
613613
}
614614
let cstr = CStr::from_bytes_with_nul(&bytes).unwrap();
615-
assert_eq!(format!("{}", cstr), ALL_ASCII_CHARS);
615+
assert_eq!(format!("{cstr}"), ALL_ASCII_CHARS);
616616
}
617617

618618
#[test]
619619
fn test_cstr_debug() {
620620
let hello_world = CStr::from_bytes_with_nul(b"hello, world!\0").unwrap();
621-
assert_eq!(format!("{:?}", hello_world), "\"hello, world!\"");
621+
assert_eq!(format!("{hello_world:?}"), "\"hello, world!\"");
622622
let non_printables = CStr::from_bytes_with_nul(b"\x01\x09\x0a\0").unwrap();
623-
assert_eq!(format!("{:?}", non_printables), "\"\\x01\\x09\\x0a\"");
623+
assert_eq!(format!("{non_printables:?}"), "\"\\x01\\x09\\x0a\"");
624624
let non_ascii = CStr::from_bytes_with_nul(b"d\xe9j\xe0 vu\0").unwrap();
625-
assert_eq!(format!("{:?}", non_ascii), "\"d\\xe9j\\xe0 vu\"");
625+
assert_eq!(format!("{non_ascii:?}"), "\"d\\xe9j\\xe0 vu\"");
626626
let good_bytes = CStr::from_bytes_with_nul(b"\xf0\x9f\xa6\x80\0").unwrap();
627-
assert_eq!(format!("{:?}", good_bytes), "\"\\xf0\\x9f\\xa6\\x80\"");
627+
assert_eq!(format!("{good_bytes:?}"), "\"\\xf0\\x9f\\xa6\\x80\"");
628628
}
629629

630630
#[test]
631631
fn test_bstr_display() {
632632
let hello_world = BStr::from_bytes(b"hello, world!");
633-
assert_eq!(format!("{}", hello_world), "hello, world!");
633+
assert_eq!(format!("{hello_world}"), "hello, world!");
634634
let escapes = BStr::from_bytes(b"_\t_\n_\r_\\_\'_\"_");
635-
assert_eq!(format!("{}", escapes), "_\\t_\\n_\\r_\\_'_\"_");
635+
assert_eq!(format!("{escapes}"), "_\\t_\\n_\\r_\\_'_\"_");
636636
let others = BStr::from_bytes(b"\x01");
637-
assert_eq!(format!("{}", others), "\\x01");
637+
assert_eq!(format!("{others}"), "\\x01");
638638
let non_ascii = BStr::from_bytes(b"d\xe9j\xe0 vu");
639-
assert_eq!(format!("{}", non_ascii), "d\\xe9j\\xe0 vu");
639+
assert_eq!(format!("{non_ascii}"), "d\\xe9j\\xe0 vu");
640640
let good_bytes = BStr::from_bytes(b"\xf0\x9f\xa6\x80");
641-
assert_eq!(format!("{}", good_bytes), "\\xf0\\x9f\\xa6\\x80");
641+
assert_eq!(format!("{good_bytes}"), "\\xf0\\x9f\\xa6\\x80");
642642
}
643643

644644
#[test]
645645
fn test_bstr_debug() {
646646
let hello_world = BStr::from_bytes(b"hello, world!");
647-
assert_eq!(format!("{:?}", hello_world), "\"hello, world!\"");
647+
assert_eq!(format!("{hello_world:?}"), "\"hello, world!\"");
648648
let escapes = BStr::from_bytes(b"_\t_\n_\r_\\_\'_\"_");
649-
assert_eq!(format!("{:?}", escapes), "\"_\\t_\\n_\\r_\\\\_'_\\\"_\"");
649+
assert_eq!(format!("{escapes:?}"), "\"_\\t_\\n_\\r_\\\\_'_\\\"_\"");
650650
let others = BStr::from_bytes(b"\x01");
651-
assert_eq!(format!("{:?}", others), "\"\\x01\"");
651+
assert_eq!(format!("{others:?}"), "\"\\x01\"");
652652
let non_ascii = BStr::from_bytes(b"d\xe9j\xe0 vu");
653-
assert_eq!(format!("{:?}", non_ascii), "\"d\\xe9j\\xe0 vu\"");
653+
assert_eq!(format!("{non_ascii:?}"), "\"d\\xe9j\\xe0 vu\"");
654654
let good_bytes = BStr::from_bytes(b"\xf0\x9f\xa6\x80");
655-
assert_eq!(format!("{:?}", good_bytes), "\"\\xf0\\x9f\\xa6\\x80\"");
655+
assert_eq!(format!("{good_bytes:?}"), "\"\\xf0\\x9f\\xa6\\x80\"");
656656
}
657657
}
658658

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/paste.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn concat_helper(tokens: &[TokenTree]) -> Vec<(String, Span)> {
5050
let tokens = group.stream().into_iter().collect::<Vec<TokenTree>>();
5151
segments.append(&mut concat_helper(tokens.as_slice()));
5252
}
53-
token => panic!("unexpected token in paste segments: {:?}", token),
53+
token => panic!("unexpected token in paste segments: {token:?}"),
5454
};
5555
}
5656

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)