Skip to content

Rustfmt cannot resolve submodules of integration tests #5119

@walkie

Description

@walkie

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 test and observe that the package successfully compiles and the tests in both submodules run and pass.
  • Run cargo fmt and 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, and 1.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions