-
Notifications
You must be signed in to change notification settings - Fork 891
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
Confusing error when a module is found as a file and a directory #5167
Comments
Thanks for the report! Confirming that I can reproduce the issue. I assumed there was an ambiguity error, and if you run error[E0761]: file for module `bar` found at both "src\bar.rs" and "src\bar\mod.rs"
--> src\lib.rs:1:1
|
1 | mod bar;
| ^^^^^^^^
|
= help: delete or rename one of them to remove the ambiguity Cargo check's is a much more helpful error message, so I'll see if I can hunt down what's happening and hopefully provide something similar. |
This almost certainly goes back to a number of pending PR in need of backport triaging. I'd start with those (they should be labeled accordingly) to avoid accidentally reinventing any wheels |
Before I saw your comment I actually identified what was going wrong. The issue here is that we're matching on a Lines 447 to 453 in 5056f4c
I was quickly able to fix the issue before I had a chance to read your comment. I've gone through the PRs and I'm struggling to find one that addresses this specific scenario. It's not a major change, just adding a new variant to ModuleResolutionErrorKind, but I'll hold off on submitting it. If you can identify the backport I'll take a look at that otherwise I've got a fix ready to go! |
Try reproducing on the 2.x branch. If you can reproduce then definitely feel free to submit a new PR with your changes. However, if you can't let's try to track down the original fix, and make a decision from there. My hesitation stems from having at least 3 or 4 fixes on that branch that are all dealing with the same code, and I want to try to avoid complicating our ability to pull in those prior fixes |
Just tested this out on the 2.0 branch, and couldn't reproduce, so I'll go back through the backport triage more thoroughly to find the PR that fixes this. |
https://github.com/rust-lang/rustfmt/pulls?page=1&q=is%3Apr+label%3Abackport-triage+is%3Aclosed plus any other relevant search criteria you can think of |
#4198 may be relevant. |
Hey, So I went back and revisited the code. A lot of investigating between the two branches, but I figured out what's going on here. On further inspection I wasn't 100% correct when I said that the issue doesn't occur on the 2.0 branch. We still run into the same parsing error, but the 2.0 branch silently ignores it. The issue comes down to how In the 1.0 branch we always return early if their is an error when calling On the 1.0 branch: Lines 209 to 223 in 5056f4c
On the 2.0 branch: rustfmt/src/formatting/modules.rs Lines 250 to 264 in cc5521d
#4284 is the I personally feel like the 1.0 behavior is what we want, and that we should let users know that there was a module resolution error (the aforementioned |
When a module is found as both a file
modname.rs
and a directorymodname/mod.rs
, the error fromcargo fmt --all
is wrong and misleading.Reproduction steps:
Output:
Error writing files: failed to resolve mod `bar`: hi/foo/src does not exist
The text was updated successfully, but these errors were encountered: