-
Notifications
You must be signed in to change notification settings - Fork 922
Rustfmt can't find module if a directory and module is named the same #3794
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
Comments
How about this? |
|
Do you use Windows? |
|
I succeeded to reproduce the bug on ubuntu 18.04. Thank you. |
The rustfmt was in my environment a bit old. |
As a workaround, the following command may work if you are using nightly (you also need rustfmt --unstable-features --skip-children `fd -e rs` |
- Issue with tests and modules causes rustfmt to fail (rust-lang/rustfmt#3794) - Will re-organize tests in 0.3 branch to fix. Don't want to do it here to avoid merge conflicts.
(It would be good if this issue's title included the detail that its specifically about resolution in cargo |
Note: generates tests into fresh temp dir, which is deleted after testing is done (regardless of success or failure). You can change the `which_temp::WhichTempDir` type to revise this behavior. This infrastructure includes two tests: `tests/cli.rs` and `tests/ice.rs`. Each uses very different strategies for testing cargo-bisect-rustc. 1. `tests/cli.rs` uses a so-called meta-build strategy: the test inspects the `rustc` version, then generates build files that will inject (or remove, e.g. when testing `--regress=success`) `#[rustc_error]` from the source code based on the `rustc` version. This way, we get the effect of an error that will come or go based solely on the `rustc` version, without any dependence on the actual behavior of `rustc` itself (beyond its version string format remaining parsable). * This strategy should remain usable for the foreseeable future, without any need for intervention from `cargo-bisect-rustc` developers. 2. `tests/ice.rs` uses a totally different strategy: It embeds an ICE that we know originated at a certain version of the compiler. The ICE is embedded in the file `src/ice/included_main.rs`. The injection point associated with the ICE is encoded in the constant `INJECTION_COMMIT`. * Over time, since we only keep a certain number of builds associated with PR merge commits available to download, the embedded ICE, the `INJECTION_COMMIT` definition, and the search bounds defined in `INJECTION_LOWER_BOUND` and `INJECTION_UPPER_BOUND` will all have to be updated as soon as the commit for `INJECTION_COMMIT` is no longer available for download. * Thus, this testing strategy requires regular maintenance from the `cargo-bisect-rustc` developers. (However, it is more flexible than the meta-build strategy, in that you can embed arbitrary failures from the recent past using this approach. The meta-build approach can only embed things that can be expressed via features like `#[rustc_error]`, which cannot currently express ICE's. ---- Includes suggestions from code review Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com> ---- Includes some coments explaining the `WhichTempDir` type. (That type maybe should just be an enum rather than a trait you implement... not sure why I made it so general...) ---- Includes workaround for rustfmt issue. Specifically, workaround rust-lang/rustfmt#3794 which was causing CI's attempt to run `cargo fmt -- --check` to erroneously report: ``` % cargo fmt -- --check error[E0583]: file not found for module `meta_build` --> /private/tmp/cbr/tests/cli.rs:11:20 | 11 | pub(crate) mod meta_build; | ^^^^^^^^^^ | = help: name the file either meta_build.rs or meta_build/mod.rs inside the directory "/private/tmp/cbr/tests/cli/cli" error[E0583]: file not found for module `command_invocation` --> /private/tmp/cbr/tests/ice.rs:34:20 | 34 | pub(crate) mod command_invocation; | ^^^^^^^^^^^^^^^^^^ | = help: name the file either command_invocation.rs or command_invocation/mod.rs inside the directory "/private/tmp/cbr/tests/ice/common" ``` ---- Includes fix for oversight in my cli test system: it needed to lookup target binary, not our PATH. (This functionality is also available via other means, such as `$CARGO_BIN_EXE_<name>` and https://crates.io/crates/assert_cmd. I opted not to use the builtin env variable because that is only available in very recent cargo versions, and I would prefer our test suite to work peven on older versions of cargo, if that is feasible...) ---- Includes applications of rustfmt suggestions, as well as an expansion of a comment in a manner compatible with rustfmt. (Namely, that replaced an inline comment which is erroneously deleted by rustfmt (see rust-lang/rustfmt#2781 ) with an additional note in the comment above the definition.)
This issue will be fixed in 2.0. |
* Regression testing of graphs * Move test cases into a file * Workaround for rust-lang/rustfmt#3794
Reproduction, clone https://github.com/Marwes/rustfmt-bug and run
cargo fmt
.Since both
tests/test.rs
andtests/test/
exists, rustfmt is unable to findtests/support/mod.rs
asmod support;
as it appears that rustfmt thinks thattest.rs
is part of thetests/test/
module tree. This is different from how rustc/cargo sees it which compile the code happily.I guess rustc/cargo has different module resolution for
tests/
thansrc/
since rustfmt's behaviour would be correct insrc/
.Workaround is to use
#[path = "module.rs"]
on the offending module.The text was updated successfully, but these errors were encountered: