Skip to content

Commit 607b8c3

Browse files
committed
Comment on the purpose(s) of NodeId in VariantData
1 parent 46750d0 commit 607b8c3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/librustc_front/hir.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,17 @@ impl StructFieldKind {
11611161
}
11621162
}
11631163

1164+
/// Fields and Ids of enum variants and structs
1165+
///
1166+
/// For enum variants: `NodeId` represents both an Id of the variant itself (relevant for all
1167+
/// variant kinds) and an Id of the variant's constructor (not relevant for `Struct`-variants).
1168+
/// One shared Id can be successfully used for these two purposes.
1169+
/// Id of the whole enum lives in `Item`.
1170+
///
1171+
/// For structs: `NodeId` represents an Id of the structure's constructor, so it is not actually
1172+
/// used for `Struct`-structs (but still presents). Structures don't have an analogue of "Id of
1173+
/// the variant itself" from enum variants.
1174+
/// Id of the whole struct lives in `Item`.
11641175
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
11651176
pub enum VariantData {
11661177
Struct(Vec<StructField>, NodeId),

src/libsyntax/ast.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,17 @@ impl StructFieldKind {
17411741
}
17421742
}
17431743

1744+
/// Fields and Ids of enum variants and structs
1745+
///
1746+
/// For enum variants: `NodeId` represents both an Id of the variant itself (relevant for all
1747+
/// variant kinds) and an Id of the variant's constructor (not relevant for `Struct`-variants).
1748+
/// One shared Id can be successfully used for these two purposes.
1749+
/// Id of the whole enum lives in `Item`.
1750+
///
1751+
/// For structs: `NodeId` represents an Id of the structure's constructor, so it is not actually
1752+
/// used for `Struct`-structs (but still presents). Structures don't have an analogue of "Id of
1753+
/// the variant itself" from enum variants.
1754+
/// Id of the whole struct lives in `Item`.
17441755
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
17451756
pub enum VariantData {
17461757
Struct(Vec<StructField>, NodeId),

0 commit comments

Comments
 (0)