Skip to content

Commit da175e7

Browse files
authored
Rollup merge of #92619 - Alexendoo:macro-diagnostic-items, r=matthewjasper
Add diagnostic items for macros For use in Clippy, it adds diagnostic items to all the stable public macros Clippy has lints that look for almost all of these (currently by name or path), but there are a few that aren't currently part of any lint, I could remove those if it's preferred to add them as needed rather than ahead of time
2 parents 09761c8 + 66e2404 commit da175e7

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

alloc/src/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#[cfg(not(test))]
3838
#[macro_export]
3939
#[stable(feature = "rust1", since = "1.0.0")]
40+
#[rustc_diagnostic_item = "vec_macro"]
4041
#[allow_internal_unstable(box_syntax, liballoc_internals)]
4142
macro_rules! vec {
4243
() => (

core/src/macros/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ macro_rules! panic {
3131
/// ```
3232
#[macro_export]
3333
#[stable(feature = "rust1", since = "1.0.0")]
34+
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_eq_macro")]
3435
#[allow_internal_unstable(core_panic)]
3536
macro_rules! assert_eq {
3637
($left:expr, $right:expr $(,)?) => ({
@@ -80,6 +81,7 @@ macro_rules! assert_eq {
8081
/// ```
8182
#[macro_export]
8283
#[stable(feature = "assert_ne", since = "1.13.0")]
84+
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_ne_macro")]
8385
#[allow_internal_unstable(core_panic)]
8486
macro_rules! assert_ne {
8587
($left:expr, $right:expr $(,)?) => ({
@@ -236,6 +238,7 @@ macro_rules! debug_assert {
236238
/// ```
237239
#[macro_export]
238240
#[stable(feature = "rust1", since = "1.0.0")]
241+
#[cfg_attr(not(test), rustc_diagnostic_item = "debug_assert_eq_macro")]
239242
macro_rules! debug_assert_eq {
240243
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_eq!($($arg)*); })
241244
}
@@ -261,6 +264,7 @@ macro_rules! debug_assert_eq {
261264
/// ```
262265
#[macro_export]
263266
#[stable(feature = "assert_ne", since = "1.13.0")]
267+
#[cfg_attr(not(test), rustc_diagnostic_item = "debug_assert_ne_macro")]
264268
macro_rules! debug_assert_ne {
265269
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); })
266270
}
@@ -320,6 +324,7 @@ pub macro debug_assert_matches($($arg:tt)*) {
320324
/// ```
321325
#[macro_export]
322326
#[stable(feature = "matches_macro", since = "1.42.0")]
327+
#[cfg_attr(not(test), rustc_diagnostic_item = "matches_macro")]
323328
macro_rules! matches {
324329
($expression:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
325330
match $expression {
@@ -475,6 +480,7 @@ macro_rules! r#try {
475480
/// ```
476481
#[macro_export]
477482
#[stable(feature = "rust1", since = "1.0.0")]
483+
#[cfg_attr(not(test), rustc_diagnostic_item = "write_macro")]
478484
macro_rules! write {
479485
($dst:expr, $($arg:tt)*) => ($dst.write_fmt($crate::format_args!($($arg)*)))
480486
}
@@ -525,6 +531,7 @@ macro_rules! write {
525531
/// ```
526532
#[macro_export]
527533
#[stable(feature = "rust1", since = "1.0.0")]
534+
#[cfg_attr(not(test), rustc_diagnostic_item = "writeln_macro")]
528535
#[allow_internal_unstable(format_args_nl)]
529536
macro_rules! writeln {
530537
($dst:expr $(,)?) => (
@@ -589,6 +596,7 @@ macro_rules! writeln {
589596
/// ```
590597
#[macro_export]
591598
#[stable(feature = "rust1", since = "1.0.0")]
599+
#[cfg_attr(not(test), rustc_diagnostic_item = "unreachable_macro")]
592600
#[allow_internal_unstable(core_panic)]
593601
macro_rules! unreachable {
594602
() => ({
@@ -675,6 +683,7 @@ macro_rules! unreachable {
675683
/// ```
676684
#[macro_export]
677685
#[stable(feature = "rust1", since = "1.0.0")]
686+
#[cfg_attr(not(test), rustc_diagnostic_item = "unimplemented_macro")]
678687
#[allow_internal_unstable(core_panic)]
679688
macro_rules! unimplemented {
680689
() => ($crate::panicking::panic("not implemented"));
@@ -737,6 +746,7 @@ macro_rules! unimplemented {
737746
/// ```
738747
#[macro_export]
739748
#[stable(feature = "todo_macro", since = "1.40.0")]
749+
#[cfg_attr(not(test), rustc_diagnostic_item = "todo_macro")]
740750
#[allow_internal_unstable(core_panic)]
741751
macro_rules! todo {
742752
() => ($crate::panicking::panic("not yet implemented"));
@@ -786,6 +796,7 @@ pub(crate) mod builtin {
786796
#[stable(feature = "compile_error_macro", since = "1.20.0")]
787797
#[rustc_builtin_macro]
788798
#[macro_export]
799+
#[cfg_attr(not(test), rustc_diagnostic_item = "compile_error_macro")]
789800
macro_rules! compile_error {
790801
($msg:expr $(,)?) => {{ /* compiler built-in */ }};
791802
}
@@ -835,6 +846,7 @@ pub(crate) mod builtin {
835846
/// assert_eq!(s, format!("hello {}", "world"));
836847
/// ```
837848
#[stable(feature = "rust1", since = "1.0.0")]
849+
#[cfg_attr(not(test), rustc_diagnostic_item = "format_args_macro")]
838850
#[allow_internal_unsafe]
839851
#[allow_internal_unstable(fmt_internals)]
840852
#[rustc_builtin_macro]
@@ -905,6 +917,7 @@ pub(crate) mod builtin {
905917
#[stable(feature = "rust1", since = "1.0.0")]
906918
#[rustc_builtin_macro]
907919
#[macro_export]
920+
#[cfg_attr(not(test), rustc_diagnostic_item = "env_macro")]
908921
macro_rules! env {
909922
($name:expr $(,)?) => {{ /* compiler built-in */ }};
910923
($name:expr, $error_msg:expr $(,)?) => {{ /* compiler built-in */ }};
@@ -930,6 +943,7 @@ pub(crate) mod builtin {
930943
#[stable(feature = "rust1", since = "1.0.0")]
931944
#[rustc_builtin_macro]
932945
#[macro_export]
946+
#[cfg_attr(not(test), rustc_diagnostic_item = "option_env_macro")]
933947
macro_rules! option_env {
934948
($name:expr $(,)?) => {{ /* compiler built-in */ }};
935949
}
@@ -1015,6 +1029,7 @@ pub(crate) mod builtin {
10151029
#[stable(feature = "rust1", since = "1.0.0")]
10161030
#[rustc_builtin_macro]
10171031
#[macro_export]
1032+
#[cfg_attr(not(test), rustc_diagnostic_item = "concat_macro")]
10181033
macro_rules! concat {
10191034
($($e:expr),* $(,)?) => {{ /* compiler built-in */ }};
10201035
}
@@ -1040,6 +1055,7 @@ pub(crate) mod builtin {
10401055
#[stable(feature = "rust1", since = "1.0.0")]
10411056
#[rustc_builtin_macro]
10421057
#[macro_export]
1058+
#[cfg_attr(not(test), rustc_diagnostic_item = "line_macro")]
10431059
macro_rules! line {
10441060
() => {
10451061
/* compiler built-in */
@@ -1079,6 +1095,7 @@ pub(crate) mod builtin {
10791095
#[stable(feature = "rust1", since = "1.0.0")]
10801096
#[rustc_builtin_macro]
10811097
#[macro_export]
1098+
#[cfg_attr(not(test), rustc_diagnostic_item = "column_macro")]
10821099
macro_rules! column {
10831100
() => {
10841101
/* compiler built-in */
@@ -1104,6 +1121,7 @@ pub(crate) mod builtin {
11041121
#[stable(feature = "rust1", since = "1.0.0")]
11051122
#[rustc_builtin_macro]
11061123
#[macro_export]
1124+
#[cfg_attr(not(test), rustc_diagnostic_item = "file_macro")]
11071125
macro_rules! file {
11081126
() => {
11091127
/* compiler built-in */
@@ -1128,6 +1146,7 @@ pub(crate) mod builtin {
11281146
#[stable(feature = "rust1", since = "1.0.0")]
11291147
#[rustc_builtin_macro]
11301148
#[macro_export]
1149+
#[cfg_attr(not(test), rustc_diagnostic_item = "stringify_macro")]
11311150
macro_rules! stringify {
11321151
($($t:tt)*) => {
11331152
/* compiler built-in */
@@ -1169,6 +1188,7 @@ pub(crate) mod builtin {
11691188
#[stable(feature = "rust1", since = "1.0.0")]
11701189
#[rustc_builtin_macro]
11711190
#[macro_export]
1191+
#[cfg_attr(not(test), rustc_diagnostic_item = "include_str_macro")]
11721192
macro_rules! include_str {
11731193
($file:expr $(,)?) => {{ /* compiler built-in */ }};
11741194
}
@@ -1208,6 +1228,7 @@ pub(crate) mod builtin {
12081228
#[stable(feature = "rust1", since = "1.0.0")]
12091229
#[rustc_builtin_macro]
12101230
#[macro_export]
1231+
#[cfg_attr(not(test), rustc_diagnostic_item = "include_bytes_macro")]
12111232
macro_rules! include_bytes {
12121233
($file:expr $(,)?) => {{ /* compiler built-in */ }};
12131234
}
@@ -1232,6 +1253,7 @@ pub(crate) mod builtin {
12321253
#[stable(feature = "rust1", since = "1.0.0")]
12331254
#[rustc_builtin_macro]
12341255
#[macro_export]
1256+
#[cfg_attr(not(test), rustc_diagnostic_item = "module_path_macro")]
12351257
macro_rules! module_path {
12361258
() => {
12371259
/* compiler built-in */
@@ -1265,6 +1287,7 @@ pub(crate) mod builtin {
12651287
#[stable(feature = "rust1", since = "1.0.0")]
12661288
#[rustc_builtin_macro]
12671289
#[macro_export]
1290+
#[cfg_attr(not(test), rustc_diagnostic_item = "cfg_macro")]
12681291
macro_rules! cfg {
12691292
($($cfg:tt)*) => {
12701293
/* compiler built-in */
@@ -1315,6 +1338,7 @@ pub(crate) mod builtin {
13151338
#[stable(feature = "rust1", since = "1.0.0")]
13161339
#[rustc_builtin_macro]
13171340
#[macro_export]
1341+
#[cfg_attr(not(test), rustc_diagnostic_item = "include_macro")]
13181342
macro_rules! include {
13191343
($file:expr $(,)?) => {{ /* compiler built-in */ }};
13201344
}

std/src/macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ macro_rules! panic {
5757
/// ```
5858
#[macro_export]
5959
#[stable(feature = "rust1", since = "1.0.0")]
60+
#[cfg_attr(not(test), rustc_diagnostic_item = "print_macro")]
6061
#[allow_internal_unstable(print_internals)]
6162
macro_rules! print {
6263
($($arg:tt)*) => ($crate::io::_print($crate::format_args!($($arg)*)));
@@ -90,6 +91,7 @@ macro_rules! print {
9091
/// ```
9192
#[macro_export]
9293
#[stable(feature = "rust1", since = "1.0.0")]
94+
#[cfg_attr(not(test), rustc_diagnostic_item = "println_macro")]
9395
#[allow_internal_unstable(print_internals, format_args_nl)]
9496
macro_rules! println {
9597
() => ($crate::print!("\n"));
@@ -121,6 +123,7 @@ macro_rules! println {
121123
/// ```
122124
#[macro_export]
123125
#[stable(feature = "eprint", since = "1.19.0")]
126+
#[cfg_attr(not(test), rustc_diagnostic_item = "eprint_macro")]
124127
#[allow_internal_unstable(print_internals)]
125128
macro_rules! eprint {
126129
($($arg:tt)*) => ($crate::io::_eprint($crate::format_args!($($arg)*)));
@@ -149,6 +152,7 @@ macro_rules! eprint {
149152
/// ```
150153
#[macro_export]
151154
#[stable(feature = "eprint", since = "1.19.0")]
155+
#[cfg_attr(not(test), rustc_diagnostic_item = "eprintln_macro")]
152156
#[allow_internal_unstable(print_internals, format_args_nl)]
153157
macro_rules! eprintln {
154158
() => ($crate::eprint!("\n"));
@@ -282,6 +286,7 @@ macro_rules! eprintln {
282286
/// [`debug!`]: https://docs.rs/log/*/log/macro.debug.html
283287
/// [`log`]: https://crates.io/crates/log
284288
#[macro_export]
289+
#[cfg_attr(not(test), rustc_diagnostic_item = "dbg_macro")]
285290
#[stable(feature = "dbg_macro", since = "1.32.0")]
286291
macro_rules! dbg {
287292
// NOTE: We cannot use `concat!` to make a static string as a format argument

std/src/thread/local.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
142142
/// [`std::thread::LocalKey`]: crate::thread::LocalKey
143143
#[macro_export]
144144
#[stable(feature = "rust1", since = "1.0.0")]
145+
#[cfg_attr(not(test), rustc_diagnostic_item = "thread_local_macro")]
145146
#[allow_internal_unstable(thread_local_internals)]
146147
macro_rules! thread_local {
147148
// empty (base case for the recursion)

0 commit comments

Comments
 (0)