-
Notifications
You must be signed in to change notification settings - Fork 971
Description
Overview
Rustfmt cannot find a submodule of an integration test located in a separate file.
Running cargo fmt on a project that contains a submodule test1/sub1 implemented by the file tests/test1/sub1.rs produces the following error message:
Error writing files: failed to resolve mod `sub1`: $PACKAGE/tests/test1/test1 does not exist
Submodules in integration tests can be created as follows:
In tests/test1.rs:
mod test1 {
mod sub1;
mod sub2;
}
The submodules sub1 and sub2 can be implemented in the files tests/test1/sub1.rs and tests/test1/sub2.rs.
This structure works with cargo build, cargo test, and cargo clippy, but fails for cargo fmt with the error message given above.
Steps to reproduce
Clone this repo containing a minimal example illustrating the problem: https://github.com/walkie/rustfmt-test-submodule-issue
From within the repo:
- Run
cargo testand observe that the package successfully compiles and the tests in both submodules run and pass. - Run
cargo fmtand observe the following error message:
Error writing files: failed to resolve mod `sub1`: [...]/rustfmt-test-submodule-issue/tests/test1/test1 does not exist
The same error can also be produced by rustfmt directly with the command: rustfmt tests/test1.rs
Expected behavior
- No Rustfmt I/O errors. :-)
Other information
- Installed Rustfmt by
rustup component add rustfmt - Tested with versions
1.51,1.57, and1.59.0-nightly (48a5999fc 2021-12-01) - Tested on Fedora Workstation 34 and MacOS 11.6.1
The error occurs in all combinations of the above.