mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
internal: document NameClass and NameRefClass
This commit is contained in:
parent
325140a165
commit
dedf0ff7c5
1 changed files with 19 additions and 1 deletions
|
@ -97,13 +97,25 @@ impl Definition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// On a first blush, a single `ast::Name` defines a single definition at some
|
||||||
|
/// scope. That is, that, by just looking at the syntactical category, we can
|
||||||
|
/// unambiguously define the semantic category.
|
||||||
|
///
|
||||||
|
/// Sadly, that's not 100% true, there are special cases. To make sure that call
|
||||||
|
/// the code handles all the special cases correctly via exhaustive matching, we
|
||||||
|
/// add a [`NameClass`] enum which lists all of them!
|
||||||
|
///
|
||||||
|
/// A model special case is `None` constant in pattern.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum NameClass {
|
pub enum NameClass {
|
||||||
ExternCrate(Crate),
|
ExternCrate(Crate),
|
||||||
Definition(Definition),
|
Definition(Definition),
|
||||||
/// `None` in `if let None = Some(82) {}`.
|
/// `None` in `if let None = Some(82) {}`.
|
||||||
|
/// Syntactically, it is a name, but semantically it is a reference.
|
||||||
ConstReference(Definition),
|
ConstReference(Definition),
|
||||||
/// `field` in `if let Foo { field } = foo`.
|
/// `field` in `if let Foo { field } = foo`. Here, `ast::Name` both Here the
|
||||||
|
/// name both introduces a definition into a local scope, and refers to an
|
||||||
|
/// existing definition.
|
||||||
PatFieldShorthand {
|
PatFieldShorthand {
|
||||||
local_def: Local,
|
local_def: Local,
|
||||||
field_ref: Definition,
|
field_ref: Definition,
|
||||||
|
@ -283,6 +295,12 @@ impl NameClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This is similar to [`NameClass`], but works for [`ast::NameRef`] rather than
|
||||||
|
/// for [`ast::Name`]. Similarly, what looks like a reference in syntax is a
|
||||||
|
/// reference most of the time, but there are a couple of annoying exceptions.
|
||||||
|
///
|
||||||
|
/// A model special case is field shorthand syntax, which uses a single
|
||||||
|
/// reference to point to two different defs.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum NameRefClass {
|
pub enum NameRefClass {
|
||||||
ExternCrate(Crate),
|
ExternCrate(Crate),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue