Commit 1056418
committed
ast: Fix module path resolution for sibling modules in root
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.
Signed-off-by: Harishankar <[email protected]>1 parent 90ca1f6 commit 1056418
File tree
3 files changed
+39
-1
lines changed- gcc
- rust/ast
- testsuite/rust/compile
3 files changed
+39
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3418 | 3418 | | |
3419 | 3419 | | |
3420 | 3420 | | |
| 3421 | + | |
3421 | 3422 | | |
3422 | 3423 | | |
3423 | | - | |
| 3424 | + | |
| 3425 | + | |
| 3426 | + | |
| 3427 | + | |
3424 | 3428 | | |
3425 | 3429 | | |
3426 | 3430 | | |
| |||
3449 | 3453 | | |
3450 | 3454 | | |
3451 | 3455 | | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
| 3469 | + | |
| 3470 | + | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
| 3477 | + | |
3452 | 3478 | | |
3453 | 3479 | | |
3454 | 3480 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments