@@ -5,46 +5,55 @@ Attributes come in two types: *inert* (or *built-in*) and *active* (*non-builtin
55## Builtin/inert attributes
66
77These attributes are defined in the compiler itself, in
8- [ ` compiler/rustc_feature/src/builtin_attrs.rs ` ] [ builtin_attrs ] .
8+ [ ` compiler/rustc_feature/src/builtin_attrs.rs ` ] [ builtin_attrs ] and in the [ attribute parsers ] [ attr_parsing ] .
99
1010Examples include ` #[allow] ` and ` #[macro_use] ` .
1111
1212[ builtin_attrs ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_feature/builtin_attrs/index.html
13+ [ attr_parsing ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html
1314
1415These attributes have several important characteristics:
1516* They are always in scope, and do not participate in typical path-based resolution.
16- * They cannot be renamed. For example, ` use allow as foo ` will compile, but writing ` #[foo] ` will
17- produce an error.
17+ * They cannot be renamed.
18+ For example, ` use allow as foo ` will compile, but writing ` #[foo] ` will produce an error.
1819* They are 'inert', meaning they are left as-is by the macro expansion code.
1920 As a result, any behavior comes as a result of the compiler explicitly checking for their presence.
2021 For example, lint-related code explicitly checks for ` #[allow] ` , ` #[warn] ` , ` #[deny] ` , and
2122 ` #[forbid] ` , rather than the behavior coming from the expansion of the attributes themselves.
2223
24+ For more information on these attributes, see the chapter about [ attribute parsing] [ attr-parsing-chapter ] .
25+
26+ [ attr-parsing-chapter ] : ./hir/attribute-parsing.md
27+
2328## 'Non-builtin'/'active' attributes
2429
2530These attributes are defined by a crate - either the standard library, or a proc-macro crate.
2631
2732** Important** : Many non-builtin attributes, such as ` #[derive] ` , are still considered part of the
28- core Rust language. However, they are ** not** called 'builtin attributes', since they have a
33+ core Rust language.
34+ However, they are ** not** called 'builtin attributes', since they have a
2935corresponding definition in the standard library.
3036
3137Definitions of non-builtin attributes take two forms:
3238
33391 . Proc-macro attributes, defined via a function annotated with ` #[proc_macro_attribute] ` in a
3440 proc-macro crate.
35- 2 . AST-based attributes, defined in the standard library. These attributes have special 'stub'
41+ 2 . AST-based attributes, defined in the standard library.
42+ These attributes have special 'stub'
3643 macros defined in places like [ ` library/core/src/macros/mod.rs ` ] [ core_macros ] .
3744
3845[ core_macros ] : https://github.com/rust-lang/rust/blob/HEAD/library/core/src/macros/mod.rs
3946
4047These definitions exist to allow the macros to participate in typical path-based resolution - they
41- can be imported, re-exported, and renamed just like any other item definition. However, the body of
42- the definition is empty. Instead, the macro is annotated with the ` #[rustc_builtin_macro] `
48+ can be imported, re-exported, and renamed just like any other item definition.
49+ However, the body of the definition is empty.
50+ Instead, the macro is annotated with the ` #[rustc_builtin_macro] `
4351attribute, which tells the compiler to run a corresponding function in ` rustc_builtin_macros ` .
4452
4553All non-builtin attributes have the following characteristics:
4654* Like all other definitions (e.g. structs), they must be brought into scope via an import.
4755 Many standard library attributes are included in the prelude - this is why writing ` #[derive] `
4856 works without an import.
49- * They participate in macro expansion. The implementation of the macro may leave the attribute
57+ * They participate in macro expansion.
58+ The implementation of the macro may leave the attribute
5059 target unchanged, modify the target, produce new AST nodes, or remove the target entirely.
0 commit comments