Commit dc07f2a
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.
* rust/compile/compile.exp:Ignore issue_4402_foo.rs
Signed-off-by: Harishankar <[email protected]>1 parent b98bdc9 commit dc07f2a
File tree
4 files changed
+52
-3
lines changed- gcc
- rust/ast
- testsuite/rust/compile
4 files changed
+52
-3
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 | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
32 | 45 | | |
33 | 46 | | |
34 | 47 | | |
35 | | - | |
| 48 | + | |
| 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 | + | |
0 commit comments