Skip to content
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

rustfmt fails on Rust 2018 "path clarity" submodules #3427

Closed
mjbshaw opened this issue Mar 2, 2019 · 1 comment
Closed

rustfmt fails on Rust 2018 "path clarity" submodules #3427

mjbshaw opened this issue Mar 2, 2019 · 1 comment
Labels
bug Panic, non-idempotency, invalid code, etc. p-high

Comments

@mjbshaw
Copy link

mjbshaw commented Mar 2, 2019

I originally reported this in #2407, but on further reflection I think it deserves its own issue. rustfmt fails for Rust 2018 submodules that don't use mod.rs (because of path clarity). Example:

$ mkdir foo
$ touch foo/bar.rs
$ echo 'mod bar;' > foo.rs
$ rustfmt --edition 2018 foo.rs
error[E0583]: file not found for module `bar`
 --> /private/tmp/demo/foo.rs:1:5
  |
1 | mod bar;
  |     ^^^
  |
  = help: name the file either bar.rs or bar/mod.rs inside the directory "/private/tmp/demo"

For clarity, the file structure is:

$ tree
.
├── foo
│   └── bar.rs
└── foo.rs

Here, foo.rs is the Rust 2018 equivalent of Rust 2015's foo/mod.rs.

@topecongiro
Copy link
Contributor

The rustc parser uses Parser::directory in order to choose on which file to look at when parsing mod foo;.
This value is changed automatically when parsing a whole crate, so rustfmt does not have to modify it manually. On the other hand, when formatting an internal file within a crate, rustfmt needs to configure this value by itself. Unfortunately, the field's visibility is crate and there is no setter method for it, so we need to fix rustc first.

@topecongiro topecongiro added the blocked Blocked on rustc, an RFC, etc. label Mar 9, 2019
Centril added a commit to Centril/rust that referenced this issue Mar 9, 2019
…rom_file, r=Centril

Expose new_sub_parser_from_file

This function is useful when external tools like rustfmt want to parse
internal files without parsing a whole crate.

cc rust-lang/rustfmt#3427.
@topecongiro topecongiro removed the blocked Blocked on rustc, an RFC, etc. label Mar 14, 2019
topecongiro added a commit to topecongiro/rustfmt that referenced this issue Mar 15, 2019
topecongiro added a commit to topecongiro/rustfmt that referenced this issue Mar 17, 2019
topecongiro added a commit to topecongiro/rustfmt that referenced this issue Apr 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. p-high
Projects
None yet
Development

No branches or pull requests

2 participants