diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-11-25 09:53:37 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-11-29 12:09:35 +1100 |
| commit | 5a2fd1a47ffb72c060b77b717e8bfa85c7e0e5bd (patch) | |
| tree | 587dab53e54e9263165a69b62ef0446261973a2a /compiler/rustc_ast | |
| parent | c9ae38c71e2838f1ac282803ddde47f21f4ca76e (diff) | |
| download | rust-5a2fd1a47ffb72c060b77b717e8bfa85c7e0e5bd.tar.gz rust-5a2fd1a47ffb72c060b77b717e8bfa85c7e0e5bd.zip | |
Improve comments about attributes and meta items.
I have found the distinction confusing.
Diffstat (limited to 'compiler/rustc_ast')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index d0bb05c3654..9d23bb5c159 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -479,20 +479,24 @@ pub struct Crate { pub is_placeholder: bool, } -/// Possible values inside of compile-time attribute lists. +/// Values inside meta item lists. /// -/// E.g., the '..' in `#[name(..)]`. +/// E.g., each of `Clone`, `Copy` in `#[derive(Clone, Copy)]`. #[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub enum NestedMetaItem { /// A full MetaItem, for recursive meta items. MetaItem(MetaItem), + /// A literal. /// /// E.g., `"foo"`, `64`, `true`. Lit(MetaItemLit), } -/// A spanned compile-time attribute item. +/// A semantic representation of a meta item. A meta item is a slightly +/// restricted form of an attribute -- it can only contain expressions in +/// certain leaf positions, rather than arbitrary token streams -- that is used +/// for most built-in attributes. /// /// E.g., `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]`. #[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] @@ -502,22 +506,22 @@ pub struct MetaItem { pub span: Span, } -/// A compile-time attribute item. -/// -/// E.g., `#[test]`, `#[derive(..)]` or `#[feature = "foo"]`. +/// The meta item kind, containing the data after the initial path. #[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub enum MetaItemKind { /// Word meta item. /// - /// E.g., `test` as in `#[test]`. + /// E.g., `#[test]`, which lacks any arguments after `test`. Word, + /// List meta item. /// - /// E.g., `derive(..)` as in `#[derive(..)]`. + /// E.g., `#[derive(..)]`, where the field represents the `..`. List(Vec<NestedMetaItem>), + /// Name value meta item. /// - /// E.g., `feature = "foo"` as in `#[feature = "foo"]`. + /// E.g., `#[feature = "foo"]`, where the field represents the `"foo"`. NameValue(MetaItemLit), } @@ -2580,7 +2584,7 @@ pub struct AttrItem { /// A list of attributes. pub type AttrVec = ThinVec<Attribute>; -/// Metadata associated with an item. +/// A syntax-level representation of an attribute. #[derive(Clone, Encodable, Decodable, Debug)] pub struct Attribute { pub kind: AttrKind, |
