Skip to content

Fix handling of modules in non_modrs_mods style #2675

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

Merged
merged 3 commits into from
May 6, 2018

Conversation

flodiebold
Copy link
Member

We need to keep track of the module relative to which we're resolving paths,
instead of always passing None.

Fixes #2673.

WIP because I still need to add a test; I'm making the PR already because I wanted to make sure this is the right approach.

@flodiebold flodiebold changed the title Fix handling of modules in non_modrs_mods style (WIP) Fix handling of modules in non_modrs_mods style May 4, 2018
@flodiebold
Copy link
Member Author

Added a test; I couldn't fit it into the existing test patterns because if I put the files e.g. into target, it will try to format foo.rs alone and fail to parse it (which I think is legitimate, but maybe not?)

@nrc
Copy link
Member

nrc commented May 5, 2018

Added a test; I couldn't fit it into the existing test patterns because if I put the files e.g. into target, it will try to format foo.rs alone and fail to parse it (which I think is legitimate, but maybe not?)

I think that should work, maybe we need to update rustc_ap_syntax?

@nrc
Copy link
Member

nrc commented May 5, 2018

maybe we need to update rustc_ap_syntax?

Just did this, could you try a regular test now please?

Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Code looks good, it would be nice to have a regular test, rather than a special case one, or at least properly understand why the regular test doesn't work.

flodiebold added 2 commits May 6, 2018 09:58
We need to keep track of the module relative to which we're resolving paths,
instead of always passing None.

Fixes rust-lang#2673.
@flodiebold
Copy link
Member Author

I rebased, but it still doesn't work. I get

error[E0583]: file not found for module `bar`
 --> tests/target/issue-2673-nonmodrs-mods/foo.rs:1:5
  |
1 | mod bar;
  |     ^^^
  |
  = help: name the file either bar.rs or bar/mod.rs inside the directory "tests/target/issue-2673-nonmodrs-mods"

when it tries to format foo.rs by itself, because the parser doesn't know to look for bar in foo/bar.rs. I've tried guessing the directory ownership from the file name (so when parsing a file foo.rs as the root, it treats it as a module foo), but that results in lots of other tests failing, because e.g. in tests/target/configs/reorder_modules/false.rs, it looks for the module lorem in false/lorem.rs instead of lorem/mod.rs.

I could make this a normal test if there were some way of telling the test runner not to format foo.rs by itself.

@topecongiro
Copy link
Contributor

@flodiebold There is skip_children config option which lets rustfmt ignore any submodules. I hope this could help to solve the issue.

We need to skip children on foo.rs, since the parser will not find bar from that
file, but with that, the test works fine.
@flodiebold
Copy link
Member Author

@topecongiro Ah, of course, why didn't I think of that :)

@nrc I've turned the test into an idempotence test now.

@nrc nrc merged commit f46f4b5 into rust-lang:master May 6, 2018
@nrc
Copy link
Member

nrc commented May 6, 2018

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants