Skip to content

Commit 19fc60c

Browse files
committed
Tag all format-like macros with #[clippy::format_args]
Since 1.85, Clippy [supports](See https://doc.rust-lang.org/nightly/clippy/attribs.html#clippyformat_args) attribute-based discovery of the `format!`-compatible macros, i.e. macros whose trailing arguments can be passed to `format_args!` as is. Tagging core library with the same attribute will allow clippy to stop maintaining a separate list of format-like macros - allowing Clippy to validate macro usage for all lints that work on format arguments. See also rust-lang/rust-clippy#14267
1 parent a18bd8a commit 19fc60c

File tree

5 files changed

+13
-0
lines changed

5 files changed

+13
-0
lines changed

library/alloc/src/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ macro_rules! vec {
121121
#[stable(feature = "rust1", since = "1.0.0")]
122122
#[allow_internal_unstable(hint_must_use, liballoc_internals)]
123123
#[cfg_attr(not(test), rustc_diagnostic_item = "format_macro")]
124+
#[clippy::format_args]
124125
macro_rules! format {
125126
($($arg:tt)*) => {
126127
$crate::__export::must_use({

library/core/src/macros/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ macro_rules! panic {
3939
#[stable(feature = "rust1", since = "1.0.0")]
4040
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_eq_macro")]
4141
#[allow_internal_unstable(panic_internals)]
42+
#[clippy::format_args]
4243
macro_rules! assert_eq {
4344
($left:expr, $right:expr $(,)?) => {
4445
match (&$left, &$right) {
@@ -95,6 +96,7 @@ macro_rules! assert_eq {
9596
#[stable(feature = "assert_ne", since = "1.13.0")]
9697
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_ne_macro")]
9798
#[allow_internal_unstable(panic_internals)]
99+
#[clippy::format_args]
98100
macro_rules! assert_ne {
99101
($left:expr, $right:expr $(,)?) => {
100102
match (&$left, &$right) {
@@ -169,6 +171,7 @@ macro_rules! assert_ne {
169171
#[unstable(feature = "assert_matches", issue = "82775")]
170172
#[allow_internal_unstable(panic_internals)]
171173
#[rustc_macro_transparency = "semitransparent"]
174+
#[clippy::format_args]
172175
pub macro assert_matches {
173176
($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
174177
match $left {
@@ -708,6 +711,7 @@ macro_rules! r#try {
708711
#[macro_export]
709712
#[stable(feature = "rust1", since = "1.0.0")]
710713
#[cfg_attr(not(test), rustc_diagnostic_item = "write_macro")]
714+
#[clippy::format_args]
711715
macro_rules! write {
712716
($dst:expr, $($arg:tt)*) => {
713717
$dst.write_fmt($crate::format_args!($($arg)*))
@@ -895,6 +899,7 @@ macro_rules! unreachable {
895899
#[stable(feature = "rust1", since = "1.0.0")]
896900
#[cfg_attr(not(test), rustc_diagnostic_item = "unimplemented_macro")]
897901
#[allow_internal_unstable(panic_internals)]
902+
#[clippy::format_args]
898903
macro_rules! unimplemented {
899904
() => {
900905
$crate::panicking::panic("not implemented")
@@ -975,6 +980,7 @@ macro_rules! unimplemented {
975980
#[stable(feature = "todo_macro", since = "1.40.0")]
976981
#[cfg_attr(not(test), rustc_diagnostic_item = "todo_macro")]
977982
#[allow_internal_unstable(panic_internals)]
983+
#[clippy::format_args]
978984
macro_rules! todo {
979985
() => {
980986
$crate::panicking::panic("not yet implemented")

library/core/src/panic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub macro panic_2015 {
4949
#[rustc_diagnostic_item = "core_panic_2021_macro"]
5050
#[rustc_macro_transparency = "semitransparent"]
5151
#[cfg(feature = "panic_immediate_abort")]
52+
#[clippy::format_args]
5253
pub macro panic_2021 {
5354
() => (
5455
$crate::panicking::panic("explicit panic")
@@ -77,6 +78,7 @@ pub macro panic_2021 {
7778
#[rustc_diagnostic_item = "core_panic_2021_macro"]
7879
#[rustc_macro_transparency = "semitransparent"]
7980
#[cfg(not(feature = "panic_immediate_abort"))]
81+
#[clippy::format_args]
8082
pub macro panic_2021 {
8183
() => ({
8284
// Create a function so that the argument for `track_caller`
@@ -131,6 +133,7 @@ pub macro unreachable_2015 {
131133
#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
132134
#[allow_internal_unstable(panic_internals)]
133135
#[rustc_macro_transparency = "semitransparent"]
136+
#[clippy::format_args]
134137
pub macro unreachable_2021 {
135138
() => (
136139
$crate::panicking::panic("internal error: entered unreachable code")

library/std/src/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ macro_rules! panic {
7979
#[stable(feature = "rust1", since = "1.0.0")]
8080
#[cfg_attr(not(test), rustc_diagnostic_item = "print_macro")]
8181
#[allow_internal_unstable(print_internals)]
82+
#[clippy::format_args]
8283
macro_rules! print {
8384
($($arg:tt)*) => {{
8485
$crate::io::_print($crate::format_args!($($arg)*));

library/std/src/rt.rs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::{mem, panic, sys};
3030
// - the standard error output
3131
// - some dedicated platform specific output
3232
// - nothing (so this macro is a no-op)
33+
#[clippy::format_args]
3334
macro_rules! rtprintpanic {
3435
($($t:tt)*) => {
3536
#[cfg(not(feature = "panic_immediate_abort"))]
@@ -43,6 +44,7 @@ macro_rules! rtprintpanic {
4344
}
4445
}
4546

47+
#[clippy::format_args]
4648
macro_rules! rtabort {
4749
($($t:tt)*) => {
4850
{

0 commit comments

Comments
 (0)