Skip to content

Commit dedf0ff

Browse files
committed
internal: document NameClass and NameRefClass
1 parent 325140a commit dedf0ff

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

crates/ide_db/src/defs.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,25 @@ impl Definition {
9797
}
9898
}
9999

100+
/// On a first blush, a single `ast::Name` defines a single definition at some
101+
/// scope. That is, that, by just looking at the syntactical category, we can
102+
/// unambiguously define the semantic category.
103+
///
104+
/// Sadly, that's not 100% true, there are special cases. To make sure that call
105+
/// the code handles all the special cases correctly via exhaustive matching, we
106+
/// add a [`NameClass`] enum which lists all of them!
107+
///
108+
/// A model special case is `None` constant in pattern.
100109
#[derive(Debug)]
101110
pub enum NameClass {
102111
ExternCrate(Crate),
103112
Definition(Definition),
104113
/// `None` in `if let None = Some(82) {}`.
114+
/// Syntactically, it is a name, but semantically it is a reference.
105115
ConstReference(Definition),
106-
/// `field` in `if let Foo { field } = foo`.
116+
/// `field` in `if let Foo { field } = foo`. Here, `ast::Name` both Here the
117+
/// name both introduces a definition into a local scope, and refers to an
118+
/// existing definition.
107119
PatFieldShorthand {
108120
local_def: Local,
109121
field_ref: Definition,
@@ -283,6 +295,12 @@ impl NameClass {
283295
}
284296
}
285297

298+
/// This is similar to [`NameClass`], but works for [`ast::NameRef`] rather than
299+
/// for [`ast::Name`]. Similarly, what looks like a reference in syntax is a
300+
/// reference most of the time, but there are a couple of annoying exceptions.
301+
///
302+
/// A model special case is field shorthand syntax, which uses a single
303+
/// reference to point to two different defs.
286304
#[derive(Debug)]
287305
pub enum NameRefClass {
288306
ExternCrate(Crate),

0 commit comments

Comments
 (0)