Skip to content

Commit 5a2fd1a

Browse files
committed
Improve comments about attributes and meta items.
I have found the distinction confusing.
1 parent c9ae38c commit 5a2fd1a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

compiler/rustc_ast/src/ast.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -479,20 +479,24 @@ pub struct Crate {
479479
pub is_placeholder: bool,
480480
}
481481

482-
/// Possible values inside of compile-time attribute lists.
482+
/// Values inside meta item lists.
483483
///
484-
/// E.g., the '..' in `#[name(..)]`.
484+
/// E.g., each of `Clone`, `Copy` in `#[derive(Clone, Copy)]`.
485485
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
486486
pub enum NestedMetaItem {
487487
/// A full MetaItem, for recursive meta items.
488488
MetaItem(MetaItem),
489+
489490
/// A literal.
490491
///
491492
/// E.g., `"foo"`, `64`, `true`.
492493
Lit(MetaItemLit),
493494
}
494495

495-
/// A spanned compile-time attribute item.
496+
/// A semantic representation of a meta item. A meta item is a slightly
497+
/// restricted form of an attribute -- it can only contain expressions in
498+
/// certain leaf positions, rather than arbitrary token streams -- that is used
499+
/// for most built-in attributes.
496500
///
497501
/// E.g., `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]`.
498502
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
@@ -502,22 +506,22 @@ pub struct MetaItem {
502506
pub span: Span,
503507
}
504508

505-
/// A compile-time attribute item.
506-
///
507-
/// E.g., `#[test]`, `#[derive(..)]` or `#[feature = "foo"]`.
509+
/// The meta item kind, containing the data after the initial path.
508510
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
509511
pub enum MetaItemKind {
510512
/// Word meta item.
511513
///
512-
/// E.g., `test` as in `#[test]`.
514+
/// E.g., `#[test]`, which lacks any arguments after `test`.
513515
Word,
516+
514517
/// List meta item.
515518
///
516-
/// E.g., `derive(..)` as in `#[derive(..)]`.
519+
/// E.g., `#[derive(..)]`, where the field represents the `..`.
517520
List(Vec<NestedMetaItem>),
521+
518522
/// Name value meta item.
519523
///
520-
/// E.g., `feature = "foo"` as in `#[feature = "foo"]`.
524+
/// E.g., `#[feature = "foo"]`, where the field represents the `"foo"`.
521525
NameValue(MetaItemLit),
522526
}
523527

@@ -2580,7 +2584,7 @@ pub struct AttrItem {
25802584
/// A list of attributes.
25812585
pub type AttrVec = ThinVec<Attribute>;
25822586

2583-
/// Metadata associated with an item.
2587+
/// A syntax-level representation of an attribute.
25842588
#[derive(Clone, Encodable, Decodable, Debug)]
25852589
pub struct Attribute {
25862590
pub kind: AttrKind,

0 commit comments

Comments
 (0)