2

Are all attributes in Rust implemented as Macros? Or some native attributes are created specially by the compiler/language and does not use the Macros mechanism?

If there are attributes not created via Macros, how do I identify them?

Finlay Weber
  • 2,989
  • 3
  • 17
  • 37

1 Answers1

2

There are many attributes that are not macros and are treated specifically by the compiler. Examples: #[cfg] (although this one can be considered as a macro, even if not implemented as one), #[repr], #[doc], #[allow(...)]/#[warn(...)]/#[deny(...)]/#[forbid(...)], and many more.

I don't know a way to identify such attributes except to look at the list of builtin macro attributes and see if they're there.

Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77
  • just not sure how the source code you pointed to show the list of builtin macro attributes, because from the look of things, it does not look like it – Finlay Weber Aug 28 '22 at 14:50
  • @FinlayWeber It is. This is the code in the compiler responsible to register them and their expander. – Chayim Friedman Aug 28 '22 at 20:05