aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/nameres.rs96
-rw-r--r--crates/ra_hir/src/nameres/mod_resolution.rs4
2 files changed, 51 insertions, 49 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index dc2e2172b..fe90879b6 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -1,51 +1,51 @@
1/// This module implements import-resolution/macro expansion algorithm. 1//! This module implements import-resolution/macro expansion algorithm.
2/// 2//!
3/// The result of this module is `CrateDefMap`: a data structure which contains: 3//! The result of this module is `CrateDefMap`: a data structure which contains:
4/// 4//!
5/// * a tree of modules for the crate 5//! * a tree of modules for the crate
6/// * for each module, a set of items visible in the module (directly declared 6//! * for each module, a set of items visible in the module (directly declared
7/// or imported) 7//! or imported)
8/// 8//!
9/// Note that `CrateDefMap` contains fully macro expanded code. 9//! Note that `CrateDefMap` contains fully macro expanded code.
10/// 10//!
11/// Computing `CrateDefMap` can be partitioned into several logically 11//! Computing `CrateDefMap` can be partitioned into several logically
12/// independent "phases". The phases are mutually recursive though, there's no 12//! independent "phases". The phases are mutually recursive though, there's no
13/// strict ordering. 13//! strict ordering.
14/// 14//!
15/// ## Collecting RawItems 15//! ## Collecting RawItems
16/// 16//!
17/// This happens in the `raw` module, which parses a single source file into a 17//! This happens in the `raw` module, which parses a single source file into a
18/// set of top-level items. Nested imports are desugared to flat imports in 18//! set of top-level items. Nested imports are desugared to flat imports in
19/// this phase. Macro calls are represented as a triple of (Path, Option<Name>, 19//! this phase. Macro calls are represented as a triple of (Path, Option<Name>,
20/// TokenTree). 20//! TokenTree).
21/// 21//!
22/// ## Collecting Modules 22//! ## Collecting Modules
23/// 23//!
24/// This happens in the `collector` module. In this phase, we recursively walk 24//! This happens in the `collector` module. In this phase, we recursively walk
25/// tree of modules, collect raw items from submodules, populate module scopes 25//! tree of modules, collect raw items from submodules, populate module scopes
26/// with defined items (so, we assign item ids in this phase) and record the set 26//! with defined items (so, we assign item ids in this phase) and record the set
27/// of unresolved imports and macros. 27//! of unresolved imports and macros.
28/// 28//!
29/// While we walk tree of modules, we also record macro_rules definitions and 29//! While we walk tree of modules, we also record macro_rules definitions and
30/// expand calls to macro_rules defined macros. 30//! expand calls to macro_rules defined macros.
31/// 31//!
32/// ## Resolving Imports 32//! ## Resolving Imports
33/// 33//!
34/// We maintain a list of currently unresolved imports. On every iteration, we 34//! We maintain a list of currently unresolved imports. On every iteration, we
35/// try to resolve some imports from this list. If the import is resolved, we 35//! try to resolve some imports from this list. If the import is resolved, we
36/// record it, by adding an item to current module scope and, if necessary, by 36//! record it, by adding an item to current module scope and, if necessary, by
37/// recursively populating glob imports. 37//! recursively populating glob imports.
38/// 38//!
39/// ## Resolving Macros 39//! ## Resolving Macros
40/// 40//!
41/// macro_rules from the same crate use a global mutable namespace. We expand 41//! macro_rules from the same crate use a global mutable namespace. We expand
42/// them immediately, when we collect modules. 42//! them immediately, when we collect modules.
43/// 43//!
44/// Macros from other crates (including proc-macros) can be used with 44//! Macros from other crates (including proc-macros) can be used with
45/// `foo::bar!` syntax. We handle them similarly to imports. There's a list of 45//! `foo::bar!` syntax. We handle them similarly to imports. There's a list of
46/// unexpanded macros. On every iteration, we try to resolve each macro call 46//! unexpanded macros. On every iteration, we try to resolve each macro call
47/// path and, upon success, we run macro expansion and "collect module" phase 47//! path and, upon success, we run macro expansion and "collect module" phase
48/// on the result 48//! on the result
49 49
50mod per_ns; 50mod per_ns;
51mod raw; 51mod raw;
diff --git a/crates/ra_hir/src/nameres/mod_resolution.rs b/crates/ra_hir/src/nameres/mod_resolution.rs
index de81fd422..918c9591f 100644
--- a/crates/ra_hir/src/nameres/mod_resolution.rs
+++ b/crates/ra_hir/src/nameres/mod_resolution.rs
@@ -1,3 +1,5 @@
1//! This module resolves `mod foo;` declaration to file.
2
1use std::{borrow::Cow, sync::Arc}; 3use std::{borrow::Cow, sync::Arc};
2 4
3use ra_db::{FileId, SourceRoot}; 5use ra_db::{FileId, SourceRoot};
@@ -77,7 +79,7 @@ pub(super) fn resolve_submodule(
77 let path = dir_path.join(file_path.as_ref()).normalize(); 79 let path = dir_path.join(file_path.as_ref()).normalize();
78 ResolutionMode::OutOfLine(OutOfLineMode::WithAttributePath(path)) 80 ResolutionMode::OutOfLine(OutOfLineMode::WithAttributePath(path))
79 } 81 }
80 _ => { 82 (None, None) => {
81 let is_dir_owner = is_root || mod_name == "mod"; 83 let is_dir_owner = is_root || mod_name == "mod";
82 if is_dir_owner { 84 if is_dir_owner {
83 let file_mod = dir_path.join(format!("{}.rs", name)); 85 let file_mod = dir_path.join(format!("{}.rs", name));