-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve out of line module resolution #5142
Conversation
77feb51
to
38d9352
Compare
Thanks for diving into this one! Few things:
|
I fixed the merge conflict! I understand you wanting to be cautious about not introducing any module resolution issues. Last night I tried to add the I'm also happy to work on another PR to build up our tests around module resolution / work on other module resolution related issues. As a side note, I don't think this fix will introduce any issues as the behavior is almost identical to how it was before, with the only difference being that we bail early if adding the next path component would lead to an invalid directory path. |
The question/concern for me would be whether the early bail results in failing to discover/load valid mods. I think one way to assuage that concern would be porting/replicating some of the existing tests (e.g. the path-based mod loads, cfg_if, etc.) and ensure we've got a test for them using the newer model leveraged here that more explicitly validates the module loading piece. That doesn't necessarily need to be done in this particular PR, but would probably want some of those to be done as well before a sync and release of this change |
Fixes 5119 When the directory structure was laid out as follows: ``` dir |---mod_a | |---sub_mod_1.rs | |---sub_mod_2.rs |---mod_a.rs ``` And ``mod_a.rs`` contains the following content: ```rust mod mod_a { mod sub_mod_1; mod sub_mod_2; } ``` rustfmt previously tried to find ``sub_mod_1.rs`` and ``sub_mod_2.rs`` in ``./mod_a/mod_a/``. This directory does not exist and this caused rustfmt to fail with the error message: Error writing files: failed to resolve mod Now, both ``sub_mod_1.rs`` and ``sub_mod_2.rs`` are resolved correctly and found at ``mod_a/sub_mod_1.rs`` and ``mod_a/sub_mod_2.rs``.
I went ahead and adjusted the current test case to incorporate both the |
To clarify and elaborate, I was referring to some of these test scenarios https://github.com/rust-lang/rustfmt/tree/master/tests/source/cfg_if and https://github.com/rust-lang/rustfmt/tree/master/tests/source/cfg_mod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still want to poke at this a bit more later on, but should be fine for now (going to wait to merge til after the next sync though)
Fixes #5119
When the directory structure was laid out as follows:
And
mod_a.rs
contains the following content:rustfmt previously tried to find
sub_mod_1.rs
andsub_mod_2.rs
in
./mod_a/mod_a/
. This directory does not exist and this causedrustfmt to fail with the error message:
Now, both
sub_mod_1.rs
andsub_mod_2.rs
are resolved correctlyand found at
mod_a/sub_mod_1.rs
andmod_a/sub_mod_2.rs
.