Commit Graph

9 Commits

Author SHA1 Message Date
Yacin Tmimi 18c0369688 Improve mod resolution error for mods with multiple candidate files
Fixes 5167

When ``a.rs`` and ``a/mod.rs`` are both present we would emit an error
message telling the user that the module couldn't be found. However,
this behavior is misleading because we're dealing with an ambiguous
module path, not a "file not found" error.

Is the file ``a.rs`` or is it ``a/mod.rs``? Rustfmt can't decide, and
the user needs to resolve this ambiguity themselves.

Now, the error message displayed to the user is in line with what they
would see if they went to compile their code with these conflicting
module names.
2022-03-08 21:51:23 -06:00
Yacin Tmimi 12048e444f fallback to dir_path when relative external mod resolution fails
We only want to fall back if two conditions are met:

1) Initial module resolution is performed relative to some nested
   directory.
2) Module resolution fails because of a ModError::FileNotFound error.

When these conditions are met we can try to fallback to searching for
the module's file relative to the dir_path instead of the nested
relative directory.

Fixes 5198

As demonstrated by 5198, it's possible that a directory name conflicts
with a rust file name. For example, src/lib/ and src/lib.rs.

If src/lib.rs references an external module like ``mod foo;``, then
module resolution will try to resolve ``foo`` to src/lib/foo.rs or
src/lib/foo/mod.rs. Module resolution would fail with a file not
found error if the ``foo`` module were defined at src/foo.rs.

When encountering these kinds of module resolution issues we now fall
back to the current directory and attempt to resolve the module again.

Given the current example, this means that if we can't find the module
``foo`` at src/lib/foo.rs or src/lib/foo/mod.rs, we'll attempt
to resolve the module to src/foo.rs.
2022-02-28 23:13:11 -06:00
Caleb Cartwright f935f0cf89 feat: support parsing asm! args 2021-12-28 20:25:17 -06:00
Caleb Cartwright 7b8303d479 chore: cleanup unused imports 2021-12-21 10:55:39 -06:00
Caleb Cartwright 97c3e48834 refactor: encapsulate cfg_if parsing within parse mod 2021-12-21 10:55:39 -06:00
Caleb Cartwright 62987562e2 refactor: extract final rustc_parse touchpoint from macros.rs 2021-12-21 10:55:39 -06:00
Caleb Cartwright c8cf454173 refactor: move lazy_static parsing to parse mod 2021-12-21 10:55:39 -06:00
Caleb Cartwright 9ce5470a8c refactor: move macro arg parsing to parse mod 2021-12-21 10:55:39 -06:00
Caleb Cartwright 40b73d8fee refactor: rename syntux mod to parse 2021-12-21 10:55:39 -06:00