Skip to content

Commit 24b27ab

Browse files
committed
Add a doc comment on the difference between Name and NameRef ast nodes
1 parent 2a5ab9f commit 24b27ab

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

crates/ra_syntax/src/ast/generated/nodes.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,20 @@ impl Visibility {
17901790
pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
17911791
}
17921792
/// Single identifier.
1793-
/// // TODO: clarify the difference between Name and NameRef
1793+
/// Note(@matklad): `Name` is for things that install a new name into the scope,
1794+
/// `NameRef` is a usage of a name. Most of the time, this definition/reference
1795+
/// distinction can be determined purely syntactically, ie in
1796+
/// ```
1797+
/// fn foo() { foo() }
1798+
/// ```
1799+
/// the first foo is `Name`, the second one is `NameRef`.
1800+
/// The notable exception are patterns, where in
1801+
/// ``
1802+
/// let x = 92
1803+
/// ```
1804+
/// `x` can be semantically either a name or a name ref, depeding on
1805+
/// wether there's an `x` constant in scope.
1806+
/// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db).
17941807
///
17951808
/// ```
17961809
/// let ❰ foo ❱ = bar;
@@ -1807,6 +1820,8 @@ impl Name {
18071820
pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
18081821
}
18091822
/// Reference to a name.
1823+
/// See the explanation on the difference between `Name` and `NameRef`
1824+
/// in `Name` ast node docs.
18101825
///
18111826
/// ```
18121827
/// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱;

xtask/src/ast_src.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,20 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
15221522
struct Visibility { T![pub], T![super], T![self], T![crate] }
15231523

15241524
/// Single identifier.
1525-
/// // TODO: clarify the difference between Name and NameRef
1525+
/// Note(@matklad): `Name` is for things that install a new name into the scope,
1526+
/// `NameRef` is a usage of a name. Most of the time, this definition/reference
1527+
/// distinction can be determined purely syntactically, ie in
1528+
/// ```
1529+
/// fn foo() { foo() }
1530+
/// ```
1531+
/// the first foo is `Name`, the second one is `NameRef`.
1532+
/// The notable exception are patterns, where in
1533+
/// ``
1534+
/// let x = 92
1535+
/// ```
1536+
/// `x` can be semantically either a name or a name ref, depeding on
1537+
/// wether there's an `x` constant in scope.
1538+
/// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db).
15261539
///
15271540
/// ```
15281541
/// let ❰ foo ❱ = bar;
@@ -1534,6 +1547,8 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
15341547
struct Name { T![ident] }
15351548

15361549
/// Reference to a name.
1550+
/// See the explanation on the difference between `Name` and `NameRef`
1551+
/// in `Name` ast node docs.
15371552
///
15381553
/// ```
15391554
/// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱;

0 commit comments

Comments
 (0)