Skip to content

Commit cf4549c

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 391b66c + 7ea03db commit cf4549c

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

compiler/rustc_span/src/symbol.rs

+31
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,10 @@ symbols! {
336336
asm_sym,
337337
asm_unwind,
338338
assert,
339+
assert_eq_macro,
339340
assert_inhabited,
340341
assert_macro,
342+
assert_ne_macro,
341343
assert_receiver_is_total_eq,
342344
assert_uninit_valid,
343345
assert_zero_valid,
@@ -407,6 +409,7 @@ symbols! {
407409
cfg_doctest,
408410
cfg_eval,
409411
cfg_hide,
412+
cfg_macro,
410413
cfg_panic,
411414
cfg_sanitize,
412415
cfg_target_abi,
@@ -434,15 +437,18 @@ symbols! {
434437
coerce_unsized,
435438
cold,
436439
column,
440+
column_macro,
437441
compare_and_swap,
438442
compare_exchange,
439443
compare_exchange_weak,
440444
compile_error,
445+
compile_error_macro,
441446
compiler_builtins,
442447
compiler_fence,
443448
concat,
444449
concat_bytes,
445450
concat_idents,
451+
concat_macro,
446452
conservative_impl_trait,
447453
console,
448454
const_allocate,
@@ -522,10 +528,13 @@ symbols! {
522528
custom_inner_attributes,
523529
custom_test_frameworks,
524530
d,
531+
dbg_macro,
525532
dead_code,
526533
dealloc,
527534
debug,
535+
debug_assert_eq_macro,
528536
debug_assert_macro,
537+
debug_assert_ne_macro,
529538
debug_assertions,
530539
debug_struct,
531540
debug_trait_builder,
@@ -597,6 +606,9 @@ symbols! {
597606
encode,
598607
end,
599608
env,
609+
env_macro,
610+
eprint_macro,
611+
eprintln_macro,
600612
eq,
601613
ermsb_target_feature,
602614
exact_div,
@@ -644,6 +656,7 @@ symbols! {
644656
field,
645657
field_init_shorthand,
646658
file,
659+
file_macro,
647660
fill,
648661
finish,
649662
flags,
@@ -666,6 +679,7 @@ symbols! {
666679
format,
667680
format_args,
668681
format_args_capture,
682+
format_args_macro,
669683
format_args_nl,
670684
format_macro,
671685
freeze,
@@ -732,7 +746,10 @@ symbols! {
732746
in_band_lifetimes,
733747
include,
734748
include_bytes,
749+
include_bytes_macro,
750+
include_macro,
735751
include_str,
752+
include_str_macro,
736753
inclusive_range_syntax,
737754
index,
738755
index_mut,
@@ -780,6 +797,7 @@ symbols! {
780797
lifetime,
781798
likely,
782799
line,
800+
line_macro,
783801
link,
784802
link_args,
785803
link_cfg,
@@ -823,6 +841,7 @@ symbols! {
823841
masked,
824842
match_beginning_vert,
825843
match_default_bindings,
844+
matches_macro,
826845
maxnumf32,
827846
maxnumf64,
828847
may_dangle,
@@ -859,6 +878,7 @@ symbols! {
859878
modifiers,
860879
module,
861880
module_path,
881+
module_path_macro,
862882
more_qualified_paths,
863883
more_struct_aliases,
864884
movbe_target_feature,
@@ -942,6 +962,7 @@ symbols! {
942962
optin_builtin_traits,
943963
option,
944964
option_env,
965+
option_env_macro,
945966
options,
946967
or,
947968
or_patterns,
@@ -1005,6 +1026,8 @@ symbols! {
10051026
prelude_import,
10061027
preserves_flags,
10071028
primitive,
1029+
print_macro,
1030+
println_macro,
10081031
proc_dash_macro: "proc-macro",
10091032
proc_macro,
10101033
proc_macro_attribute,
@@ -1292,6 +1315,7 @@ symbols! {
12921315
str,
12931316
str_alloc,
12941317
stringify,
1318+
stringify_macro,
12951319
struct_field_attributes,
12961320
struct_inherit,
12971321
struct_variant,
@@ -1335,6 +1359,8 @@ symbols! {
13351359
then_with,
13361360
thread,
13371361
thread_local,
1362+
thread_local_macro,
1363+
todo_macro,
13381364
tool_attributes,
13391365
tool_lints,
13401366
trace_macros,
@@ -1385,6 +1411,7 @@ symbols! {
13851411
underscore_imports,
13861412
underscore_lifetimes,
13871413
uniform_paths,
1414+
unimplemented_macro,
13881415
unit,
13891416
universal_impl_trait,
13901417
unix,
@@ -1393,6 +1420,7 @@ symbols! {
13931420
unpin,
13941421
unreachable,
13951422
unreachable_code,
1423+
unreachable_macro,
13961424
unrestricted_attribute_tokens,
13971425
unsafe_block_in_unsafe_fn,
13981426
unsafe_cell,
@@ -1423,6 +1451,7 @@ symbols! {
14231451
var,
14241452
variant_count,
14251453
vec,
1454+
vec_macro,
14261455
version,
14271456
vis,
14281457
visible_private_types,
@@ -1447,7 +1476,9 @@ symbols! {
14471476
wrapping_sub,
14481477
wreg,
14491478
write_bytes,
1479+
write_macro,
14501480
write_str,
1481+
writeln_macro,
14511482
x87_reg,
14521483
xer,
14531484
xmm_reg,

library/alloc/src/macros.rs

+1
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
() => (

library/core/src/macros/mod.rs

+24
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
}

0 commit comments

Comments
 (0)