Skip to content

Conversation

@Harishankar14
Copy link
Contributor

Currently, the compiler fails to resolve module paths when a file in the root directory (e.g. 'bar.rs') attempts to load a sibling module (e.g. 'foo.rs') if a 'bar/' directory does not exist. The compiler incorrectly assumes that if 'bar.rs' is not 'mod.rs', it must look exclusively in a subdirectory.

This patch adds a fallback mechanism in 'Module::process_file_path'. If the subdirectory search fails, it strips the implicit subdirectory and attempts to resolve the module in the parent directory, consistent with Rust 2018 path rules.

Fixes #4402

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Module::process_file_path): Add fallback search for sibling modules when subdirectory search fails.

gcc/testsuite/ChangeLog:

* rust/compile/issue-4402.rs: New test.
* rust/compile/issue_4402_foo.rs: New test.

Thank you for making Rust GCC better!

If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.

Here is a checklist to help you with your PR.

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

*Please write a comment explaining your change. This is the message
that will be part of the merge commit.

Currently, the compiler fails to resolve module paths when a file in the
root directory (e.g. 'bar.rs') attempts to load a sibling module
(e.g. 'foo.rs') if a 'bar/' directory does not exist. The compiler
incorrectly assumes that if 'bar.rs' is not 'mod.rs', it must look
exclusively in a subdirectory.

This patch adds a fallback mechanism in 'Module::process_file_path'.
If the subdirectory search fails, it strips the implicit subdirectory
and attempts to resolve the module in the parent directory, consistent
with Rust 2018 path rules.

Fixes Rust-GCC#4402

gcc/rust/ChangeLog:

	* ast/rust-ast.cc (Module::process_file_path): Add fallback search
	for sibling modules when subdirectory search fails.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4402.rs: New test.
	* rust/compile/issue_4402_foo.rs: New test.

Signed-off-by: Harishankar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot resolve module path properly in simple setting

1 participant