aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-03 16:54:29 +0000
committerGitHub <[email protected]>2021-02-03 16:54:29 +0000
commit6817f1ff99123af3fdef0657bd25dbc507065210 (patch)
tree6eb56b4241c51a2121640b4d27ad4aa75175dd86 /crates/hir_def
parentc92be90fd227c3cf96ab9b5f4a9cb6684b00c05e (diff)
parentd4a22fc801f4768990c7e62241bea5fe4ff92ead (diff)
Merge #7544
7544: Update `DefMap` and `block_def_map` docs r=jonas-schievink a=jonas-schievink bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/db.rs15
-rw-r--r--crates/hir_def/src/nameres.rs11
2 files changed, 25 insertions, 1 deletions
diff --git a/crates/hir_def/src/db.rs b/crates/hir_def/src/db.rs
index 7fe6f6346..6c01f1ed0 100644
--- a/crates/hir_def/src/db.rs
+++ b/crates/hir_def/src/db.rs
@@ -58,6 +58,21 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
58 #[salsa::invoke(DefMap::crate_def_map_query)] 58 #[salsa::invoke(DefMap::crate_def_map_query)]
59 fn crate_def_map_query(&self, krate: CrateId) -> Arc<DefMap>; 59 fn crate_def_map_query(&self, krate: CrateId) -> Arc<DefMap>;
60 60
61 /// Computes the block-level `DefMap`, returning `None` when `block` doesn't contain any inner
62 /// items directly.
63 ///
64 /// For example:
65 ///
66 /// ```
67 /// fn f() { // (0)
68 /// { // (1)
69 /// fn inner() {}
70 /// }
71 /// }
72 /// ```
73 ///
74 /// The `block_def_map` for block 0 would return `None`, while `block_def_map` of block 1 would
75 /// return a `DefMap` containing `inner`.
61 #[salsa::invoke(DefMap::block_def_map_query)] 76 #[salsa::invoke(DefMap::block_def_map_query)]
62 fn block_def_map(&self, block: BlockId) -> Option<Arc<DefMap>>; 77 fn block_def_map(&self, block: BlockId) -> Option<Arc<DefMap>>;
63 78
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index ece5958f4..ef54f7d08 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -73,7 +73,15 @@ use crate::{
73 AstId, BlockId, BlockLoc, LocalModuleId, ModuleDefId, ModuleId, 73 AstId, BlockId, BlockLoc, LocalModuleId, ModuleDefId, ModuleId,
74}; 74};
75 75
76/// Contains all top-level defs from a macro-expanded crate 76/// Contains the results of (early) name resolution.
77///
78/// A `DefMap` stores the module tree and the definitions that are in scope in every module after
79/// item-level macros have been expanded.
80///
81/// Every crate has a primary `DefMap` whose root is the crate's main file (`main.rs`/`lib.rs`),
82/// computed by the `crate_def_map` query. Additionally, every block expression introduces the
83/// opportunity to write arbitrary item and module hierarchies, and thus gets its own `DefMap` that
84/// is computed by the `block_def_map` query.
77#[derive(Debug, PartialEq, Eq)] 85#[derive(Debug, PartialEq, Eq)]
78pub struct DefMap { 86pub struct DefMap {
79 _c: Count<Self>, 87 _c: Count<Self>,
@@ -91,6 +99,7 @@ pub struct DefMap {
91 diagnostics: Vec<DefDiagnostic>, 99 diagnostics: Vec<DefDiagnostic>,
92} 100}
93 101
102/// For `DefMap`s computed for a block expression, this stores its location in the parent map.
94#[derive(Debug, PartialEq, Eq)] 103#[derive(Debug, PartialEq, Eq)]
95struct BlockInfo { 104struct BlockInfo {
96 block: BlockId, 105 block: BlockId,