Skip to content

Commit

Permalink
Rollup merge of #92619 - Alexendoo:macro-diagnostic-items, r=matthewj…
Browse files Browse the repository at this point in the history
…asper

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
  • Loading branch information
matthiaskrgr authored Jan 16, 2022
2 parents 391b66c + 7ea03db commit cf4549c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ symbols! {
asm_sym,
asm_unwind,
assert,
assert_eq_macro,
assert_inhabited,
assert_macro,
assert_ne_macro,
assert_receiver_is_total_eq,
assert_uninit_valid,
assert_zero_valid,
Expand Down Expand Up @@ -407,6 +409,7 @@ symbols! {
cfg_doctest,
cfg_eval,
cfg_hide,
cfg_macro,
cfg_panic,
cfg_sanitize,
cfg_target_abi,
Expand Down Expand Up @@ -434,15 +437,18 @@ symbols! {
coerce_unsized,
cold,
column,
column_macro,
compare_and_swap,
compare_exchange,
compare_exchange_weak,
compile_error,
compile_error_macro,
compiler_builtins,
compiler_fence,
concat,
concat_bytes,
concat_idents,
concat_macro,
conservative_impl_trait,
console,
const_allocate,
Expand Down Expand Up @@ -522,10 +528,13 @@ symbols! {
custom_inner_attributes,
custom_test_frameworks,
d,
dbg_macro,
dead_code,
dealloc,
debug,
debug_assert_eq_macro,
debug_assert_macro,
debug_assert_ne_macro,
debug_assertions,
debug_struct,
debug_trait_builder,
Expand Down Expand Up @@ -597,6 +606,9 @@ symbols! {
encode,
end,
env,
env_macro,
eprint_macro,
eprintln_macro,
eq,
ermsb_target_feature,
exact_div,
Expand Down Expand Up @@ -644,6 +656,7 @@ symbols! {
field,
field_init_shorthand,
file,
file_macro,
fill,
finish,
flags,
Expand All @@ -666,6 +679,7 @@ symbols! {
format,
format_args,
format_args_capture,
format_args_macro,
format_args_nl,
format_macro,
freeze,
Expand Down Expand Up @@ -732,7 +746,10 @@ symbols! {
in_band_lifetimes,
include,
include_bytes,
include_bytes_macro,
include_macro,
include_str,
include_str_macro,
inclusive_range_syntax,
index,
index_mut,
Expand Down Expand Up @@ -780,6 +797,7 @@ symbols! {
lifetime,
likely,
line,
line_macro,
link,
link_args,
link_cfg,
Expand Down Expand Up @@ -823,6 +841,7 @@ symbols! {
masked,
match_beginning_vert,
match_default_bindings,
matches_macro,
maxnumf32,
maxnumf64,
may_dangle,
Expand Down Expand Up @@ -859,6 +878,7 @@ symbols! {
modifiers,
module,
module_path,
module_path_macro,
more_qualified_paths,
more_struct_aliases,
movbe_target_feature,
Expand Down Expand Up @@ -942,6 +962,7 @@ symbols! {
optin_builtin_traits,
option,
option_env,
option_env_macro,
options,
or,
or_patterns,
Expand Down Expand Up @@ -1005,6 +1026,8 @@ symbols! {
prelude_import,
preserves_flags,
primitive,
print_macro,
println_macro,
proc_dash_macro: "proc-macro",
proc_macro,
proc_macro_attribute,
Expand Down Expand Up @@ -1292,6 +1315,7 @@ symbols! {
str,
str_alloc,
stringify,
stringify_macro,
struct_field_attributes,
struct_inherit,
struct_variant,
Expand Down Expand Up @@ -1335,6 +1359,8 @@ symbols! {
then_with,
thread,
thread_local,
thread_local_macro,
todo_macro,
tool_attributes,
tool_lints,
trace_macros,
Expand Down Expand Up @@ -1385,6 +1411,7 @@ symbols! {
underscore_imports,
underscore_lifetimes,
uniform_paths,
unimplemented_macro,
unit,
universal_impl_trait,
unix,
Expand All @@ -1393,6 +1420,7 @@ symbols! {
unpin,
unreachable,
unreachable_code,
unreachable_macro,
unrestricted_attribute_tokens,
unsafe_block_in_unsafe_fn,
unsafe_cell,
Expand Down Expand Up @@ -1423,6 +1451,7 @@ symbols! {
var,
variant_count,
vec,
vec_macro,
version,
vis,
visible_private_types,
Expand All @@ -1447,7 +1476,9 @@ symbols! {
wrapping_sub,
wreg,
write_bytes,
write_macro,
write_str,
writeln_macro,
x87_reg,
xer,
xmm_reg,
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#[cfg(not(test))]
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "vec_macro"]
#[allow_internal_unstable(box_syntax, liballoc_internals)]
macro_rules! vec {
() => (
Expand Down
24 changes: 24 additions & 0 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ macro_rules! panic {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_eq_macro")]
#[allow_internal_unstable(core_panic)]
macro_rules! assert_eq {
($left:expr, $right:expr $(,)?) => ({
Expand Down Expand Up @@ -80,6 +81,7 @@ macro_rules! assert_eq {
/// ```
#[macro_export]
#[stable(feature = "assert_ne", since = "1.13.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_ne_macro")]
#[allow_internal_unstable(core_panic)]
macro_rules! assert_ne {
($left:expr, $right:expr $(,)?) => ({
Expand Down Expand Up @@ -236,6 +238,7 @@ macro_rules! debug_assert {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "debug_assert_eq_macro")]
macro_rules! debug_assert_eq {
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_eq!($($arg)*); })
}
Expand All @@ -261,6 +264,7 @@ macro_rules! debug_assert_eq {
/// ```
#[macro_export]
#[stable(feature = "assert_ne", since = "1.13.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "debug_assert_ne_macro")]
macro_rules! debug_assert_ne {
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); })
}
Expand Down Expand Up @@ -320,6 +324,7 @@ pub macro debug_assert_matches($($arg:tt)*) {
/// ```
#[macro_export]
#[stable(feature = "matches_macro", since = "1.42.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "matches_macro")]
macro_rules! matches {
($expression:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
match $expression {
Expand Down Expand Up @@ -475,6 +480,7 @@ macro_rules! r#try {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "write_macro")]
macro_rules! write {
($dst:expr, $($arg:tt)*) => ($dst.write_fmt($crate::format_args!($($arg)*)))
}
Expand Down Expand Up @@ -525,6 +531,7 @@ macro_rules! write {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "writeln_macro")]
#[allow_internal_unstable(format_args_nl)]
macro_rules! writeln {
($dst:expr $(,)?) => (
Expand Down Expand Up @@ -589,6 +596,7 @@ macro_rules! writeln {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "unreachable_macro")]
#[allow_internal_unstable(core_panic)]
macro_rules! unreachable {
() => ({
Expand Down Expand Up @@ -675,6 +683,7 @@ macro_rules! unreachable {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "unimplemented_macro")]
#[allow_internal_unstable(core_panic)]
macro_rules! unimplemented {
() => ($crate::panicking::panic("not implemented"));
Expand Down Expand Up @@ -737,6 +746,7 @@ macro_rules! unimplemented {
/// ```
#[macro_export]
#[stable(feature = "todo_macro", since = "1.40.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "todo_macro")]
#[allow_internal_unstable(core_panic)]
macro_rules! todo {
() => ($crate::panicking::panic("not yet implemented"));
Expand Down Expand Up @@ -786,6 +796,7 @@ pub(crate) mod builtin {
#[stable(feature = "compile_error_macro", since = "1.20.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "compile_error_macro")]
macro_rules! compile_error {
($msg:expr $(,)?) => {{ /* compiler built-in */ }};
}
Expand Down Expand Up @@ -835,6 +846,7 @@ pub(crate) mod builtin {
/// assert_eq!(s, format!("hello {}", "world"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "format_args_macro")]
#[allow_internal_unsafe]
#[allow_internal_unstable(fmt_internals)]
#[rustc_builtin_macro]
Expand Down Expand Up @@ -905,6 +917,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "env_macro")]
macro_rules! env {
($name:expr $(,)?) => {{ /* compiler built-in */ }};
($name:expr, $error_msg:expr $(,)?) => {{ /* compiler built-in */ }};
Expand All @@ -930,6 +943,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "option_env_macro")]
macro_rules! option_env {
($name:expr $(,)?) => {{ /* compiler built-in */ }};
}
Expand Down Expand Up @@ -1015,6 +1029,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "concat_macro")]
macro_rules! concat {
($($e:expr),* $(,)?) => {{ /* compiler built-in */ }};
}
Expand All @@ -1040,6 +1055,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "line_macro")]
macro_rules! line {
() => {
/* compiler built-in */
Expand Down Expand Up @@ -1079,6 +1095,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "column_macro")]
macro_rules! column {
() => {
/* compiler built-in */
Expand All @@ -1104,6 +1121,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "file_macro")]
macro_rules! file {
() => {
/* compiler built-in */
Expand All @@ -1128,6 +1146,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "stringify_macro")]
macro_rules! stringify {
($($t:tt)*) => {
/* compiler built-in */
Expand Down Expand Up @@ -1169,6 +1188,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "include_str_macro")]
macro_rules! include_str {
($file:expr $(,)?) => {{ /* compiler built-in */ }};
}
Expand Down Expand Up @@ -1208,6 +1228,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "include_bytes_macro")]
macro_rules! include_bytes {
($file:expr $(,)?) => {{ /* compiler built-in */ }};
}
Expand All @@ -1232,6 +1253,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "module_path_macro")]
macro_rules! module_path {
() => {
/* compiler built-in */
Expand Down Expand Up @@ -1265,6 +1287,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "cfg_macro")]
macro_rules! cfg {
($($cfg:tt)*) => {
/* compiler built-in */
Expand Down Expand Up @@ -1315,6 +1338,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_builtin_macro]
#[macro_export]
#[cfg_attr(not(test), rustc_diagnostic_item = "include_macro")]
macro_rules! include {
($file:expr $(,)?) => {{ /* compiler built-in */ }};
}
Expand Down
Loading

0 comments on commit cf4549c

Please sign in to comment.