diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-20 16:45:58 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-20 16:45:58 +0100 |
commit | 0492b18ed47115c630cf3490fcdf904155f6e496 (patch) | |
tree | 534255fd111da9af89ebe19a8f6df886783155b1 /crates | |
parent | 24ac228c395681e600b0a7034bd332458af9ce8c (diff) | |
parent | 6a4cf48bffb739c3657443ae308fc0c91215d4d3 (diff) |
Merge #1883
1883: Fix path attribute causing false "unresolved module" error for submodules r=matklad a=gfreezy
fixed #1880
Co-authored-by: gfreezy <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/mod_resolution.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/mod_resolution.rs | 31 |
3 files changed, 40 insertions, 2 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index a6b9b41d0..6b253ac40 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use ra_db::FileId; | 1 | use ra_db::FileId; |
2 | use ra_syntax::ast; | 2 | use ra_syntax::{ast, SmolStr}; |
3 | use rustc_hash::FxHashMap; | 3 | use rustc_hash::FxHashMap; |
4 | use test_utils::tested_by; | 4 | use test_utils::tested_by; |
5 | 5 | ||
@@ -98,6 +98,7 @@ where | |||
98 | self.def_map.modules[module_id].definition = Some(file_id); | 98 | self.def_map.modules[module_id].definition = Some(file_id); |
99 | ModCollector { | 99 | ModCollector { |
100 | def_collector: &mut *self, | 100 | def_collector: &mut *self, |
101 | attr_path: None, | ||
101 | module_id, | 102 | module_id, |
102 | file_id: file_id.into(), | 103 | file_id: file_id.into(), |
103 | raw_items: &raw_items, | 104 | raw_items: &raw_items, |
@@ -474,6 +475,7 @@ where | |||
474 | ModCollector { | 475 | ModCollector { |
475 | def_collector: &mut *self, | 476 | def_collector: &mut *self, |
476 | file_id, | 477 | file_id, |
478 | attr_path: None, | ||
477 | module_id, | 479 | module_id, |
478 | raw_items: &raw_items, | 480 | raw_items: &raw_items, |
479 | parent_module: None, | 481 | parent_module: None, |
@@ -497,6 +499,7 @@ struct ModCollector<'a, D> { | |||
497 | def_collector: D, | 499 | def_collector: D, |
498 | module_id: CrateModuleId, | 500 | module_id: CrateModuleId, |
499 | file_id: HirFileId, | 501 | file_id: HirFileId, |
502 | attr_path: Option<&'a SmolStr>, | ||
500 | raw_items: &'a raw::RawItems, | 503 | raw_items: &'a raw::RawItems, |
501 | parent_module: Option<ParentModule<'a>>, | 504 | parent_module: Option<ParentModule<'a>>, |
502 | } | 505 | } |
@@ -551,6 +554,7 @@ where | |||
551 | ModCollector { | 554 | ModCollector { |
552 | def_collector: &mut *self.def_collector, | 555 | def_collector: &mut *self.def_collector, |
553 | module_id, | 556 | module_id, |
557 | attr_path: attr_path.as_ref(), | ||
554 | file_id: self.file_id, | 558 | file_id: self.file_id, |
555 | raw_items: self.raw_items, | 559 | raw_items: self.raw_items, |
556 | parent_module: Some(parent_module), | 560 | parent_module: Some(parent_module), |
@@ -567,6 +571,7 @@ where | |||
567 | match resolve_submodule( | 571 | match resolve_submodule( |
568 | self.def_collector.db, | 572 | self.def_collector.db, |
569 | self.file_id, | 573 | self.file_id, |
574 | self.attr_path, | ||
570 | name, | 575 | name, |
571 | is_root, | 576 | is_root, |
572 | attr_path.as_ref(), | 577 | attr_path.as_ref(), |
@@ -578,6 +583,7 @@ where | |||
578 | ModCollector { | 583 | ModCollector { |
579 | def_collector: &mut *self.def_collector, | 584 | def_collector: &mut *self.def_collector, |
580 | module_id, | 585 | module_id, |
586 | attr_path: attr_path.as_ref(), | ||
581 | file_id: file_id.into(), | 587 | file_id: file_id.into(), |
582 | raw_items: &raw_items, | 588 | raw_items: &raw_items, |
583 | parent_module: None, | 589 | parent_module: None, |
diff --git a/crates/ra_hir/src/nameres/mod_resolution.rs b/crates/ra_hir/src/nameres/mod_resolution.rs index a9e9eb9e6..3aa32bd66 100644 --- a/crates/ra_hir/src/nameres/mod_resolution.rs +++ b/crates/ra_hir/src/nameres/mod_resolution.rs | |||
@@ -23,6 +23,7 @@ impl<'a> ParentModule<'a> { | |||
23 | pub(super) fn resolve_submodule( | 23 | pub(super) fn resolve_submodule( |
24 | db: &impl DefDatabase, | 24 | db: &impl DefDatabase, |
25 | file_id: HirFileId, | 25 | file_id: HirFileId, |
26 | mod_attr_path: Option<&SmolStr>, | ||
26 | name: &Name, | 27 | name: &Name, |
27 | is_root: bool, | 28 | is_root: bool, |
28 | attr_path: Option<&SmolStr>, | 29 | attr_path: Option<&SmolStr>, |
@@ -80,7 +81,7 @@ pub(super) fn resolve_submodule( | |||
80 | ResolutionMode::OutOfLine(OutOfLineMode::WithAttributePath(path)) | 81 | ResolutionMode::OutOfLine(OutOfLineMode::WithAttributePath(path)) |
81 | } | 82 | } |
82 | (None, None) => { | 83 | (None, None) => { |
83 | let is_dir_owner = is_root || mod_name == "mod"; | 84 | let is_dir_owner = is_root || mod_name == "mod" || mod_attr_path.is_some(); |
84 | if is_dir_owner { | 85 | if is_dir_owner { |
85 | let file_mod = dir_path.join(format!("{}.rs", name)); | 86 | let file_mod = dir_path.join(format!("{}.rs", name)); |
86 | let dir_mod = dir_path.join(format!("{}/mod.rs", name)); | 87 | let dir_mod = dir_path.join(format!("{}/mod.rs", name)); |
diff --git a/crates/ra_hir/src/nameres/tests/mod_resolution.rs b/crates/ra_hir/src/nameres/tests/mod_resolution.rs index 4f8398460..e3e6f1e95 100644 --- a/crates/ra_hir/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir/src/nameres/tests/mod_resolution.rs | |||
@@ -706,3 +706,34 @@ fn unresolved_module_diagnostics() { | |||
706 | "### | 706 | "### |
707 | ); | 707 | ); |
708 | } | 708 | } |
709 | |||
710 | #[test] | ||
711 | fn module_resolution_decl_inside_module_in_non_crate_root_2() { | ||
712 | let map = def_map_with_crate_graph( | ||
713 | r###" | ||
714 | //- /main.rs | ||
715 | #[path="module/m2.rs"] | ||
716 | mod module; | ||
717 | |||
718 | //- /module/m2.rs | ||
719 | pub mod submod; | ||
720 | |||
721 | //- /module/submod.rs | ||
722 | pub struct Baz; | ||
723 | "###, | ||
724 | crate_graph! { | ||
725 | "main": ("/main.rs", []), | ||
726 | }, | ||
727 | ); | ||
728 | |||
729 | assert_snapshot!(map, @r###" | ||
730 | ⋮crate | ||
731 | ⋮module: t | ||
732 | ⋮ | ||
733 | ⋮crate::module | ||
734 | ⋮submod: t | ||
735 | ⋮ | ||
736 | ⋮crate::module::submod | ||
737 | ⋮Baz: t v | ||
738 | "###); | ||
739 | } | ||