Skip to content
Open
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
28 changes: 27 additions & 1 deletion gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3410,9 +3410,13 @@ Module::process_file_path ()
auto path_string = filename_from_path_attribute (get_outer_attrs ());

std::string including_subdir;
bool subdir_was_added = false;
if (path_string.empty () && module_scope.empty ()
&& get_file_subdir (including_fname, including_subdir))
current_directory_name += including_subdir + file_separator;
{
current_directory_name += including_subdir + file_separator;
subdir_was_added = true;
}

// Handle inline module declarations adding path components.
for (auto const &name : module_scope)
Expand Down Expand Up @@ -3441,6 +3445,28 @@ Module::process_file_path ()
+ file_separator + expected_dir_path;
bool dir_mod_found = file_exists (dir_mod_path);

if (!file_mod_found && !dir_mod_found && subdir_was_added)
{
size_t suffix_len
= including_subdir.length () + std::string (file_separator).length ();
std::string fallback_dir
= current_directory_name.substr (0, current_directory_name.length ()
- suffix_len);
std::string fallback_file = fallback_dir + expected_file_path;
std::string fallback_dir_mod = fallback_dir + module_name.as_string ()
+ file_separator + expected_dir_path;
if (file_exists (fallback_file))
{
file_mod_found = true;
file_mod_path = fallback_file;
}
else if (file_exists (fallback_dir_mod))
{
dir_mod_found = true;
dir_mod_path = fallback_dir_mod;
}
}

bool multiple_candidates_found = file_mod_found && dir_mod_found;
bool no_candidates_found = !file_mod_found && !dir_mod_found;

Expand Down
7 changes: 7 additions & 0 deletions gcc/testsuite/rust/compile/issue-4402.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use issue_4402_foo::Bar;
pub mod issue_4402_foo;

fn main() {
// use '_a' to silence the unused variable warning
let _a = Bar;
}
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/issue_4402_foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct Bar;