-
Notifications
You must be signed in to change notification settings - Fork 926
Improve mod resolution error for mods with multiple candidate files #5243
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good improvement to me, thanks! For the sake of consistent tests across the variants, would you mind adding one that still triggers the file not found variant (I assume easiest way would be a test that had a path
attribute on the mod import pointing to some non-existent file)
Good call! I'll get on that soon. |
caecaee
to
6584c7e
Compare
@calebcartwright I added additional tests to cover 3 different cases where a module might not be found. I also needed to modify the behavior I introduced in #5205 to surface the original error when the fallback doesn't work. |
Fixes 5167 When ``a.rs`` and ``a/mod.rs`` are both present we would emit an error message telling the user that the module couldn't be found. However, this behavior is misleading because we're dealing with an ambiguous module path, not a "file not found" error. Is the file ``a.rs`` or is it ``a/mod.rs``? Rustfmt can't decide, and the user needs to resolve this ambiguity themselves. Now, the error message displayed to the user is in line with what they would see if they went to compile their code with these conflicting module names.
A slight improvement could be made to the existing behavior proposed in this PR. In the currently implementation we'll always tell uses that ModError::FileNotFound(_, default_path, secondary_path) => {
let file = if let Some(path) = secondary_path.parent() && path.exist() {
secondary_path
} else {
default_path
};
Err(ModuleResolutionError {
module: mod_name.to_string(),
kind: ModuleResolutionErrorKind::NotFound { file },
})
} to write the code more succinctly I've used the new |
We've historically tried to stay away from using features, though I'm not entirely sure why to be honest. Not sure if I'm ready to take that plunge here, so let's keep that separate (can be addressed in a follow up PR if we decide to open that door) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
Will get back to regarding the potential introduction of the usage of gated features
Fixes #5167
When
a.rs
anda/mod.rs
are both present we would emit an errormessage telling the user that the module couldn't be found. However,
this behavior is misleading because we're dealing with an ambiguous
module path, not a "file not found" error.
Is the file
a.rs
or is ita/mod.rs
? Rustfmt can't decide, andthe user needs to resolve this ambiguity themselves.
Now, the error message displayed to the user is in line with what they
would see if they went to compile their code with these conflicting
module names.