This commit is contained in:
Aleksey Kladov 2019-09-06 14:30:24 +03:00
parent 3bdb456d17
commit f477f2516a
2 changed files with 51 additions and 49 deletions

View file

@ -1,51 +1,51 @@
/// This module implements import-resolution/macro expansion algorithm. //! This module implements import-resolution/macro expansion algorithm.
/// //!
/// The result of this module is `CrateDefMap`: a data structure which contains: //! The result of this module is `CrateDefMap`: a data structure which contains:
/// //!
/// * a tree of modules for the crate //! * a tree of modules for the crate
/// * for each module, a set of items visible in the module (directly declared //! * for each module, a set of items visible in the module (directly declared
/// or imported) //! or imported)
/// //!
/// Note that `CrateDefMap` contains fully macro expanded code. //! Note that `CrateDefMap` contains fully macro expanded code.
/// //!
/// Computing `CrateDefMap` can be partitioned into several logically //! Computing `CrateDefMap` can be partitioned into several logically
/// independent "phases". The phases are mutually recursive though, there's no //! independent "phases". The phases are mutually recursive though, there's no
/// strict ordering. //! strict ordering.
/// //!
/// ## Collecting RawItems //! ## Collecting RawItems
/// //!
/// This happens in the `raw` module, which parses a single source file into a //! This happens in the `raw` module, which parses a single source file into a
/// set of top-level items. Nested imports are desugared to flat imports in //! set of top-level items. Nested imports are desugared to flat imports in
/// this phase. Macro calls are represented as a triple of (Path, Option<Name>, //! this phase. Macro calls are represented as a triple of (Path, Option<Name>,
/// TokenTree). //! TokenTree).
/// //!
/// ## Collecting Modules //! ## Collecting Modules
/// //!
/// This happens in the `collector` module. In this phase, we recursively walk //! This happens in the `collector` module. In this phase, we recursively walk
/// tree of modules, collect raw items from submodules, populate module scopes //! tree of modules, collect raw items from submodules, populate module scopes
/// with defined items (so, we assign item ids in this phase) and record the set //! with defined items (so, we assign item ids in this phase) and record the set
/// of unresolved imports and macros. //! of unresolved imports and macros.
/// //!
/// While we walk tree of modules, we also record macro_rules definitions and //! While we walk tree of modules, we also record macro_rules definitions and
/// expand calls to macro_rules defined macros. //! expand calls to macro_rules defined macros.
/// //!
/// ## Resolving Imports //! ## Resolving Imports
/// //!
/// We maintain a list of currently unresolved imports. On every iteration, we //! We maintain a list of currently unresolved imports. On every iteration, we
/// try to resolve some imports from this list. If the import is resolved, we //! try to resolve some imports from this list. If the import is resolved, we
/// record it, by adding an item to current module scope and, if necessary, by //! record it, by adding an item to current module scope and, if necessary, by
/// recursively populating glob imports. //! recursively populating glob imports.
/// //!
/// ## Resolving Macros //! ## Resolving Macros
/// //!
/// macro_rules from the same crate use a global mutable namespace. We expand //! macro_rules from the same crate use a global mutable namespace. We expand
/// them immediately, when we collect modules. //! them immediately, when we collect modules.
/// //!
/// Macros from other crates (including proc-macros) can be used with //! Macros from other crates (including proc-macros) can be used with
/// `foo::bar!` syntax. We handle them similarly to imports. There's a list of //! `foo::bar!` syntax. We handle them similarly to imports. There's a list of
/// unexpanded macros. On every iteration, we try to resolve each macro call //! unexpanded macros. On every iteration, we try to resolve each macro call
/// path and, upon success, we run macro expansion and "collect module" phase //! path and, upon success, we run macro expansion and "collect module" phase
/// on the result //! on the result
mod per_ns; mod per_ns;
mod raw; mod raw;

View file

@ -1,3 +1,5 @@
//! This module resolves `mod foo;` declaration to file.
use std::{borrow::Cow, sync::Arc}; use std::{borrow::Cow, sync::Arc};
use ra_db::{FileId, SourceRoot}; use ra_db::{FileId, SourceRoot};
@ -77,7 +79,7 @@ pub(super) fn resolve_submodule(
let path = dir_path.join(file_path.as_ref()).normalize(); let path = dir_path.join(file_path.as_ref()).normalize();
ResolutionMode::OutOfLine(OutOfLineMode::WithAttributePath(path)) ResolutionMode::OutOfLine(OutOfLineMode::WithAttributePath(path))
} }
_ => { (None, None) => {
let is_dir_owner = is_root || mod_name == "mod"; let is_dir_owner = is_root || mod_name == "mod";
if is_dir_owner { if is_dir_owner {
let file_mod = dir_path.join(format!("{}.rs", name)); let file_mod = dir_path.join(format!("{}.rs", name));