about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorSydney Acksman <obsidianminor@gmail.com>2024-07-20 14:09:13 -0500
committerSydney Acksman <obsidianminor@gmail.com>2024-07-20 14:32:28 -0500
commite43b74a1f6fe7bb32fe6fff9def9e2d3cfeb4b9e (patch)
tree6c30f508026d6a81565bc17c0e598691a957dbee /src/tools
parentb939d3bf30a7a75585774b2597735144c0c264bf (diff)
downloadrust-e43b74a1f6fe7bb32fe6fff9def9e2d3cfeb4b9e.tar.gz
rust-e43b74a1f6fe7bb32fe6fff9def9e2d3cfeb4b9e.zip
Fix path resolution for child mods of those expanded by `include!`
Child modules wouldn't use the correct candidate paths due to a branch that doesn't seem to be doing what it's intended to do. Removing the branch fixes the problem and all existing test cases pass.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/nameres/mod_resolution.rs6
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs46
2 files changed, 47 insertions, 5 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/mod_resolution.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/mod_resolution.rs
index 19fdd8e33d4..ab4ffbb2c1e 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/mod_resolution.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/mod_resolution.rs
@@ -1,7 +1,7 @@
 //! This module resolves `mod foo;` declaration to file.
 use arrayvec::ArrayVec;
 use base_db::AnchoredPath;
-use hir_expand::{name::Name, HirFileIdExt, MacroFileIdExt};
+use hir_expand::{name::Name, HirFileIdExt};
 use limit::Limit;
 use span::EditionedFileId;
 use syntax::ToSmolStr as _;
@@ -73,10 +73,6 @@ impl ModDir {
             Some(attr_path) => {
                 candidate_files.push(self.dir_path.join_attr(attr_path, self.root_non_dir_owner))
             }
-            None if file_id.macro_file().map_or(false, |it| it.is_include_macro(db.upcast())) => {
-                candidate_files.push(format!("{}.rs", name.display(db.upcast())));
-                candidate_files.push(format!("{}/mod.rs", name.display(db.upcast())));
-            }
             None => {
                 candidate_files.push(format!(
                     "{}{}.rs",
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs
index 14d497b3a11..b6e1cfb3ebd 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs
@@ -1310,6 +1310,52 @@ pub mod ip_address {
 }
 
 #[test]
+fn include_with_submod_file() {
+    check(
+        r#"
+//- minicore: include
+//- /lib.rs
+include!("out_dir/includes.rs");
+
+//- /out_dir/includes.rs
+pub mod company_name {
+    pub mod network {
+        pub mod v1;
+    }
+}
+//- /out_dir/company_name/network/v1.rs
+pub struct IpAddress {
+    pub ip_type: &'static str,
+}
+/// Nested message and enum types in `IpAddress`.
+pub mod ip_address {
+    pub enum IpType {
+        IpV4(u32),
+    }
+}
+
+"#,
+        expect![[r#"
+            crate
+            company_name: t
+
+            crate::company_name
+            network: t
+
+            crate::company_name::network
+            v1: t
+
+            crate::company_name::network::v1
+            IpAddress: t
+            ip_address: t
+
+            crate::company_name::network::v1::ip_address
+            IpType: t
+        "#]],
+    );
+}
+
+#[test]
 fn macro_use_imports_all_macro_types() {
     let db = TestDB::with_files(
         r#"