diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2023-05-28 09:44:39 -0400 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-06-07 11:23:48 +0000 |
commit | ab44003c26a5dc5c92145d491e51b7582d51a4f6 (patch) | |
tree | d164f6915e0aeeed1368beb0bfa3297772af08c9 /gcc/rust/parse/rust-parse-impl.h | |
parent | 25b40ba2e03c4ff030adb7ce8ce00e5315c46cb3 (diff) | |
download | gcc-ab44003c26a5dc5c92145d491e51b7582d51a4f6.zip gcc-ab44003c26a5dc5c92145d491e51b7582d51a4f6.tar.gz gcc-ab44003c26a5dc5c92145d491e51b7582d51a4f6.tar.bz2 |
Fix non-mod-rs files' external module loading paths
gcc/rust/ChangeLog:
* Make-lang.in: Add "rust-dir-owner.o".
* ast/rust-ast.cc: Include "rust-dir-owner.h".
(Module::process_file_path):
Handle non-mod-rs external file modules properly.
* parse/rust-parse-impl.h: Include "rust-dir-owner.h".
(Parser::parse_module):
Handle non-mod-rs external file modules properly.
* util/rust-dir-owner.cc: New file.
* util/rust-dir-owner.h: New file.
gcc/testsuite/ChangeLog:
* rust/compile/test_mod.rs: Moved to...
* rust/compile/issue-1089/test_mod.rs: ...here.
* rust/compile/mod_missing_middle.rs: Fix paths.
* rust/compile/missing_middle/both_path.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/both_path.rs: ...here.
* rust/compile/missing_middle/explicit.not.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/explicit.not.rs: ...here.
* rust/compile/missing_middle/other.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/explicit.not/other.rs: ...here.
* rust/compile/missing_middle/inner_path.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/inner_path.rs: ...here.
* rust/compile/missing_middle/outer_path.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/outer_path.rs: ...here.
* rust/compile/missing_middle/sub/mod.rs: Moved to...
* rust/compile/mod_missing_middle/missing_middle/sub/mod.rs: ...here.
* rust/compile/torture/modules/mod.rs: Moved to...
* rust/compile/torture/extern_mod1/modules/mod.rs: ...here.
* rust/execute/torture/modules/mod.rs: Moved to...
* rust/execute/torture/extern_mod4/modules/mod.rs: ...here.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index cb06b28..d6b045b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -25,6 +25,7 @@ #define INCLUDE_ALGORITHM #include "rust-diagnostics.h" #include "rust-make-unique.h" +#include "rust-dir-owner.h" namespace Rust { // Left binding powers of operations. @@ -2430,8 +2431,25 @@ Parser<ManagedTokenSource>::parse_module (AST::Visibility vis, // parse inner attributes AST::AttrVec inner_attrs = parse_inner_attributes (); + std::string default_path = name; + + if (inline_module_stack.empty ()) + { + std::string filename = lexer.get_filename (); + auto slash_idx = filename.rfind (file_separator); + if (slash_idx == std::string::npos) + slash_idx = 0; + else + slash_idx++; + filename = filename.substr (slash_idx); + + std::string subdir; + if (get_file_subdir (filename, subdir)) + default_path = subdir + file_separator + name; + } + std::string module_path_name - = extract_module_path (inner_attrs, outer_attrs, name); + = extract_module_path (inner_attrs, outer_attrs, default_path); InlineModuleStackScope scope (*this, std::move (module_path_name)); // parse items |