Skip to content

fix: unescape all occurrences of module name in module resolution #13149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/hir-def/src/nameres/mod_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl ModDir {
name: &Name,
attr_path: Option<&SmolStr>,
) -> Result<(FileId, bool, ModDir), Box<[String]>> {
let name = name.unescaped();
let orig_file_id = file_id.original_file(db.upcast());

let mut candidate_files = ArrayVec::<_, 2>::new();
Expand All @@ -73,12 +74,10 @@ impl ModDir {
candidate_files.push(self.dir_path.join_attr(attr_path, self.root_non_dir_owner))
}
None if file_id.is_include_macro(db.upcast()) => {
let name = name.unescaped();
candidate_files.push(format!("{}.rs", name));
candidate_files.push(format!("{}/mod.rs", name));
}
None => {
let name = name.unescaped();
candidate_files.push(format!("{}{}.rs", self.dir_path.0, name));
candidate_files.push(format!("{}{}/mod.rs", self.dir_path.0, name));
}
Expand Down
16 changes: 16 additions & 0 deletions crates/hir-def/src/nameres/tests/mod_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ mod r#async;
use self::r#async::Bar;

//- /async.rs
mod foo;
mod r#async;
pub struct Bar;

//- /async/foo.rs
pub struct Foo;

//- /async/async.rs
pub struct Baz;
"#,
expect![[r#"
crate
Expand All @@ -136,6 +144,14 @@ pub struct Bar;

crate::r#async
Bar: t v
foo: t
r#async: t

crate::r#async::foo
Foo: t v

crate::r#async::r#async
Baz: t v
"#]],
);
}
Expand Down