Skip to content

Commit 184a31b

Browse files
committed
rust: clean Rust 1.88.0's clippy::uninlined_format_args lint
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]>
1 parent aa35cb8 commit 184a31b

File tree

6 files changed

+35
-50
lines changed

6 files changed

+35
-50
lines changed

drivers/gpu/nova-core/gpu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Chipset {
9393
// For now, redirect to fmt::Debug for convenience.
9494
impl fmt::Display for Chipset {
9595
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
96-
write!(f, "{:?}", self)
96+
write!(f, "{self:?}")
9797
}
9898
}
9999

rust/kernel/str.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl fmt::Display for BStr {
7373
b'\r' => f.write_str("\\r")?,
7474
// Printable characters.
7575
0x20..=0x7e => f.write_char(b as char)?,
76-
_ => write!(f, "\\x{:02x}", b)?,
76+
_ => write!(f, "\\x{b:02x}")?,
7777
}
7878
}
7979
Ok(())
@@ -109,7 +109,7 @@ impl fmt::Debug for BStr {
109109
b'\\' => f.write_str("\\\\")?,
110110
// Printable characters.
111111
0x20..=0x7e => f.write_char(b as char)?,
112-
_ => write!(f, "\\x{:02x}", b)?,
112+
_ => write!(f, "\\x{b:02x}")?,
113113
}
114114
}
115115
f.write_char('"')
@@ -447,7 +447,7 @@ impl fmt::Display for CStr {
447447
// Printable character.
448448
f.write_char(c as char)?;
449449
} else {
450-
write!(f, "\\x{:02x}", c)?;
450+
write!(f, "\\x{c:02x}")?;
451451
}
452452
}
453453
Ok(())
@@ -479,7 +479,7 @@ impl fmt::Debug for CStr {
479479
// Printable characters.
480480
b'\"' => f.write_str("\\\"")?,
481481
0x20..=0x7e => f.write_char(c as char)?,
482-
_ => write!(f, "\\x{:02x}", c)?,
482+
_ => write!(f, "\\x{c:02x}")?,
483483
}
484484
}
485485
f.write_str("\"")
@@ -641,13 +641,13 @@ mod tests {
641641
#[test]
642642
fn test_cstr_display() {
643643
let hello_world = CStr::from_bytes_with_nul(b"hello, world!\0").unwrap();
644-
assert_eq!(format!("{}", hello_world), "hello, world!");
644+
assert_eq!(format!("{hello_world}"), "hello, world!");
645645
let non_printables = CStr::from_bytes_with_nul(b"\x01\x09\x0a\0").unwrap();
646-
assert_eq!(format!("{}", non_printables), "\\x01\\x09\\x0a");
646+
assert_eq!(format!("{non_printables}"), "\\x01\\x09\\x0a");
647647
let non_ascii = CStr::from_bytes_with_nul(b"d\xe9j\xe0 vu\0").unwrap();
648-
assert_eq!(format!("{}", non_ascii), "d\\xe9j\\xe0 vu");
648+
assert_eq!(format!("{non_ascii}"), "d\\xe9j\\xe0 vu");
649649
let good_bytes = CStr::from_bytes_with_nul(b"\xf0\x9f\xa6\x80\0").unwrap();
650-
assert_eq!(format!("{}", good_bytes), "\\xf0\\x9f\\xa6\\x80");
650+
assert_eq!(format!("{good_bytes}"), "\\xf0\\x9f\\xa6\\x80");
651651
}
652652

653653
#[test]
@@ -658,47 +658,47 @@ mod tests {
658658
bytes[i as usize] = i.wrapping_add(1);
659659
}
660660
let cstr = CStr::from_bytes_with_nul(&bytes).unwrap();
661-
assert_eq!(format!("{}", cstr), ALL_ASCII_CHARS);
661+
assert_eq!(format!("{cstr}"), ALL_ASCII_CHARS);
662662
}
663663

664664
#[test]
665665
fn test_cstr_debug() {
666666
let hello_world = CStr::from_bytes_with_nul(b"hello, world!\0").unwrap();
667-
assert_eq!(format!("{:?}", hello_world), "\"hello, world!\"");
667+
assert_eq!(format!("{hello_world:?}"), "\"hello, world!\"");
668668
let non_printables = CStr::from_bytes_with_nul(b"\x01\x09\x0a\0").unwrap();
669-
assert_eq!(format!("{:?}", non_printables), "\"\\x01\\x09\\x0a\"");
669+
assert_eq!(format!("{non_printables:?}"), "\"\\x01\\x09\\x0a\"");
670670
let non_ascii = CStr::from_bytes_with_nul(b"d\xe9j\xe0 vu\0").unwrap();
671-
assert_eq!(format!("{:?}", non_ascii), "\"d\\xe9j\\xe0 vu\"");
671+
assert_eq!(format!("{non_ascii:?}"), "\"d\\xe9j\\xe0 vu\"");
672672
let good_bytes = CStr::from_bytes_with_nul(b"\xf0\x9f\xa6\x80\0").unwrap();
673-
assert_eq!(format!("{:?}", good_bytes), "\"\\xf0\\x9f\\xa6\\x80\"");
673+
assert_eq!(format!("{good_bytes:?}"), "\"\\xf0\\x9f\\xa6\\x80\"");
674674
}
675675

676676
#[test]
677677
fn test_bstr_display() {
678678
let hello_world = BStr::from_bytes(b"hello, world!");
679-
assert_eq!(format!("{}", hello_world), "hello, world!");
679+
assert_eq!(format!("{hello_world}"), "hello, world!");
680680
let escapes = BStr::from_bytes(b"_\t_\n_\r_\\_\'_\"_");
681-
assert_eq!(format!("{}", escapes), "_\\t_\\n_\\r_\\_'_\"_");
681+
assert_eq!(format!("{escapes}"), "_\\t_\\n_\\r_\\_'_\"_");
682682
let others = BStr::from_bytes(b"\x01");
683-
assert_eq!(format!("{}", others), "\\x01");
683+
assert_eq!(format!("{others}"), "\\x01");
684684
let non_ascii = BStr::from_bytes(b"d\xe9j\xe0 vu");
685-
assert_eq!(format!("{}", non_ascii), "d\\xe9j\\xe0 vu");
685+
assert_eq!(format!("{non_ascii}"), "d\\xe9j\\xe0 vu");
686686
let good_bytes = BStr::from_bytes(b"\xf0\x9f\xa6\x80");
687-
assert_eq!(format!("{}", good_bytes), "\\xf0\\x9f\\xa6\\x80");
687+
assert_eq!(format!("{good_bytes}"), "\\xf0\\x9f\\xa6\\x80");
688688
}
689689

690690
#[test]
691691
fn test_bstr_debug() {
692692
let hello_world = BStr::from_bytes(b"hello, world!");
693-
assert_eq!(format!("{:?}", hello_world), "\"hello, world!\"");
693+
assert_eq!(format!("{hello_world:?}"), "\"hello, world!\"");
694694
let escapes = BStr::from_bytes(b"_\t_\n_\r_\\_\'_\"_");
695-
assert_eq!(format!("{:?}", escapes), "\"_\\t_\\n_\\r_\\\\_'_\\\"_\"");
695+
assert_eq!(format!("{escapes:?}"), "\"_\\t_\\n_\\r_\\\\_'_\\\"_\"");
696696
let others = BStr::from_bytes(b"\x01");
697-
assert_eq!(format!("{:?}", others), "\"\\x01\"");
697+
assert_eq!(format!("{others:?}"), "\"\\x01\"");
698698
let non_ascii = BStr::from_bytes(b"d\xe9j\xe0 vu");
699-
assert_eq!(format!("{:?}", non_ascii), "\"d\\xe9j\\xe0 vu\"");
699+
assert_eq!(format!("{non_ascii:?}"), "\"d\\xe9j\\xe0 vu\"");
700700
let good_bytes = BStr::from_bytes(b"\xf0\x9f\xa6\x80");
701-
assert_eq!(format!("{:?}", good_bytes), "\"\\xf0\\x9f\\xa6\\x80\"");
701+
assert_eq!(format!("{good_bytes:?}"), "\"\\xf0\\x9f\\xa6\\x80\"");
702702
}
703703
}
704704

rust/macros/kunit.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ pub(crate) fn kunit_tests(attr: TokenStream, ts: TokenStream) -> TokenStream {
1515
}
1616

1717
if attr.len() > 255 {
18-
panic!(
19-
"The test suite name `{}` exceeds the maximum length of 255 bytes",
20-
attr
21-
)
18+
panic!("The test suite name `{attr}` exceeds the maximum length of 255 bytes")
2219
}
2320

2421
let mut tokens: Vec<_> = ts.into_iter().collect();
@@ -102,16 +99,14 @@ pub(crate) fn kunit_tests(attr: TokenStream, ts: TokenStream) -> TokenStream {
10299
let mut kunit_macros = "".to_owned();
103100
let mut test_cases = "".to_owned();
104101
for test in &tests {
105-
let kunit_wrapper_fn_name = format!("kunit_rust_wrapper_{}", test);
102+
let kunit_wrapper_fn_name = format!("kunit_rust_wrapper_{test}");
106103
let kunit_wrapper = format!(
107-
"unsafe extern \"C\" fn {}(_test: *mut kernel::bindings::kunit) {{ {}(); }}",
108-
kunit_wrapper_fn_name, test
104+
"unsafe extern \"C\" fn {kunit_wrapper_fn_name}(_test: *mut kernel::bindings::kunit) {{ {test}(); }}"
109105
);
110106
writeln!(kunit_macros, "{kunit_wrapper}").unwrap();
111107
writeln!(
112108
test_cases,
113-
" kernel::kunit::kunit_case(kernel::c_str!(\"{}\"), {}),",
114-
test, kunit_wrapper_fn_name
109+
" kernel::kunit::kunit_case(kernel::c_str!(\"{test}\"), {kunit_wrapper_fn_name}),"
115110
)
116111
.unwrap();
117112
}

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!(
@@ -126,10 +126,7 @@ impl ModuleInfo {
126126
};
127127

128128
if seen_keys.contains(&key) {
129-
panic!(
130-
"Duplicated key \"{}\". Keys can only be specified once.",
131-
key
132-
);
129+
panic!("Duplicated key \"{key}\". Keys can only be specified once.");
133130
}
134131

135132
assert_eq!(expect_punct(it), ':');
@@ -143,10 +140,7 @@ impl ModuleInfo {
143140
"license" => info.license = expect_string_ascii(it),
144141
"alias" => info.alias = Some(expect_string_array(it)),
145142
"firmware" => info.firmware = Some(expect_string_array(it)),
146-
_ => panic!(
147-
"Unknown key \"{}\". Valid keys are: {:?}.",
148-
key, EXPECTED_KEYS
149-
),
143+
_ => panic!("Unknown key \"{key}\". Valid keys are: {EXPECTED_KEYS:?}."),
150144
}
151145

152146
assert_eq!(expect_punct(it), ',');
@@ -158,7 +152,7 @@ impl ModuleInfo {
158152

159153
for key in REQUIRED_KEYS {
160154
if !seen_keys.iter().any(|e| e == key) {
161-
panic!("Missing required key \"{}\".", key);
155+
panic!("Missing required key \"{key}\".");
162156
}
163157
}
164158

@@ -170,10 +164,7 @@ impl ModuleInfo {
170164
}
171165

172166
if seen_keys != ordered_keys {
173-
panic!(
174-
"Keys are not ordered as expected. Order them like: {:?}.",
175-
ordered_keys
176-
);
167+
panic!("Keys are not ordered as expected. Order them like: {ordered_keys:?}.");
177168
}
178169

179170
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/pin-init/internal/src/pinned_drop.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ pub(crate) fn pinned_drop(_args: TokenStream, input: TokenStream) -> TokenStream
2828
// Found the end of the generics, this should be `PinnedDrop`.
2929
assert!(
3030
matches!(tt, TokenTree::Ident(i) if i.to_string() == "PinnedDrop"),
31-
"expected 'PinnedDrop', found: '{:?}'",
32-
tt
31+
"expected 'PinnedDrop', found: '{tt:?}'"
3332
);
3433
pinned_drop_idx = Some(i);
3534
break;

0 commit comments

Comments
 (0)