1883: Fix path attribute causing false "unresolved module" error for submodules r=matklad a=gfreezy

fixed #1880

Co-authored-by: gfreezy <gfreezy@gmail.com>
This commit is contained in:
bors[bot] 2019-09-20 15:45:58 +00:00 committed by GitHub
commit 0492b18ed4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 2 deletions

View file

@ -1,5 +1,5 @@
use ra_db::FileId;
use ra_syntax::ast;
use ra_syntax::{ast, SmolStr};
use rustc_hash::FxHashMap;
use test_utils::tested_by;
@ -98,6 +98,7 @@ where
self.def_map.modules[module_id].definition = Some(file_id);
ModCollector {
def_collector: &mut *self,
attr_path: None,
module_id,
file_id: file_id.into(),
raw_items: &raw_items,
@ -474,6 +475,7 @@ where
ModCollector {
def_collector: &mut *self,
file_id,
attr_path: None,
module_id,
raw_items: &raw_items,
parent_module: None,
@ -497,6 +499,7 @@ struct ModCollector<'a, D> {
def_collector: D,
module_id: CrateModuleId,
file_id: HirFileId,
attr_path: Option<&'a SmolStr>,
raw_items: &'a raw::RawItems,
parent_module: Option<ParentModule<'a>>,
}
@ -551,6 +554,7 @@ where
ModCollector {
def_collector: &mut *self.def_collector,
module_id,
attr_path: attr_path.as_ref(),
file_id: self.file_id,
raw_items: self.raw_items,
parent_module: Some(parent_module),
@ -567,6 +571,7 @@ where
match resolve_submodule(
self.def_collector.db,
self.file_id,
self.attr_path,
name,
is_root,
attr_path.as_ref(),
@ -578,6 +583,7 @@ where
ModCollector {
def_collector: &mut *self.def_collector,
module_id,
attr_path: attr_path.as_ref(),
file_id: file_id.into(),
raw_items: &raw_items,
parent_module: None,

View file

@ -23,6 +23,7 @@ impl<'a> ParentModule<'a> {
pub(super) fn resolve_submodule(
db: &impl DefDatabase,
file_id: HirFileId,
mod_attr_path: Option<&SmolStr>,
name: &Name,
is_root: bool,
attr_path: Option<&SmolStr>,
@ -80,7 +81,7 @@ pub(super) fn resolve_submodule(
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" || mod_attr_path.is_some();
if is_dir_owner {
let file_mod = dir_path.join(format!("{}.rs", name));
let dir_mod = dir_path.join(format!("{}/mod.rs", name));

View file

@ -706,3 +706,34 @@ fn unresolved_module_diagnostics() {
"###
);
}
#[test]
fn module_resolution_decl_inside_module_in_non_crate_root_2() {
let map = def_map_with_crate_graph(
r###"
//- /main.rs
#[path="module/m2.rs"]
mod module;
//- /module/m2.rs
pub mod submod;
//- /module/submod.rs
pub struct Baz;
"###,
crate_graph! {
"main": ("/main.rs", []),
},
);
assert_snapshot!(map, @r###"
crate
module: t
crate::module
submod: t
crate::module::submod
Baz: t v
"###);
}