Commit 725536d
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 b940d2c commit 725536d
File tree
3 files changed
+35
-1
lines changed- gcc
- rust/ast
- testsuite/rust/compile
3 files changed
+35
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3410 | 3410 | | |
3411 | 3411 | | |
3412 | 3412 | | |
| 3413 | + | |
3413 | 3414 | | |
3414 | 3415 | | |
3415 | | - | |
| 3416 | + | |
| 3417 | + | |
| 3418 | + | |
| 3419 | + | |
3416 | 3420 | | |
3417 | 3421 | | |
3418 | 3422 | | |
| |||
3441 | 3445 | | |
3442 | 3446 | | |
3443 | 3447 | | |
| 3448 | + | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
| 3469 | + | |
3444 | 3470 | | |
3445 | 3471 | | |
3446 | 3472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments